/* IWT Billing — visual system
   Borrowed from the IWT mark: black outline strokes + olive green fill.
   Heavy 2px ink rules frame the things that matter (money, due dates);
   hairlines carry everything else. */

:root {
  --bg: #F2F3EF;
  --surface: #FFFFFF;
  --ink: #17191B;
  --ink-2: #3B403C;
  --muted: #6A716B;
  --line: #DCE0D8;
  --line-strong: #17191B;
  --green: #567E3B;
  --green-deep: #2F4D1D;
  --green-tint: #E9F1E2;
  --amber: #9A6200;
  --amber-tint: #FAF0D9;
  --red: #AE2A1F;
  --red-tint: #FBE7E4;
  --blue: #2C5A85;
  --blue-tint: #E5EEF6;
  --radius: 6px;
  --font: "IBM Plex Sans", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --shadow-pop: 0 12px 40px rgba(23, 25, 27, .18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--bg); }
a { color: var(--green-deep); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0 0 10px; }
code { font-size: 12.5px; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.ic { flex: none; vertical-align: middle; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
[dir="auto"] { unicode-bidi: plaintext; }

/* ---------- Shell ---------- */
.has-shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-right: 2px solid var(--line-strong); display: flex; flex-direction: column; padding: 18px 12px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 16px; color: var(--ink); font-weight: 600; font-size: 15px; }
.brand img { height: 30px; width: auto; }
.brand span { border-left: 2px solid var(--ink); padding-left: 10px; letter-spacing: .01em; }
.brand:hover { text-decoration: none; }
.search-trigger { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; margin-bottom: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); color: var(--muted); font: inherit; cursor: pointer; }
.search-trigger span { flex: 1; text-align: left; }
.search-trigger kbd { font: 11px var(--font); border: 1px solid var(--line); background: var(--surface); padding: 0 6px; border-radius: 4px; }
.sidebar nav { flex: 1; }
.nav-group { font-size: 12px; color: var(--muted); padding: 14px 10px 4px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius); color: var(--ink-2); font-weight: 500; position: relative; }
.sidebar nav a:hover { background: var(--bg); text-decoration: none; }
.sidebar nav a.active { color: var(--green-deep); background: var(--green-tint); }
.sidebar nav a.active::before { content: ""; position: absolute; left: -12px; top: 6px; bottom: 6px; width: 4px; background: var(--green); border-radius: 0 3px 3px 0; }
.sidebar-user { display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.sidebar-user .who { flex: 1; display: flex; gap: 10px; align-items: center; color: var(--ink); min-width: 0; }
.sidebar-user .who:hover { text-decoration: none; }
.sidebar-user .who span:last-child { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user strong { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user small { color: var(--muted); font-size: 12px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--ink); display: grid; place-items: center; font-weight: 600; background: var(--green-tint); color: var(--green-deep); flex: none; }
.logout { color: var(--muted); padding: 6px; border-radius: var(--radius); }
.logout:hover { color: var(--red); background: var(--red-tint); }

.main { min-width: 0; padding: 22px 32px 60px; max-width: 1480px; }
.topbar { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.topbar .titles { flex: 1; min-width: 240px; }
.topbar h1 { font-size: 26px; font-weight: 600; letter-spacing: -.01em; }
.topbar .subtitle { margin: 4px 0 0; color: var(--muted); }
.topbar .crumb { display: inline-block; font-size: 13px; margin-bottom: 4px; color: var(--muted); }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.nav-toggle { display: none; background: none; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; cursor: pointer; color: var(--ink); align-self: center; }
.scrim { display: none; }

@media (max-width: 960px) {
  .has-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; z-index: 50; width: 260px; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(23,25,27,.35); z-index: 40; }
  .nav-toggle { display: inline-flex; }
  .main { padding: 16px 16px 60px; }
  .topbar h1 { font-size: 22px; }
}

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: var(--radius); font: 500 13.5px var(--font); cursor: pointer; white-space: nowrap; line-height: 1.3; }
.btn:hover { border-color: var(--ink); text-decoration: none; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-deep); border-color: var(--green-deep); }
.btn-ink { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: var(--red-tint); }
.btn-wa { color: #127A3E; }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn-link { background: none; border: none; color: var(--green-deep); padding: 0; font: inherit; cursor: pointer; }
.btn-link.danger { color: var(--red); }
.btn[disabled] { opacity: .5; pointer-events: none; }

label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 4px; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input[type=tel], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #C9CEC5; border-radius: var(--radius); background: #fff; font: 14px var(--font); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-tint); }
textarea { min-height: 70px; resize: vertical; }
input.money { text-align: right; font-variant-numeric: tabular-nums; }
.field { margin-bottom: 14px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 760px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--green); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 6px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { max-width: 280px; }
.filters select, .filters input[type=date] { width: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink-2); font-size: 13px; }
.chip:hover { text-decoration: none; border-color: var(--ink); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip b { font-weight: 600; margin-left: 4px; }

/* ---------- Panels & tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
.panel.framed { border: 2px solid var(--line-strong); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { flex: 1; }
.panel-body { padding: 16px; }
.panel-foot { padding: 10px 16px; border-top: 1px solid var(--line); }

.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-weight: 500; font-size: 12.5px; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #FAFBF9; }
.t td { padding: 9px 12px; border-bottom: 1px solid #ECEEE9; vertical-align: middle; }
.t tr:last-child td { border-bottom: none; }
.t tbody tr:hover td { background: #FAFBF8; }
.t td.actions { text-align: right; white-space: nowrap; }
.t tfoot td { font-weight: 600; border-top: 2px solid var(--ink); background: #FAFBF9; }
.t .sub { display: block; color: var(--muted); font-size: 12.5px; }
.t tr.row-muted td { color: var(--muted); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.badge-green { background: var(--green-tint); color: var(--green-deep); }
.badge-amber { background: var(--amber-tint); color: var(--amber); }
.badge-amber-soft { background: #fff; color: var(--amber); border-color: #E8CF97; }
.badge-red { background: var(--red-tint); color: var(--red); }
.badge-grey { background: #ECEEEA; color: var(--muted); }
.badge-blue { background: var(--blue-tint); color: var(--blue); }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border-left: 4px solid; background: var(--surface); }
.flash-success { border-color: var(--green); background: var(--green-tint); }
.flash-error { border-color: var(--red); background: var(--red-tint); }
.flash-warning { border-color: var(--amber); background: var(--amber-tint); }
.flash-info { border-color: var(--blue); background: var(--blue-tint); }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state h2 { color: var(--ink); margin-bottom: 8px; }
.empty { padding: 26px 16px; text-align: center; color: var(--muted); }

.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; gap: 8px; }
.pager div { display: flex; gap: 6px; }

/* ---------- Figures ---------- */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); background: var(--surface); border: 2px solid var(--line-strong); border-radius: var(--radius); margin-bottom: 18px; }
.figure { padding: 14px 18px; border-right: 1px solid var(--line); }
.figure:last-child { border-right: none; }
.figure-label { color: var(--muted); font-size: 13px; }
.figure-value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; line-height: 1.25; margin-top: 2px; white-space: nowrap; }
.figure-value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.figure-note { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.figure.red .figure-value { color: var(--red); }
.figure.green .figure-value { color: var(--green-deep); }
.figure.amber .figure-value { color: var(--amber); }
.up { color: var(--green-deep); }
.down { color: var(--red); }
@media (max-width: 760px) { .figure { border-right: none; border-bottom: 1px solid var(--line); } }

.cols { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.cols-even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .cols, .cols-even { grid-template-columns: 1fr; } }

/* ---------- Renewal runway (dashboard) ---------- */
.runway { padding: 16px 16px 10px; }
.runway-bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; border-bottom: 2px solid var(--ink); position: relative; }
.runway-bars a { flex: 1; min-width: 4px; background: var(--green); border-radius: 2px 2px 0 0; position: relative; opacity: .9; }
.runway-bars a.empty-day { background: var(--line); height: 3px !important; opacity: 1; }
.runway-bars a.past { background: var(--red); }
.runway-bars a.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.runway-bars a.weekend:not(.past):not(.empty-day) { background: #7A9E60; }
.runway-bars a:hover { opacity: 1; background: var(--green-deep); }
.runway-bars a.past:hover { background: #7E1D15; }
.runway-bars a[data-tip]:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 4px; white-space: pre; z-index: 5; pointer-events: none; }
.runway-scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding-top: 6px; }
.runway-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); padding: 0 16px 14px; flex-wrap: wrap; }
.runway-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Detail layouts ---------- */
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--ink); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); font-weight: 500; border-radius: var(--radius) var(--radius) 0 0; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { background: var(--ink); color: #fff; }
.tabs a .count { font-weight: 400; opacity: .75; margin-left: 4px; }

.balance-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; border: 2px solid var(--ink); border-radius: var(--radius); background: var(--surface); margin-bottom: 18px; }
.balance-strip div { padding: 10px 14px; border-right: 1px solid var(--line); }
.balance-strip div:last-child { border-right: 0; }
.balance-strip span { display: block; color: var(--muted); font-size: 12.5px; }
.balance-strip strong { font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Invoice editor ---------- */
.lines th:nth-child(1) { width: 46%; }
.lines td { vertical-align: top; }
.lines input { padding: 6px 8px; }
.lines .amount-cell { padding-top: 14px; }
.totals { margin-left: auto; width: 100%; max-width: 380px; }
.totals .row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; gap: 12px; }
.totals .row input { max-width: 150px; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; font-size: 18px; font-weight: 600; }
.picker { position: relative; }
.picker-list { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--ink); border-radius: var(--radius); max-height: 280px; overflow-y: auto; box-shadow: var(--shadow-pop); }
.picker-list button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; font: inherit; cursor: pointer; border-bottom: 1px solid #F0F1EE; }
.picker-list button:hover, .picker-list button.hl { background: var(--green-tint); }
.picker-list small { display: block; color: var(--muted); }
.svc-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
.svc-suggest button { border: 1px dashed #B9C0B4; background: #fff; padding: 5px 10px; border-radius: var(--radius); font: 13px var(--font); cursor: pointer; text-align: left; }
.svc-suggest button:hover { border-style: solid; border-color: var(--green); background: var(--green-tint); }
.svc-suggest button small { color: var(--muted); display: block; font-size: 11.5px; }

/* ---------- Invoice document ---------- */
.doc { background: #fff; border: 2px solid var(--ink); border-radius: var(--radius); padding: 36px 40px; max-width: 900px; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--ink); padding-bottom: 20px; margin-bottom: 20px; }
.doc-head img { height: 58px; }
.doc-title { text-align: right; }
.doc-title .word { font-size: 30px; font-weight: 700; letter-spacing: -.01em; }
.doc-title .ar { font-family: "IBM Plex Sans Arabic", var(--font); font-size: 16px; color: var(--muted); }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 22px; }
.doc-parties h3 { font-size: 12.5px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.doc .t th { background: #fff; color: var(--ink); border-bottom: 2px solid var(--ink); }
.doc-totals { display: flex; justify-content: flex-end; margin-top: 12px; }
.doc-foot { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 20px; }
.paid-stamp { display: inline-block; border: 3px solid var(--green); color: var(--green); font-weight: 700; font-size: 20px; padding: 2px 14px; transform: rotate(-6deg); border-radius: 4px; }
.review-note { background: var(--amber-tint); border: 1px solid #E8CF97; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; }
@media (max-width: 700px) { .doc { padding: 20px; } .doc-head, .doc-parties { grid-template-columns: 1fr; flex-direction: column; } .doc-title { text-align: left; } }

/* ---------- Dialogs ---------- */
dialog { border: 2px solid var(--ink); border-radius: 8px; padding: 0; max-width: 560px; width: calc(100% - 32px); box-shadow: var(--shadow-pop); color: var(--ink); }
dialog::backdrop { background: rgba(23,25,27,.4); }
dialog .dlg-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
dialog .dlg-body { padding: 18px; }
dialog .dlg-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.search-dialog { max-width: 640px; margin-top: 10vh; }
.search-box { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.search-box input { border: none; box-shadow: none !important; font-size: 16px; padding: 4px 0; }
.search-results { max-height: 60vh; overflow-y: auto; }
.search-results .hint { padding: 14px 16px; color: var(--muted); margin: 0; }
.search-results .grp { font-size: 12px; color: var(--muted); padding: 10px 16px 4px; }
.search-results a { display: flex; justify-content: space-between; gap: 10px; padding: 8px 16px; color: var(--ink); }
.search-results a small { color: var(--muted); }
.search-results a.hl, .search-results a:hover { background: var(--green-tint); text-decoration: none; }

/* ---------- Permission matrix ---------- */
.perm-group { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.perm-group h3 { padding: 9px 14px; border-bottom: 1px solid var(--line); background: #FAFBF9; display: flex; justify-content: space-between; align-items: center; }
.perm-row { display: grid; grid-template-columns: 1fr 90px 90px 90px; align-items: center; padding: 7px 14px; border-bottom: 1px solid #F0F1EE; gap: 8px; }
.perm-row:last-child { border-bottom: none; }
.perm-row code { font-size: 11.5px; color: var(--muted); background: none; padding: 0; }
.perm-row .c { text-align: center; }
.perm-simple { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; padding: 10px 14px; }

/* ---------- Auth pages ---------- */
.bare { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 2px solid var(--ink); border-radius: 8px; padding: 32px; }
.auth-card img { height: 54px; margin-bottom: 18px; }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 10px; margin-top: 6px; }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }
.bar-list { list-style: none; margin: 0; padding: 0; }
.bar-list li { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr auto; gap: 10px; align-items: center; padding: 6px 0; }
.bar-list .track { height: 10px; background: #ECEEE9; border-radius: 5px; overflow: hidden; }
.bar-list .track span { display: block; height: 100%; background: var(--green); }

/* ---------- Print ---------- */
@media print {
  @page { margin: 12mm; }
  body { background: #fff; }
  .sidebar, .topbar, .no-print, .flash, .scrim { display: none !important; }
  .has-shell { display: block; }
  .main { padding: 0; max-width: none; }
  .doc { border: none; padding: 0; max-width: none; }
  a { color: inherit; }
}
