/* Al Falah TraceChain — showcase UI */
:root {
  color-scheme: light;
  --brand: #0e5c40;
  --brand-dark: #0a4530;
  --brand-ink: #dff3ea;
  --gold: #c9a227;

  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: #e1e0d9;
  --baseline: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--series-1); }
h1, h2, h3 { margin: 0; font-weight: 650; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px;
  background: var(--brand-dark);
  color: var(--brand-ink);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.side-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.side-brand .co { font-weight: 700; font-size: 15px; color: #fff; letter-spacing: 0.2px; }
.side-brand .prod { font-size: 12px; color: var(--brand-ink); margin-top: 2px; }
.side-brand .prod b { color: var(--gold); font-weight: 650; }
.nav { padding: 10px 8px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin: 2px 0;
  border-radius: 8px;
  color: var(--brand-ink); text-decoration: none; font-weight: 500;
}
.nav a svg { flex: 0 0 18px; opacity: 0.85; }
.nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav a.active { background: rgba(255,255,255,0.14); color: #fff; }
.side-foot {
  padding: 14px 18px; font-size: 12px;
  border-top: 1px solid rgba(255,255,255,0.12);
  color: rgba(223,243,234,0.75);
}
.side-foot .user { color: #fff; font-weight: 600; font-size: 13px; }
.side-foot button {
  margin-top: 8px; width: 100%;
  background: transparent; color: var(--brand-ink);
  border: 1px solid rgba(255,255,255,0.25); border-radius: 7px;
  padding: 6px 10px; font-size: 12.5px;
}
.side-foot button:hover { background: rgba(255,255,255,0.1); color: #fff; }

.main { flex: 1; min-width: 0; padding: 26px 32px 48px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-size: 21px; }
.page-head .sub { color: var(--ink-2); margin-top: 3px; font-size: 13.5px; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- cards & grid ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 12px;
  padding: 18px 20px;
}
.card + .card { margin-top: 16px; }
.card h2 { font-size: 15px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: 1.1fr 1fr; align-items: start; }
@media (max-width: 980px) { .grid.two { grid-template-columns: 1fr; } }

/* ---------- stat tiles ---------- */
.tile { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 14px 16px; }
.tile .label { color: var(--ink-2); font-size: 12.5px; font-weight: 550; }
.tile .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.tile .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile .hint.good { color: var(--good-text); }
.tile .hint.bad { color: var(--critical); }

/* ---------- bar rows (stock by grade) ---------- */
.bar-row { display: grid; grid-template-columns: 110px 1fr 86px; align-items: center; gap: 10px; padding: 7px 0; }
.bar-row .bl { font-size: 13px; color: var(--ink-2); font-weight: 550; }
.bar-row .track { background: transparent; height: 18px; position: relative; }
.bar-row .fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--series-1); border-radius: 0 4px 4px 0;
  min-width: 2px;
}
.bar-row .bv { font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }

/* ---------- tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-weight: 600; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px;
  padding: 8px 10px; border-bottom: 1px solid var(--hairline);
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--hairline); vertical-align: top; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.clickable:hover td { background: #f4f4f1; cursor: pointer; }
.tbl .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-scroll { overflow-x: auto; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px;
  white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.good { color: var(--good-text); background: #e2f5e2; }
.badge.warn { color: #7a5200; background: #fdf0d2; }
.badge.serious { color: #8a3417; background: #fbe6dd; }
.badge.critical { color: #8f1f1f; background: #f9dede; }
.badge.neutral { color: var(--ink-2); background: #eeeeea; }
.badge.chain { color: #123e73; background: #dcE9fa; }

.grade-chip {
  display: inline-block; min-width: 22px; text-align: center;
  font-weight: 700; font-size: 12px; border-radius: 6px; padding: 2px 6px;
  border: 1px solid var(--ring); background: #f2f2ef; color: var(--ink-2);
}
.grade-chip.A { background: #dff3ea; color: #0a4530; border-color: #b8e0cd; }
.grade-chip.B { background: #e4edfb; color: #123e73; border-color: #bcd4f2; }
.grade-chip.C { background: #f3ecdc; color: #6b5410; border-color: #e2d4ac; }

/* ---------- buttons ---------- */
.btn {
  border-radius: 8px; border: 1px solid var(--ring);
  background: var(--surface); color: var(--ink);
  padding: 7px 14px; font-weight: 600; font-size: 13px;
}
.btn:hover { background: #f1f1ee; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--baseline); border-radius: 8px;
  background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(42,120,214,0.35); border-color: var(--series-1);
}
.form-actions { margin-top: 14px; display: flex; gap: 10px; align-items: center; }
.form-msg { font-size: 13px; }
.form-msg.err { color: var(--critical); }
.form-msg.ok { color: var(--good-text); }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(10, 20, 16, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; z-index: 50; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px;
  width: 100%; max-width: 640px;
  padding: 22px 24px; border: 1px solid var(--ring);
  box-shadow: 0 18px 50px rgba(0,0,0,0.22);
}
.modal h2 { font-size: 16px; margin-bottom: 14px; }
.modal .close-row { display: flex; justify-content: flex-end; margin-top: 4px; }

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; }
.timeline li { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--hairline); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 2px; }
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 2px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--series-1); border: 2px solid var(--surface);
}
.timeline li.delay::before { background: var(--serious); }
.timeline .t-stage { font-weight: 600; font-size: 13.5px; }
.timeline .t-ts { color: var(--muted); font-size: 12px; }
.timeline .t-note { color: var(--ink-2); font-size: 13px; margin-top: 1px; }

/* ---------- ledger ---------- */
.hash { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; color: var(--ink-2); }
.block-type { font-weight: 600; font-size: 12.5px; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--hairline); align-items: baseline; }
.feed li:last-child { border-bottom: none; }
.feed .f-idx { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; flex: 0 0 34px; }
.feed .f-main { flex: 1; min-width: 0; }
.feed .f-desc { font-size: 13.5px; }
.feed .f-meta { font-size: 12px; color: var(--muted); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--brand-dark) 0%, var(--brand) 55%, #147a55 100%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border-radius: 16px;
  padding: 34px 34px 30px; box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}
.login-card .mark { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-card .mark .logo-badge {
  width: 44px; height: 44px; border-radius: 11px;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; letter-spacing: 0.5px;
}
.login-card h1 { font-size: 18px; }
.login-card .sub { color: var(--ink-2); font-size: 13px; margin: 2px 0 22px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; padding: 10px; font-size: 14px; }
.login-foot { text-align: center; color: var(--muted); font-size: 11.5px; margin-top: 18px; }

/* ---------- verify page ---------- */
.verify-wrap { max-width: 860px; margin: 0 auto; padding: 40px 20px 70px; }
.verify-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.verify-head .logo-badge {
  width: 46px; height: 46px; border-radius: 12px; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 19px;
}
.prov-bale { border: 1px solid var(--hairline); border-radius: 10px; padding: 14px 16px; margin-top: 12px; }
.prov-bale .pb-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.prov-parent { margin: 10px 0 0 18px; padding-left: 14px; border-left: 2px dashed var(--baseline); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- mobile ---------- */
.menu-btn { display: none; background: transparent; border: 0; color: #fff; padding: 6px; }
.tbl-scroll { -webkit-overflow-scrolling: touch; }
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: sticky; top: 0; width: 100%; flex: none; height: auto;
    z-index: 40; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  }
  .side-brand {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 16px; border-bottom: none;
  }
  .menu-btn { display: inline-flex; align-items: center; }
  .nav, .side-foot { display: none; }
  body.nav-open .nav { display: block; border-top: 1px solid rgba(255,255,255,0.12); padding: 8px; }
  body.nav-open .side-foot { display: block; }
  .nav a { padding: 12px 14px; font-size: 15px; }
  .main { padding: 16px 14px 44px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head h1 { font-size: 19px; }
  .card { padding: 14px; border-radius: 10px; }
  .grid.kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tile { padding: 12px 14px; }
  .tile .value { font-size: 22px; }
  .bar-row { grid-template-columns: 82px 1fr 76px; gap: 8px; }
  .bar-row .bl, .bar-row .bv { font-size: 12.5px; }
  .btn { padding: 9px 14px; }
  .btn.small { padding: 7px 11px; }
  .tbl th, .tbl td { padding: 8px; }
  .tbl-scroll .tbl { min-width: 560px; }
  .tbl th { white-space: nowrap; }
  .modal-back { padding: 12px 10px; }
  .modal { padding: 16px; border-radius: 12px; }
  .form-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .field input, .field select, .field textarea { padding: 9px 10px; }
  .kv { grid-template-columns: 118px 1fr; }
  .verify-wrap { padding: 22px 14px 50px; }
  .verify-head h1 { font-size: 16px !important; }
  .login-card { padding: 26px 22px 24px; }
}
@media (max-width: 420px) {
  .form-grid { grid-template-columns: 1fr; }
  .head-actions .btn { flex: 1; }
}

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt { margin-top: 14px; }
.copy-link { font-size: 12.5px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; font-size: 13.5px; }
