/* SiaMaker — design system */
:root {
  --bg: #f8f6f2;
  --surface: #ffffff;
  --surface-2: #f2efe9;
  --border: #e4dfd6;
  --text: #1f2421;
  --muted: #6b7068;
  --primary: #0f5c55;
  --primary-ink: #ffffff;
  --primary-soft: #e1efec;
  --accent: #d26a2e;
  --accent-soft: #fbeadf;
  --ok: #1d7a46;
  --ok-soft: #e1f3e8;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --info: #1e5aa8;
  --info-soft: #e5eefb;
  --warn: #9a6200;
  --warn-soft: #fdf1d8;
  --shadow: 0 1px 2px rgba(31, 36, 33, .06), 0 2px 8px rgba(31, 36, 33, .04);
  --radius: 12px;
  --radius-sm: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Arabic", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141716;
    --surface: #1c201f;
    --surface-2: #232826;
    --border: #2f3533;
    --text: #e8ebe9;
    --muted: #9aa29e;
    --primary: #3fb3a5;
    --primary-ink: #08201d;
    --primary-soft: #183531;
    --accent: #f08a4b;
    --accent-soft: #3a2518;
    --ok: #5ccf8b;
    --ok-soft: #173525;
    --bad: #ff8577;
    --bad-soft: #3d1c19;
    --info: #7fb2ff;
    --info-soft: #1a2a42;
    --warn: #f2bd5c;
    --warn-soft: #3a2d12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- app shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--text); margin: 0 8px 18px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--primary); color: var(--primary-ink); font-weight: 800; }
.ws-name { font-size: .8rem; color: var(--muted); margin: -12px 8px 16px 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-section { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 12px 4px; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); font-size: .85rem; }
.sidebar-foot form { display: inline; }
.linkish { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; }
.linkish:hover { text-decoration: underline; }
.main { padding: 28px 32px 60px; min-width: 0; }
.container { max-width: 1180px; margin: 0 auto; }
.topbar { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; max-width: 300px; z-index: 50; transform: translateX(-105%); transition: transform .2s ease; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 40; }
  .topbar .brand { margin: 0; }
  .main { padding: 20px 16px 60px; }
}
.menu-btn { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px; color: var(--text); font: inherit; cursor: pointer; }

/* ---------------------------------------------------------------- page parts */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin: 4px 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.crumb { font-size: .85rem; color: var(--muted); margin-bottom: 6px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; min-width: 0; }
.card > h2:first-child, .card > .card-head:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: 16px 20px 0; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .cols, .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 1400px) { .grid-2.stack-lg { grid-template-columns: 1fr; } }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label { color: var(--muted); font-size: .82rem; font-weight: 500; }
.kpi .value { font-size: 1.45rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .delta { font-size: .8rem; margin-top: 2px; color: var(--muted); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table tfoot td { font-weight: 700; border-bottom: 0; }
.table.compact th, .table.compact td { padding: 7px 10px; }
.table td.num, .table th.num { text-align: right; }
.card.flush .table th:first-child, .card.flush .table td:first-child { padding-left: 20px; }
.card.flush .table th:last-child, .card.flush .table td:last-child { padding-right: 20px; }
.row-link { color: var(--text); font-weight: 600; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h3 { color: var(--text); }

/* ---------------------------------------------------------------- badges, alerts */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-muted { background: var(--surface-2); color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.chip { display: inline-flex; align-items: center; font-size: .8rem; color: var(--muted); }

.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid transparent; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------------------------------------------------------------- forms */
.form label, label.field { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 14px; }
.form small, .hint { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; margin-top: 5px; min-height: 40px; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; margin: 0 8px 0 0; accent-color: var(--primary); }
input[type=color] { padding: 2px; height: 40px; width: 56px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
.check { display: flex !important; align-items: center; font-weight: 500 !important; }
.field-error { color: var(--bad); font-size: .8rem; font-weight: 500; margin-top: 4px; display: block; }
.has-error input, .has-error select { border-color: var(--bad); }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.inline-form label { margin: 0; flex: 1 1 140px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.toolbar input, .toolbar select { margin: 0; width: auto; min-width: 140px; flex: 0 1 auto; }
.toolbar input[type=search] { flex: 1 1 200px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* ---------------------------------------------------------------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .9rem; padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; min-height: 40px; white-space: nowrap; }
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, black); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .82rem; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }

/* ---------------------------------------------------------------- charts */
.bars { display: flex; align-items: flex-end; gap: 14px; height: 200px; padding: 10px 4px 0; border-bottom: 1px solid var(--border); }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; min-width: 0; }
.bar-pair { display: flex; gap: 4px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bar { width: 40%; max-width: 30px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bar.rev { background: var(--primary); }
.bar.cost { background: var(--accent); }
.bar-labels { display: flex; gap: 14px; padding: 6px 4px 0; }
.bar-labels span { flex: 1; text-align: center; font-size: .78rem; color: var(--muted); }
.legend { display: flex; gap: 16px; font-size: .8rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.meter { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.stat-list { list-style: none; padding: 0; margin: 0; }
.stat-list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.stat-list li:last-child { border-bottom: 0; }
.stat-list .total { font-weight: 700; border-top: 1px solid var(--border); border-bottom: 0; margin-top: 4px; padding-top: 10px; }

.order-lines td { vertical-align: top; }
.order-lines input, .order-lines select { margin: 0; }
.totals { margin-left: auto; max-width: 360px; }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 12px; }
.anchor-nav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }

/* ---------------------------------------------------------------- public pages */
body.public { background: var(--bg); }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.auth-card.wide { max-width: 560px; }
.auth-card .brand { margin: 0 0 20px; }
.auth-alt { text-align: center; margin-top: 16px; font-size: .9rem; color: var(--muted); }
.steps li { margin-bottom: 8px; }

.site-nav { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; max-width: 1180px; margin: 0 auto; }
.site-nav .brand { margin: 0; }
.hero { max-width: 1180px; margin: 0 auto; padding: 56px 24px 40px; display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; align-items: center; }
.hero h1 { font-size: clamp(2rem, 4.5vw, 3.2rem); line-height: 1.08; letter-spacing: -.025em; margin-bottom: 18px; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p.lead { font-size: 1.12rem; color: var(--muted); max-width: 34em; }
.hero .cta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.hero-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 22px; box-shadow: 0 20px 50px rgba(15, 92, 85, .12); }
.hero-card .row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px dashed var(--border); gap: 10px; }
.hero-card .row:last-child { border-bottom: 0; }
.features { max-width: 1180px; margin: 0 auto; padding: 24px 24px 64px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.feature { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.feature .ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); margin-bottom: 12px; }
.feature .ico svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.feature p { color: var(--muted); margin: 0; font-size: .93rem; }
.band { background: var(--primary); color: var(--primary-ink); }
.band .inner { max-width: 1180px; margin: 0 auto; padding: 44px 24px; display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; }
.band h2 { font-size: 1.5rem; margin: 0; }
.band .btn { background: var(--primary-ink); color: var(--primary); border-color: transparent; }
.site-foot { max-width: 1180px; margin: 0 auto; padding: 24px; color: var(--muted); font-size: .85rem; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; padding-top: 24px; gap: 28px; }
  .features { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .features { grid-template-columns: 1fr; }
  .site-nav { padding: 14px 16px; }
  .hero, .features { padding-left: 16px; padding-right: 16px; }
  .auth-card { padding: 24px 20px; }
}

/* ---------------------------------------------------------------- invoice / print */
.invoice { max-width: 820px; margin: 24px auto; background: #fff; color: #1f2421; padding: 48px; border: 1px solid #e4dfd6; border-radius: 12px; }
.invoice table { width: 100%; border-collapse: collapse; }
.invoice th, .invoice td { padding: 8px 6px; border-bottom: 1px solid #e4dfd6; text-align: left; }
.invoice .num { text-align: right; }
.invoice-head { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 32px; flex-wrap: wrap; }
.invoice-title { font-size: 1.8rem; font-weight: 800; color: #0f5c55; margin: 0; }
.print-bar { max-width: 820px; margin: 16px auto 0; display: flex; gap: 8px; justify-content: flex-end; padding: 0 16px; }
@media (max-width: 600px) { .invoice { padding: 24px 18px; margin: 12px; } }
@media print {
  .print-bar, .no-print { display: none !important; }
  body { background: #fff; }
  .invoice { border: 0; margin: 0; padding: 0; max-width: none; }
}
