/* ============ RESET & BASE ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0a;
  --bg-card: #141414;
  --bg-hover: #1a1a1a;
  --border: #2a2a2a;
  --border-light: #333;
  --fg: #f5f5f5;
  --fg-dim: #a0a0a0;
  --fg-mute: #666;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
  --transition: 0.2s ease;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }

/* ============ SPLASH ============ */
.splash {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 9999;
  transition: opacity 0.4s ease;
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash-logo {
  font-size: 64px; font-weight: 800;
  color: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}
.splash-sub {
  margin-top: 12px; color: var(--fg-dim);
  font-size: 14px; letter-spacing: 0.1em;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.05); }
}

/* ============ AUTH VIEW ============ */
.view { height: 100%; }
#view-auth {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at top, #1a1a2e 0%, var(--bg) 70%);
  padding: 20px;
}
.auth-container {
  width: 100%; max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  box-shadow: var(--shadow);
}
.auth-brand { text-align: center; margin-bottom: 32px; }
.brand-logo { font-size: 48px; font-weight: 800; color: var(--accent); margin-bottom: 8px; }
.auth-brand h1 { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.auth-brand p { color: var(--fg-dim); font-size: 14px; }

.auth-tabs {
  display: flex; gap: 4px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}
.tab {
  flex: 1; text-align: center;
  padding: 10px; border-radius: 6px;
  font-weight: 600; font-size: 14px;
  cursor: pointer; color: var(--fg-dim);
  transition: var(--transition);
}
.tab.active { background: var(--accent); color: #fff; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-divider { text-align: center; color: var(--fg-mute); font-size: 12px; margin: 4px 0; }

.role-select { display: flex; gap: 10px; margin-top: 6px; }
.role-option {
  flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--transition);
}
.role-option:hover { border-color: var(--accent); }
.role-option input { accent-color: var(--accent); }
.role-option.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.role-option input:checked + span { color: var(--accent); font-weight: 600; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 10px 18px;
  border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  transition: var(--transition); white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--fg-dim); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--fg); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 8px; font-size: 18px; }

/* ============ FIELDS ============ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.field input, .field textarea, .field select {
  padding: 12px 14px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--fg); font-size: 14px; transition: var(--transition);
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.field textarea { resize: vertical; min-height: 100px; }

/* ============ MAIN LAYOUT ============ */
#view-main { display: flex; height: 100vh; }
.sidebar {
  width: 240px; background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 20px 12px; transition: transform 0.3s ease;
}
.sidebar-header { display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin-bottom: 20px; }
.sidebar-header .brand-logo { font-size: 28px; margin-bottom: 0; }
.brand-name { font-size: 18px; font-weight: 700; }

.nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--fg-dim);
  transition: var(--transition); font-weight: 500;
}
.nav-item:hover { background: var(--bg-hover); color: var(--fg); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .ico { font-size: 18px; width: 24px; text-align: center; }

.sidebar-footer {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-top: 1px solid var(--border); margin-top: 12px;
}
.user-card { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-info { overflow: hidden; }
.user-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--fg-mute); text-transform: capitalize; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.view-title { font-size: 20px; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ============ COMPONENTS ============ */
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.badge {
  background: var(--error); color: #fff;
  font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 10px; margin-left: 4px;
}

.page-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-title { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.page-sub { color: var(--fg-dim); font-size: 14px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; transition: var(--transition);
}
.card:hover { border-color: var(--border-light); }
.project-card { cursor: pointer; }
.project-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.card-title { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.desc {
  font-size: 13px; color: var(--fg-dim); line-height: 1.5; margin: 10px 0;
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  padding: 4px 10px; border-radius: 20px;
  background: var(--bg); border: 1px solid var(--border);
  font-size: 11px; color: var(--fg-dim);
}
.chip.accent {
  background: var(--accent-glow); border-color: var(--accent);
  color: var(--accent-hover); font-weight: 600;
}
.footer {
  display: flex; justify-content: space-between;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
}

.status {
  padding: 4px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.status.open { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.status.closed { background: rgba(239, 68, 68, 0.15); color: var(--error); }
.status.pending { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.status.accepted { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.status.rejected { background: rgba(239, 68, 68, 0.15); color: var(--error); }

.stat {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.stat-label { font-size: 12px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 28px; font-weight: 700; margin: 8px 0; }
.stat-delta { font-size: 12px; color: var(--accent); }

.empty { text-align: center; padding: 60px 20px; color: var(--fg-dim); }
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }

.match-score {
  width: 56px; height: 56px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--s, 0) * 1%), var(--border) 0);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; position: relative; flex-shrink: 0;
}
.match-score::before {
  content: ''; position: absolute;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg-card);
}
.match-score span { position: relative; z-index: 1; }

.ai-pulse {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  animation: aiPulse 1.5s ease-in-out infinite;
}
@keyframes aiPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 0 8px transparent; }
}

.offer-card { border-color: var(--accent); }
.offer-price { font-size: 32px; font-weight: 800; color: var(--success); margin-right: 10px; }
.offer-original { font-size: 18px; color: var(--fg-mute); text-decoration: line-through; }
.offer-savings {
  display: inline-block; padding: 6px 12px; border-radius: 20px;
  background: rgba(16, 185, 129, 0.15);
  color: var(--success); font-size: 13px; font-weight: 600; margin-top: 10px;
}

.chat-layout {
  display: flex; height: calc(100vh - 140px);
  border-radius: var(--radius); overflow: hidden;
  background: var(--bg-card); border: 1px solid var(--border);
}
.chat-list {
  width: 280px; border-right: 1px solid var(--border);
  overflow-y: auto; background: var(--bg);
}
.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; cursor: pointer;
  border-bottom: 1px solid var(--border); transition: var(--transition);
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-hover); border-left: 3px solid var(--accent); }
.chat-main { flex: 1; display: flex; flex-direction: column; }
.chat-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: 70%; padding: 10px 14px;
  border-radius: 12px; font-size: 14px; line-height: 1.4;
}
.msg.me {
  align-self: flex-end; background: var(--accent); color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.them {
  align-self: flex-start; background: var(--bg); border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-time { font-size: 10px; color: var(--fg-mute); margin-top: 4px; }
.chat-input {
  display: flex; gap: 10px; padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.chat-input input {
  flex: 1; padding: 12px 14px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--fg);
}
.chat-input input:focus { outline: none; border-color: var(--accent); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px; animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 18px; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--fg-dim);
  font-size: 20px; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg-hover); color: var(--fg); }
.modal > div:not(.modal-header) { padding: 24px; }

.toast-container {
  position: fixed; top: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 10px; z-index: 2000;
}
.toast {
  padding: 14px 20px; border-radius: var(--radius-sm);
  background: var(--bg-card); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: 14px; font-weight: 500;
  animation: slideIn 0.3s ease; transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--error); }
.toast.info { border-left: 4px solid var(--accent); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 100; transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .chat-list { width: 200px; }
}
@media (max-width: 600px) {
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .chat-layout { flex-direction: column; height: calc(100vh - 120px); }
  .chat-list { width: 100%; max-height: 200px; }
}