/* ─────────────────────────────────────────
   MyConsignTrack — Design System
   ───────────────────────────────────────── */

:root {
  --bg: #ffffff;
  --bg-secondary: #f7f7f6;
  --bg-tertiary: #f0efed;
  --border: rgba(0,0,0,0.1);
  --border-md: rgba(0,0,0,0.18);
  --text: #1a1a1a;
  --text-secondary: #555550;
  --text-tertiary: #999990;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);

  /* semantic */
  --green-bg: #EAF3DE;
  --green-text: #3B6D11;
  --blue-bg: #E8F0FD;
  --blue-text: #1D4ED8;
  --amber-bg: #FFF3E8;
  --amber-text: #B86A00;
  --red-bg: #FEE2E2;
  --red-text: #B91C1C;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ── */
h1 { font-size: 28px; font-weight: 500; letter-spacing: -0.02em; }
h2 { font-size: 20px; font-weight: 500; letter-spacing: -0.01em; }
h3 { font-size: 15px; font-weight: 500; }
p  { color: var(--text-secondary); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 0.5px solid var(--border-md);
  background: transparent; color: var(--text);
  transition: background 0.1s, opacity 0.1s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--bg-secondary); }
.btn:active { opacity: 0.8; }

.btn-primary {
  background: #1a1a1a; color: #fff;
  border-color: #1a1a1a;
}
.btn-primary:hover { background: #333; }

.btn-danger {
  background: var(--red-bg); color: var(--red-text);
  border-color: transparent;
}
.btn-danger:hover { opacity: 0.85; }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ── Inputs ── */
.input, .select, .textarea {
  width: 100%; padding: 9px 12px;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-md);
  font-size: 13px; color: var(--text);
  background: var(--bg);
  outline: none; transition: border-color 0.15s;
  font-family: inherit;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: #1a1a1a;
}
.input::placeholder { color: var(--text-tertiary); }
.textarea { resize: vertical; min-height: 80px; }
.select { appearance: none; cursor: pointer; }

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.form-hint  { font-size: 12px; color: var(--text-tertiary); }
.form-error { font-size: 11px; color: var(--red-text); }

/* ── Cards ── */
.card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-secondary {
  background: var(--bg-secondary);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

/* ── Stat Cards ── */
.stat-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}
.stat-label { font-size: 12px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 500; color: var(--text); }
.stat-sub   { font-size: 12px; color: var(--text-tertiary); margin-top: 3px; }
.stat-up    { color: var(--green-text); }
.stat-warn  { color: var(--amber-text); }

/* ── Pills / Badges ── */
.pill {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 500;
}
.pill-available { background: var(--green-bg); color: var(--green-text); }
.pill-sold      { background: var(--blue-bg);  color: var(--blue-text); }
.pill-aging     { background: var(--amber-bg); color: var(--amber-text); }
.pill-pending   { background: var(--amber-bg); color: var(--amber-text); }
.pill-sent      { background: var(--green-bg); color: var(--green-text); }
.pill-returned  { background: var(--bg-tertiary); color: var(--text-secondary); }
.pill-pro       { background: #1a1a1a; color: #fff; }
.pill-free      { background: var(--bg-tertiary); color: var(--text-secondary); }

/* ── Tables ── */
.table-wrap {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  padding: 10px 16px; text-align: left;
  font-size: 12px; font-weight: 500;
  color: var(--text-tertiary);
  border-bottom: 0.5px solid var(--border);
  background: var(--bg-secondary);
  text-transform: uppercase; letter-spacing: 0.04em;
  white-space: nowrap;
}
td {
  padding: 11px 16px;
  border-bottom: 0.5px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-secondary); }
.td-name { font-weight: 500; }
.td-sub  { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }

/* ── Empty State ── */
.empty-state {
  text-align: center; padding: 64px 24px;
  color: var(--text-tertiary);
}
.empty-state-icon {
  width: 40px; height: 40px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.empty-state h3 { font-size: 14px; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  width: 100%; max-width: 480px;
  padding: 24px;
  transform: translateY(8px);
  transition: transform 0.15s;
  max-height: 90vh; overflow-y: auto;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 15px; font-weight: 500; }
.modal-close {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  border: none; background: var(--bg-secondary);
  cursor: pointer; font-size: 16px; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg-tertiary); }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 20px; padding-top: 16px;
  border-top: 0.5px solid var(--border);
}

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: #1a1a1a; color: #fff;
  padding: 12px 18px; border-radius: var(--radius-md);
  font-size: 13px; z-index: 9999;
  transform: translateY(80px); opacity: 0;
  transition: all 0.2s; pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--green-text); }
.toast.error   { background: var(--red-text); }

/* ── App Layout ── */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 220px; min-width: 220px;
  background: var(--bg);
  border-right: 0.5px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar-logo {
  padding: 18px 16px 14px;
  border-bottom: 0.5px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.logo-icon {
  width: 26px; height: 26px;
  background: #1a1a1a; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-icon svg { width: 14px; height: 14px; }
.logo-text { font-size: 14px; font-weight: 500; }

.sidebar-nav { padding: 10px 10px 0; flex: 1; }
.nav-section-label {
  font-size: 11px; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 0 8px; margin: 12px 0 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: var(--radius-md);
  font-size: 14px; color: var(--text-secondary);
  cursor: pointer; text-decoration: none;
  transition: background 0.1s; margin-bottom: 1px;
}
.nav-item:hover { background: var(--bg-secondary); color: var(--text); }
.nav-item.active { background: var(--bg-secondary); color: var(--text); font-weight: 500; }
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.6; }
.nav-item.active svg { opacity: 1; }
.nav-badge {
  margin-left: auto; font-size: 11px;
  padding: 1px 6px; border-radius: 20px;
  background: var(--bg-tertiary); color: var(--text-secondary);
  border: 0.5px solid var(--border);
}
.nav-badge.warn { background: var(--amber-bg); color: var(--amber-text); border-color: transparent; }

.sidebar-bottom {
  padding: 10px;
  border-top: 0.5px solid var(--border);
}
.user-row {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: var(--radius-md);
  cursor: pointer;
}
.user-row:hover { background: var(--bg-secondary); }
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--blue-bg); color: var(--blue-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 500; flex-shrink: 0;
}
.user-name { font-size: 12px; font-weight: 500; color: var(--text); }
.user-plan { font-size: 10px; color: var(--text-tertiary); }

/* Main content area */
.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: 52px; min-height: 52px;
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 10px;
}
.topbar-title { font-size: 14px; font-weight: 500; flex: 1; }

.page-content {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 24px;
  background: var(--bg-secondary);
}

/* ── Grids ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ── Divider ── */
.divider { border: none; border-top: 0.5px solid var(--border); margin: 16px 0; }

/* ── Loading ── */
.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 40px; color: var(--text-tertiary); font-size: 13px; gap: 8px;
}
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border-md);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Alert ── */
.alert {
  padding: 12px 16px; border-radius: var(--radius-md);
  font-size: 13px; margin-bottom: 16px;
}
.alert-error   { background: var(--red-bg);   color: var(--red-text); }
.alert-success { background: var(--green-bg); color: var(--green-text); }
.alert-warn    { background: var(--amber-bg); color: var(--amber-text); }

/* ── Responsive ── */
/* ── Mobile hamburger button ── */
.hamburger {
  display: none;
  width: 36px; height: 36px;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-md);
  background: transparent;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.hamburger svg { width: 16px; height: 16px; }

/* ── Mobile overlay ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 998;
}
.sidebar-overlay.open { display: block; }

/* ── Mobile filter bar (items page) ── */
.mobile-filter-bar {
  display: none;
  padding: 8px 14px;
  gap: 8px;
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
}
.topbar-actions-desktop { display: flex; align-items: center; gap: 8px; }

@media (max-width: 768px) {
  /* Layout */
  .app-layout { position: relative; }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.12);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: flex; }
  .main-area { width: 100%; min-width: 0; overflow-x: hidden; }

  /* Topbar */
  .topbar { padding: 0 14px; gap: 8px; }
  .topbar-title { font-size: 14px; }
  .topbar-actions-desktop { display: none; }

  /* Mobile filter bar */
  .mobile-filter-bar { display: flex; }

  /* Grids */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .three-col { grid-template-columns: 1fr; }

  /* Page content — extra bottom padding so last card is never cut off */
  .page-content { padding: 12px 12px 16px; }

  /* Modal max height on mobile */
  .modal { max-height: 85vh; overflow-y: auto; }

  /* Tables — card view on mobile */
  .table-wrap { overflow: hidden; }
  .table-wrap table { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tbody { display: block; }
  .table-wrap tr {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border-radius: var(--radius-md);
    border: 0.5px solid var(--border);
    padding: 12px 14px;
    margin-bottom: 8px;
    gap: 6px;
  }
  .table-wrap td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0;
    border-bottom: none;
    font-size: 13px;
    min-width: 0;
  }
  .table-wrap td:first-child {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
  }
  .table-wrap td[data-label]:before {
    content: attr(data-label);
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    margin-right: 8px;
  }
  .table-wrap td:last-child {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 0.5px solid var(--border);
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .table-wrap td:empty { display: none; }

  /* Cards on mobile */
  .card { padding: 14px; }
  .card-secondary { padding: 14px; }

  /* Modals full screen on mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100% !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 90vh;
  }

  /* Consignors grid */
  #consignors-grid { grid-template-columns: 1fr !important; }

  /* Dashboard topbar */
  .topbar { padding: 0 12px; gap: 8px; }

  /* Settings page */
  .page-content > div { max-width: 100% !important; }
  .page-content { padding-bottom: 80px; }

  /* Stat cards smaller on mobile */
  .stat-value { font-size: 20px; }

  /* Hide text on small buttons, keep icons */
  .btn-icon-only span { display: none; }

  /* Fix content cutoff on mobile */
  .app-layout { height: auto; min-height: 100vh; overflow: visible; }
  .main-area { overflow: visible; min-height: 0; }
  .page-content {
    overflow-y: visible;
    overflow-x: hidden;
    padding-bottom: 80px;
  }
}
