/* ============================================
   A&H CONSIGNMENT — UI
   Design tokens drive light + dark themes.
   Layout: fixed sidebar + scrollable main.
   ============================================ */

/* ---- TOKENS: LIGHT (default) ---- */
:root {
  --bg:           #F7F7F9;
  --surface:      #FFFFFF;
  --surface-2:    #F1F2F4;
  --surface-3:    #E9EBEF;
  --border:       #E5E7EB;
  --border-strong:#D1D5DB;
  --text:         #0F172A;
  --text-soft:    #334155;
  --text-muted:   #64748B;
  --text-faint:   #94A3B8;
  --accent:       #E32525;
  --accent-soft:  #FEE7E7;
  --accent-strong:#B41F1F;
  --on-accent:    #FFFFFF;
  --ok:           #16A34A;
  --ok-soft:      #DCFCE7;
  --warn:         #F59E0B;
  --warn-soft:    #FEF3C7;
  --danger:       #DC2626;
  --danger-soft:  #FEE2E2;
  --pending:      #FEF3C7;
  --pending-text: #92400E;
  --shadow-sm:    0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow:       0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg:    0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
  --ring:         0 0 0 3px rgba(227, 37, 37, 0.15);
  --radius-sm:    6px;
  --radius:       10px;
  --radius-lg:    14px;
}

/* ---- TOKENS: DARK ---- */
:root[data-theme="dark"] {
  --bg:           #0A0B0F;
  --surface:      #14161B;
  --surface-2:    #1C1F26;
  --surface-3:    #232730;
  --border:       #262A33;
  --border-strong:#363B47;
  --text:         #F1F5F9;
  --text-soft:    #CBD5E1;
  --text-muted:   #94A3B8;
  --text-faint:   #64748B;
  --accent:       #FF4D4D;
  --accent-soft:  #2A0F0F;
  --accent-strong:#FF6B6B;
  --on-accent:    #FFFFFF;
  --ok:           #4ADE80;
  --ok-soft:      #052E16;
  --warn:         #FBBF24;
  --warn-soft:    #292109;
  --danger:       #F87171;
  --danger-soft:  #2A0A0A;
  --pending:      #2A2010;
  --pending-text: #FCD34D;
  --shadow-sm:    0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow:       0 2px 4px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-lg:    0 12px 24px rgba(0, 0, 0, 0.4);
  --ring:         0 0 0 3px rgba(255, 77, 77, 0.25);
}

/* ---- BASE ---- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--accent-strong); }

h1, h2, h3 { color: var(--text); font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 24px; margin: 0 0 4px; line-height: 1.2; }
h2 { font-size: 14px; margin: 28px 0 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
h3 { font-size: 16px; margin: 16px 0 8px; }
small { color: var(--text-muted); font-size: 12px; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 12px; }

/* ---- APP LAYOUT (sidebar + main) ---- */
body { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 12px;
  z-index: 10;
  overflow-y: auto;
}
main, .container, body > main {
  margin-left: 240px;
  padding: 32px 40px;
  width: calc(100% - 240px);
  min-height: 100vh;
}

/* ---- SIDEBAR: BRAND ---- */
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.logo-square {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: var(--accent); color: var(--on-accent);
  font-weight: 700; font-size: 18px;
  letter-spacing: -0.02em;
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}
.brand-text strong { display: block; font-size: 14px; color: var(--text); }
.brand-text small  { color: var(--text-muted); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }

/* ---- SIDEBAR: NAV ---- */
.sidebar nav { flex: 1; }
.nav-section { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.08em; padding: 14px 10px 6px; font-weight: 600; }
.nav-links { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.nav-links a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-weight: 500;
  font-size: 13px;
  transition: background .15s ease, color .15s ease;
}
.nav-links a:hover { background: var(--surface-2); color: var(--text); }
.nav-links a.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.nav-links a.active .icon { color: var(--accent); }
.nav-links .icon {
  width: 18px; height: 18px; flex-shrink: 0;
  color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.nav-links a:hover .icon { color: var(--text-soft); }

/* ---- SIDEBAR: BOTTOM ---- */
.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.theme-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 500;
}
.theme-toggle:hover { background: var(--surface-3); }
.theme-toggle .icon { width: 16px; height: 16px; }
.who-block {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}
.who-name { color: var(--text); font-size: 12px; font-weight: 500; line-height: 1.2; flex: 1; min-width: 0; }
.who-name small { color: var(--text-muted); font-size: 11px; display: block; }
.logout-form button {
  background: transparent; border: none; padding: 4px 6px;
  border-radius: 4px; cursor: pointer;
  color: var(--text-muted); font-size: 12px;
}
.logout-form button:hover { color: var(--accent); background: var(--surface-2); }

/* ---- TILLY FOOTER (product brand below user block) ---- */
.tilly-footer {
  margin-top: 8px;
  padding: 10px 10px 4px;
  border-top: 1px dashed var(--border);
  display: flex; flex-direction: column; gap: 1px;
}
.tilly-wordmark {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
}
.tilly-tagline {
  font-size: 10.5px;
  color: var(--text-faint);
  line-height: 1.3;
}

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: all .15s ease;
  line-height: 1.4;
}
.btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.btn:focus { outline: none; box-shadow: var(--ring); }
.btn.primary {
  background: var(--accent); color: var(--on-accent); border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.btn.danger:hover { background: var(--danger); color: var(--on-accent); border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }

/* ---- CARDS ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin: 14px 0 24px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: box-shadow .15s ease, border-color .15s ease, transform .15s ease;
  position: relative;
  overflow: hidden;
}
.card:hover {
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}
.card-label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-value { font-size: 26px; font-weight: 700; margin: 8px 0 4px; color: var(--text); letter-spacing: -0.02em; }
.card small { color: var(--text-muted); font-size: 12px; display: block; margin-top: 2px; }
.card a { font-size: 12px; color: var(--accent); }
.card.accent {
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--surface) 60%);
  border-color: var(--accent-soft);
}
.card.accent .card-value { color: var(--accent); }
.card.accent::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent);
}
.card.success .card-value { color: var(--ok); }
.card.warn    .card-value { color: var(--warn); }
.card.danger  .card-value { color: var(--danger); }

/* ---- TABLES ---- */
table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table.data th {
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
table.data td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--text);
}
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .12s ease; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .empty { text-align: center; color: var(--text-muted); padding: 28px; font-style: italic; }
table.data tr.pending td { background: var(--pending); color: var(--pending-text); font-style: italic; }
table.data tr.total td { background: var(--surface-2); font-weight: 600; color: var(--accent); }
table.data tr.total-red td { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.num.warn { color: var(--danger); font-weight: 600; }
.num.ok   { color: var(--ok);     font-weight: 600; }

/* ---- FORMS ---- */
form.form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
form.form h2 { margin-top: 8px; }
form.form .row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
form.form label {
  display: block;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}
form.form input[type="text"],
form.form input[type="email"],
form.form input[type="number"],
form.form input[type="date"],
form.form input[type="month"],
form.form input[type="password"],
form.form select,
form.form textarea {
  display: block; width: 100%; margin-top: 6px; padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
form.form input:focus, form.form select:focus, form.form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
form.form textarea { min-height: 80px; resize: vertical; }
form.form .checkbox {
  display: flex; align-items: center; gap: 8px;
  color: var(--text);
  font-size: 13px;
}
form.form .checkbox input { margin: 0; }
form.form .actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- LINE-ITEM TABLES (inside forms) ---- */
.line-items { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.line-items th, .line-items td { padding: 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.line-items th { background: var(--surface-2); color: var(--text-muted); font-size: 11px; text-align: left; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.line-items input { width: 100%; padding: 7px 9px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 13px; color: var(--text); }
.line-items input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.line-items .remove { background: transparent; border: none; color: var(--danger); cursor: pointer; font-size: 14px; padding: 4px 6px; border-radius: 4px; }
.line-items .remove:hover { background: var(--danger-soft); }

/* ---- FLASH ---- */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin: 12px 0;
  font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  border-left: 3px solid;
}
.flash-info    { background: var(--surface-2); color: var(--text);  border-left-color: var(--text-muted); }
.flash-success { background: var(--ok-soft);   color: var(--ok);    border-left-color: var(--ok); }
.flash-error   { background: var(--danger-soft); color: var(--danger); border-left-color: var(--danger); }

/* ---- DETAIL HEADER ---- */
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }
.detail-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.supplier-meta { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.badge {
  display: inline-block; padding: 2px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px; font-size: 11px;
  color: var(--text-soft);
  font-weight: 500;
}

/* ---- AUTH ---- */
body.auth-body {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
body.auth-body .sidebar { display: none; }
body.auth-body main, body.auth-body .container {
  margin-left: 0; width: auto; min-height: auto; padding: 0;
}
.auth-card {
  background: var(--surface);
  padding: 36px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  width: 400px;
  max-width: 90vw;
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-brand strong { display: block; color: var(--text); }
.auth-brand small  { color: var(--text-muted); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }
.auth-card h1 { margin: 12px 0 22px; font-size: 22px; }
.auth-card label { display: block; margin-bottom: 14px; font-size: 12px; color: var(--text-muted); font-weight: 500; }
.auth-card input {
  display: block; width: 100%; margin-top: 6px; padding: 11px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text);
}
.auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.auth-card .btn.primary { width: 100%; justify-content: center; padding: 12px; }
.auth-tilly {
  margin-top: 22px; padding-top: 14px;
  border-top: 1px dashed var(--border);
  text-align: center;
  display: flex; flex-direction: column; gap: 2px;
}
.auth-tilly strong { color: var(--accent); font-size: 13px; letter-spacing: 0.04em; }
.auth-tilly span   { color: var(--text-muted); font-size: 11px; }

/* ---- STATEMENT (HTML preview) ---- */
.statement {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 920px;
  margin: 0 auto;
}
.statement-header { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--accent); }
.statement-header strong { color: var(--accent); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.statement-section { margin: 24px 0; }
.statement-section h3 { color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; font-weight: 600; }
.statement-note {
  background: var(--pending);
  color: var(--pending-text);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin: 12px 0;
  font-size: 13px;
}
.signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 40px; padding-top: 16px; }
.sig-block { border-top: 1px solid var(--text); padding-top: 6px; color: var(--text); }
.sig-block small { color: var(--text-muted); }

/* ---- BULLETS ---- */
ul.bullet { padding-left: 18px; color: var(--text); }
ul.bullet li { margin-bottom: 4px; }

/* ---- MOBILE ---- */
@media (max-width: 900px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    align-items: center;
    padding: 10px 16px;
    gap: 16px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .sidebar .brand { border: none; padding: 0; margin: 0; flex-shrink: 0; }
  .sidebar nav { flex: none; }
  .nav-section { display: none; }
  .nav-links { flex-direction: row; gap: 4px; }
  .nav-links a span { display: none; }
  .nav-links .icon { width: 20px; height: 20px; }
  .sidebar-bottom { flex-direction: row; align-items: center; border: none; padding: 0; margin-left: auto; flex-shrink: 0; gap: 4px; }
  .theme-toggle .label { display: none; }
  .who-block { padding: 4px 8px; }
  .who-name { display: none; }
  body { flex-direction: column; }
  main, .container, body > main { margin-left: 0; padding: 20px 16px; width: 100%; }
}
