/* ─── CSS Custom Properties ─────────────────────────────────────────────── */
:root {
  --bg:         #111111;
  --surface:    #1c1c1c;
  --surface2:   #242424;
  --border:     #2a2a2a;
  --accent:     #f59e0b;
  --accent-hover: #fbbf24;
  --text:       #f5f5f5;
  --text-muted: #888888;
  --success:    #10b981;
  --danger:     #ef4444;
  --danger-hover: #dc2626;
  --sidebar-width: 240px;
  --topbar-h:   56px;
  --radius:     8px;
  --radius-sm:  4px;
  --shadow:     0 2px 8px rgba(0,0,0,0.4);
  --transition: 0.2s ease;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }
ul { list-style: none; }
svg { display: inline-block; vertical-align: middle; flex-shrink: 0; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  transition: transform var(--transition);
}
.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-icon { width: 28px; height: 28px; object-fit: contain; }
.logo-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.sidebar-workspace {
  padding: 6px 16px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
}
.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 12px 8px 4px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-link svg { width: 14px; height: 14px; flex-shrink: 0; }
.nav-link:hover { background: var(--surface2); color: var(--text); }
.nav-link.active { background: rgba(245,158,11,0.12); color: var(--accent); }
.nav-project { font-size: 13px; padding-left: 14px; }

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.status-active  { background: var(--accent); }
.status-dot.status-sold    { background: var(--success); }
.status-dot.status-scrapped{ background: var(--text-muted); }

.nav-section-spacer { flex: 1; min-height: 8px; }
.nav-user-email {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 10px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logout { color: var(--text-muted); }
.logout:hover { color: var(--danger); background: rgba(239,68,68,0.08); }

/* ─── Topbar (mobile) ────────────────────────────────────────────────────── */
.sidebar-toggle, .sidebar-overlay { display: none; }

/* ─── Main Content ───────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  padding: 32px;
}

/* ─── Page Header ────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.page-header-left h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}
.page-subtitle { color: var(--text-muted); margin-top: 4px; font-size: 13px; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.project-title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 8px;
  transition: color var(--transition);
}
.back-link:hover { color: var(--text); }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: none;
  transition: background var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn-primary   { background: var(--accent);   color: #111; }
.btn-primary:hover   { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger    { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover    { background: rgba(239,68,68,0.25); }
.btn-sm  { padding: 5px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

.btn-icon {
  background: none;
  border: none;
  padding: 5px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.btn-delete:hover { background: rgba(239,68,68,0.15); color: var(--danger); }

.btn-add-item {
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  transition: border-color var(--transition), color var(--transition);
}
.btn-add-item:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-active   { background: rgba(245,158,11,0.15); color: var(--accent); border: 1px solid rgba(245,158,11,0.3); }
.badge-sold     { background: rgba(16,185,129,0.12); color: var(--success); border: 1px solid rgba(16,185,129,0.3); }
.badge-scrapped { background: rgba(136,136,136,0.12); color: var(--text-muted); border: 1px solid var(--border); }
.badge-admin    { background: rgba(99,102,241,0.15); color: #818cf8; border: 1px solid rgba(99,102,241,0.3); }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}
.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: border-color var(--transition);
}
.project-card:hover { border-color: rgba(245,158,11,0.3); }
.project-card-image {
  margin: -20px -20px 0;
  height: 200px;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  background: var(--surface2);
}
.project-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.project-card-image--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.project-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.project-card-title h2 { font-size: 16px; font-weight: 600; color: var(--text); }
.project-car-info { font-size: 12px; color: var(--text-muted); margin-top: 2px; display: block; }
.project-card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 15px; font-weight: 600; color: var(--text); }
.project-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ─── Surface Card (generic) ─────────────────────────────────────────────── */
.surface-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.surface-card-body {
  padding: 20px;
}
.surface-card-body + .table-wrapper,
.surface-card-body + .surface-card-body { border-top: 1px solid var(--border); }

/* ─── Summary Grid (project page) ───────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.summary-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.summary-value { font-size: 22px; font-weight: 700; color: var(--text); }

.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 700;
  cursor: default;
  position: relative;
  vertical-align: middle;
  margin-left: 3px;
  text-transform: none;
  letter-spacing: 0;
}
.tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.4;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
}
.tip:hover::after { opacity: 1; }

/* ─── Text Helpers ───────────────────────────────────────────────────────── */
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-muted   { color: var(--text-muted); }

/* ─── Expense Sections ───────────────────────────────────────────────────── */
.expense-sections { display: flex; flex-direction: column; gap: 24px; }
.expense-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.section-header h2 { font-size: 15px; font-weight: 600; color: var(--text); }
.section-total { font-size: 13px; font-weight: 600; color: var(--text-muted); }

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
.expense-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.expense-table th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.expense-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.expense-table th:first-child,
.expense-table td:first-child { padding-left: 20px; }
.expense-table th:last-child,
.expense-table td:last-child { padding-right: 20px; }
.expense-table tr:last-child td { border-bottom: none; }
.expense-table tbody tr:hover td { background: rgba(255,255,255,0.02); }
.th-actions, .td-actions { width: 90px; text-align: right; white-space: nowrap; }

/* ─── Inline Add Form ────────────────────────────────────────────────────── */
.add-item-row {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 4px;
}
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.inline-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  flex: 1;
  min-width: 120px;
  transition: border-color var(--transition);
}
.inline-input:focus { outline: none; border-color: var(--accent); }
.inline-input-sm { max-width: 130px; flex: 0 0 130px; }

/* ─── Edit Panel ─────────────────────────────────────────────────────────── */
.edit-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}
.edit-form .form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.form-group { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 140px; }
.form-group label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.form-group input,
.form-group select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: border-color var(--transition);
}
.form-group input:focus,
.form-group select:focus { outline: none; border-color: var(--accent); }
.form-group-sm { max-width: 100px; flex: 0 0 100px; }
.form-group select option { background: var(--surface2); }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
  margin-bottom: 16px;
}
.modal-header h2 { font-size: 17px; font-weight: 600; }
.modal-close {
  background: none; border: none;
  color: var(--text-muted);
  font-size: 22px; line-height: 1;
  padding: 4px;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }
.modal-form { padding: 0 20px 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.modal-confirm { max-width: 380px; }

/* ─── Invite role selector ───────────────────────────────────────────────── */
.invite-role-options { display: flex; flex-direction: column; gap: 10px; }
.invite-role-option {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.invite-role-option:hover { border-color: var(--success); }
.invite-role-selected {
  border-color: var(--success);
  background: rgba(16,185,129,0.1);
}
.invite-role-check { color: var(--success); font-size: 16px; font-weight: 700; visibility: visible; }
.invite-role-check.hidden { display: inline !important; visibility: hidden; }

/* ─── Alert ──────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 12px;
}
.alert-danger { background: rgba(239,68,68,0.12); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 300;
  transition: opacity 0.3s;
  max-width: 300px;
}
.toast.hidden { display: none; }
.toast.success { border-color: rgba(16,185,129,0.4); color: var(--success); }
.toast.error   { border-color: rgba(239,68,68,0.4);  color: var(--danger); }

/* ─── Empty State ────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
}
.empty-state h3 { font-size: 18px; color: var(--text); }
.empty-state p  { max-width: 300px; }

/* ─── Login Page ─────────────────────────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo-img { width: 48px; height: 48px; object-fit: contain; display: block; margin: 0 auto 8px; }
.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--accent); }
.login-logo p  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.login-footer  { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-muted); }
.login-form .form-group { margin-bottom: 16px; }
.login-form label { display: block; margin-bottom: 6px; font-size: 12px; color: var(--text-muted); font-weight: 500; }
.login-form input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.login-form input:focus { outline: none; border-color: var(--accent); }

/* ─── Attachments ────────────────────────────────────────────────────────── */
.btn-attach { position: relative; }
.btn-attach:hover { background: rgba(245,158,11,0.12); color: var(--accent); }

.attach-badge {
  position: absolute;
  top: -2px; right: -2px;
  background: var(--accent);
  color: #111;
  font-size: 9px;
  font-weight: 700;
  width: 14px; height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  line-height: 1;
}

.attachment-row td { padding: 0 !important; border-bottom: 1px solid var(--border); }
.attachment-panel {
  padding: 8px 20px;
  background: rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}
.attachment-list { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-height: 24px; }
.attachment-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 6px 3px 10px;
}
.attachment-name {
  color: var(--text);
  font-size: 12px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-name:hover { color: var(--accent); }
.attachment-upload-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}
.attachment-upload-label:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Hidden Utility ─────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    z-index: 150;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 140;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
  }
  .sidebar-overlay.visible {
    opacity: 1;
    pointer-events: all;
  }
  .sidebar-toggle {
    display: flex;
    flex-direction: column;
    gap: 5px;
    position: fixed;
    top: 12px; left: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    z-index: 120;
  }
  .sidebar-toggle span {
    display: block;
    width: 18px; height: 2px;
    background: var(--text);
    border-radius: 1px;
    transition: transform var(--transition);
  }
  .main-content {
    margin-left: 0;
    padding: 20px 16px;
    padding-top: 56px;
  }
  .projects-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-grid  { grid-template-columns: repeat(2, 1fr); }
  .project-card-stats { grid-template-columns: 1fr 1fr; }
  .form-group-sm { max-width: 100%; flex: 1 1 100px; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-input-sm { max-width: 100%; flex: 1; }
}

@media (max-width: 480px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .project-card-stats { grid-template-columns: 1fr; }
  .summary-value { font-size: 18px; }
}
