/* Textile Trading — shared design system.
   Warm paper ground, deep teal accent, tabular figures for money columns. */

:root {
  --paper:      #faf7f2;
  --surface:    #ffffff;
  --surface-2:  #f4f0e9;
  --line:       #e3ddd2;
  --line-soft:  #eee9e0;
  --ink:        #1f2421;
  --ink-2:      #5b6360;
  --ink-3:      #8a918d;

  --accent:     #0f766e;
  --accent-ink: #0b5952;
  --accent-soft:#d7ece9;

  --pos:        #15803d;
  --pos-soft:   #dcf3e4;
  --neg:        #b42318;
  --neg-soft:   #fbe4e2;
  --warn:       #b45309;
  --warn-soft:  #fbeed6;

  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 1px 2px rgba(31, 36, 33, .05), 0 4px 16px rgba(31, 36, 33, .04);
  --shadow-lg:  0 8px 40px rgba(31, 36, 33, .16);

  --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
  --sidebar-w: 232px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #14181a;
    --surface:    #1b2124;
    --surface-2:  #232a2e;
    --line:       #303940;
    --line-soft:  #262d32;
    --ink:        #e8ece9;
    --ink-2:      #a3aeaa;
    --ink-3:      #76817d;
    --accent:     #4db6a8;
    --accent-ink: #7fd3c6;
    --accent-soft:#1c332f;
    --pos:        #5bbd7d;
    --pos-soft:   #16301f;
    --neg:        #f27a6e;
    --neg-soft:   #33191a;
    --warn:       #e0a458;
    --warn-soft:  #33260f;
    --shadow:     0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.24);
    --shadow-lg:  0 8px 40px rgba(0,0,0,.5);
  }
}

:root[data-theme="dark"] {
  --paper: #14181a; --surface: #1b2124; --surface-2: #232a2e;
  --line: #303940; --line-soft: #262d32;
  --ink: #e8ece9; --ink-2: #a3aeaa; --ink-3: #76817d;
  --accent: #4db6a8; --accent-ink: #7fd3c6; --accent-soft: #1c332f;
  --pos: #5bbd7d; --pos-soft: #16301f; --neg: #f27a6e; --neg-soft: #33191a;
  --warn: #e0a458; --warn-soft: #33260f;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.24);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -.015em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ layout */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-ink));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px;
}
.brand-name { font-weight: 640; letter-spacing: -.02em; font-size: 15px; line-height: 1.15; }
.brand-sub { font-size: 11px; color: var(--ink-3); }

.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-3); padding: 14px 10px 5px; font-weight: 600; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 500; text-decoration: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav-item svg { width: 16px; height: 16px; flex: none; opacity: .85; }

.nav-foot {
  margin-top: auto; padding: 12px 10px 2px; border-top: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 8px;
}
.nav-user { min-width: 0; flex: 1; }
.nav-user-name { font-size: 12.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-user-role { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 18px 28px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.topbar .spacer { flex: 1; }
.page-sub { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.content { padding: 24px 28px 60px; }

/* ------------------------------------------------------------------ pieces */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
}
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }

.grid { display: grid; gap: 16px; }
.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.kpi { padding: 14px 16px; }
.kpi-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; }
.kpi-value { font-size: 25px; font-weight: 650; letter-spacing: -.025em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.kpi.accent { border-left: 3px solid var(--accent); }
.kpi.good  { border-left: 3px solid var(--pos); }
.kpi.bad   { border-left: 3px solid var(--neg); }
.kpi.warn  { border-left: 3px solid var(--warn); }

/* ------------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); font-weight: 650; padding: 10px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
  background: var(--surface); position: sticky; top: 0;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--ink-3); }
.strong { font-weight: 620; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
tfoot td { padding: 11px 12px; border-top: 2px solid var(--line); font-weight: 650; }

.empty { padding: 44px 20px; text-align: center; color: var(--ink-3); }
.empty svg { width: 34px; height: 34px; opacity: .4; margin-bottom: 10px; }

/* ------------------------------------------------------------------ inputs */

label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
textarea { resize: vertical; min-height: 62px; }
.field { margin-bottom: 12px; }
.field-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.search { max-width: 280px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 8px 14px; font: inherit; font-weight: 580; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-danger { color: var(--neg); border-color: var(--line); }
.btn-danger:hover { background: var(--neg-soft); }
.btn-sm { padding: 5px 9px; font-size: 12.5px; }
.btn-icon { padding: 6px; width: 30px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--ink-2);
}
.tag.pos  { background: var(--pos-soft);  color: var(--pos); }
.tag.neg  { background: var(--neg-soft);  color: var(--neg); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.info { background: var(--accent-soft); color: var(--accent-ink); }

/* ------------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 24, 26, .5);
  display: grid; place-items: start center; padding: 40px 16px; z-index: 100;
  overflow-y: auto; backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; border: 1px solid var(--line);
}
.modal.wide { max-width: 940px; }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line-soft); }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 18px; }
.modal-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 14px 18px; border-top: 1px solid var(--line-soft); background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius); flex-wrap: wrap;
}
.modal-foot .spacer { flex: 1; }

.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; }
.alert-error { background: var(--neg-soft); color: var(--neg); border: 1px solid rgba(180,35,24,.2); }
.alert-error ul { margin: 6px 0 0; padding-left: 18px; }
.alert-info { background: var(--accent-soft); color: var(--accent-ink); }

/* ------------------------------------------------------------------- toast */

.toast-host { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  padding: 11px 15px; border-radius: var(--radius-sm); background: var(--ink); color: var(--paper);
  box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 380px; animation: rise .18s ease-out;
}
.toast.err { background: var(--neg); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* -------------------------------------------------------------- line items */

.items-table input, .items-table select { padding: 6px 8px; }
.items-table td { padding: 6px; }
.items-table thead th { position: static; }
.hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

.totals { display: grid; gap: 6px; margin-left: auto; max-width: 320px; }
.totals-row { display: flex; justify-content: space-between; gap: 20px; font-variant-numeric: tabular-nums; }
.totals-row.grand { border-top: 1px solid var(--line); padding-top: 8px; font-weight: 680; font-size: 16px; }
.totals-row.profit { color: var(--pos); font-weight: 620; }

/* -------------------------------------------------------------------- misc */

.bar { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.pos > span { background: var(--pos); }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 46px; }
.spark div { flex: 1; background: var(--accent-soft); border-radius: 2px 2px 0 0; min-height: 2px; }
.spark div.hi { background: var(--accent); }

.chart-row { display: grid; grid-template-columns: 110px 1fr 96px; gap: 10px; align-items: center; padding: 5px 0; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    flex-direction: row; overflow-x: auto; padding: 10px; align-items: center;
  }
  .brand { padding: 0 12px 0 4px; }
  .nav-group { display: none; }
  .nav-item { white-space: nowrap; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
}

@media print {
  .sidebar, .topbar .btn, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
