/* Only LOGICAL CSS properties (margin-inline-start, not margin-left) -
   BUILD-PLAN.md P1.S6: the same layout must work in Arabic's right-to-left
   and Turkish/English's left-to-right without a second stylesheet. The
   <html dir> attribute (set by web/app.mjs from the active language) is what
   flips "inline-start" between left and right - the CSS never says which. */

/* ---- design tokens ---------------------------------------------------
   This is the day-long working tool for a wholesale distributor's sales
   desk - a trade ledger, not a startup marketing site. The palette and the
   numeral treatment below come from that: warm paper, deep ledger ink, and
   an ochre "customs stamp" accent (goods/quantities/duty stamps are the
   visual language of wholesale trade, not app-store blue or SaaS violet).
   No web font is loaded on purpose - this app has a hard no-CDN, no-build
   rule (BUILD-PLAN.md §2; the dev-tunnel workflow must work offline), so
   the type system builds hierarchy from the same system stack with weight,
   size and one deliberate switch to tabular monospace for anything that is
   a quantity, price or code - the one place a distinctive numeral face earns
   its keep in a multilingual (AR/TR/EN) admin tool. */
:root {
  --bg: #eaede2;
  --surface: #ffffff;
  --surface-sunken: #e2e6d7;
  --ink: #182a22;
  --muted: #5c6b5c;
  --line: #cfd6c2;

  --accent: #9c6b17;
  --accent-deep: #7a5310;
  --accent-soft: #f1e6cd;
  --accent-ink: #ffffff;

  --danger: #9c3e23;
  --danger-soft: #f4e1d6;
  --good: #33623f;
  --good-soft: #e1ebdc;
  --warn: #8a6414;
  --warn-soft: #f6efd9;

  --sidebar-bg: #152018;
  --sidebar-fg: #dee4d4;
  --sidebar-muted: #91a08c;
  --sidebar-line: rgba(255, 255, 255, 0.09);

  --font-ui: "Segoe UI", Tahoma, Arial, sans-serif;
  --font-num: Consolas, "Courier New", monospace;

  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 var(--font-ui);
  min-inline-size: 320px;
}

[dir="rtl"] body { font-family: var(--font-ui); }

button, input, select, textarea { font: inherit; color: inherit; }

/* One visible focus ring everywhere, not per-widget - a quiet accessibility
   floor rather than a decorative flourish. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: no-preference) {
  .nav-link, .btn-primary, .btn-outline, .board-card, button { transition: background-color .12s ease, border-color .12s ease, color .12s ease; }
}

.app-shell { display: flex; min-block-size: 100vh; }

/* The sidebar reads as the ledger's spine: dark, fixed, the one place color
   is used structurally rather than decoratively. */
.sidebar {
  inline-size: 216px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  padding-block: 18px;
  padding-inline: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .01em;
  margin-block: 0 18px;
  padding-inline: 10px;
  color: #fff;
}

.nav-link {
  display: block;
  padding-block: 8px;
  padding-inline: 10px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--ink);
  cursor: pointer;
  border: 0;
  border-inline-start: 3px solid transparent;
  background: transparent;
  text-align: start;
  font-size: 13.5px;
}
/* Inside the dark sidebar, a nav-link is light text; everywhere else (the
   topbar logout button, table row actions...) it stays ink-on-paper. The
   sidebar rule below only applies to links actually inside .sidebar. */
.sidebar .nav-link { color: var(--sidebar-muted); }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, .06); color: var(--sidebar-fg); }
.sidebar .nav-link[aria-current="page"] {
  background: rgba(156, 107, 23, .18);
  border-inline-start-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.nav-link:hover { background: var(--bg); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-deep); font-weight: 600; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 10px;
  padding-inline: 18px;
  border-block-end: 1px solid var(--line);
  background: var(--surface);
  gap: 12px;
  flex-wrap: wrap;
}

.demo-banner {
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  padding-block: 3px;
  padding-inline: 10px;
  border-radius: 999px;
}

.content { padding: 20px; flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-block-start: 2px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  max-inline-size: 60ch;
}

select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding-block: 4px;
  padding-inline: 8px;
}

/* ---- login screen ---- */
.login-page {
  min-block-size: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--sidebar-bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-block-start: 3px solid var(--accent);
  border-radius: 10px;
  padding: 28px;
  inline-size: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 19px; font-weight: 700; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; color: var(--muted); }
.field input {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding-block: 8px;
  padding-inline: 10px;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 6px;
  padding-block: 9px;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-deep); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.error-text { color: var(--danger); font-size: 13px; }

/* ---- the workspace screens (P3.S1, P3.S2, P4.S1-S6, P5.S2, P5.S3) ---- */
.screen { display: flex; flex-direction: column; gap: 14px; }
.screen.with-drawer { flex-direction: row; align-items: flex-start; gap: 16px; }
.screen-main { flex: 1; min-inline-size: 0; display: flex; flex-direction: column; gap: 14px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.toolbar-title {
  margin: 0; font-size: 15.5px; font-weight: 700;
  padding-block-end: 6px; border-block-end: 2px solid var(--accent-soft);
}
.search {
  border: 1px solid var(--line); border-radius: 6px;
  padding-block: 7px; padding-inline: 10px; min-inline-size: 220px; background: var(--surface);
}
.btn-inline { inline-size: auto; padding-inline: 14px; }
.btn-outline { border: 1px solid var(--line); background: var(--surface); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent-deep); }
.nav-link.danger, .btn-outline.danger { color: var(--danger); }
.tabs { display: flex; gap: 4px; }
.tabs .nav-link.active { background: var(--accent-soft); color: var(--accent-deep); font-weight: 600; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table.data { inline-size: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: start; font-weight: 700; color: var(--muted); font-size: 11.5px;
  letter-spacing: .01em;
  padding-block: 9px; padding-inline: 10px; border-block-end: 2px solid var(--accent-soft); white-space: nowrap;
}
table.data td { padding-block: 9px; padding-inline: 10px; border-block-start: 1px solid var(--line); vertical-align: top; }
table.data tbody tr:nth-child(even) td { background: var(--bg); }
/* Ledger numerals: quantities, prices and codes set in tabular monospace so
   columns of figures line up the way they would on a real invoice. */
table.data td.num { text-align: end; font-variant-numeric: tabular-nums; font-family: var(--font-num); }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--accent-soft); }
table.data tr.selected td { background: var(--accent-soft); }
table.data.compact { font-size: 13px; }
.mono { font-family: var(--font-num); }

.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  padding-block: 2px; padding-inline: 8px; border-radius: 999px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line);
}
.badge-good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.empty { color: var(--muted); font-size: 13px; padding-block: 12px; }
.empty.small { padding-block: 4px; font-size: 12px; }
.notice {
  background: var(--good-soft); color: var(--good); border-radius: 8px;
  padding-block: 10px; padding-inline: 12px; font-size: 13px;
}
/* "It worked, but not all of it" - a quote that was sent without its PDF.
   Not an error (nothing was lost) and not a plain success either. */
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.hint { color: var(--muted); font-size: 12.5px; margin-block: 6px 0; }
.hint.warn { color: var(--danger); }
.error-list { margin-block: 6px 0; padding-inline-start: 18px; font-size: 12.5px; }

.form-card { max-inline-size: none; display: flex; flex-direction: column; gap: 12px; }
.form-card h3 { margin: 0; font-size: 15px; font-weight: 700; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.field span { font-size: 12.5px; color: var(--muted); }
.field input, .field select, .field textarea {
  inline-size: 100%; border: 1px solid var(--line); border-radius: 6px;
  padding-block: 8px; padding-inline: 10px; background: var(--surface); font: inherit;
}
.row-actions { display: flex; gap: 8px; align-items: center; }
.row-actions.wrap { flex-wrap: wrap; }
.checks { display: flex; gap: 12px; flex-wrap: wrap; }
.check-row { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; cursor: pointer; }

/* deal board */
.board { display: flex; gap: 10px; overflow-x: auto; padding-block-end: 4px; align-items: flex-start; }
.board-col {
  flex: 0 0 200px; background: var(--surface); border: 1px solid var(--line);
  border-block-start: 2px solid var(--line);
  border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.board-col header { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.board-col .count, .task-col .count { background: var(--bg); border-radius: 999px; padding-inline: 7px; font-size: 11.5px; }
.board-card {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px; font-size: 13px;
  cursor: pointer; background: var(--surface);
}
.board-card:hover, .board-card.selected { border-color: var(--accent); }
.board-card .muted { font-size: 12px; }

/* tasks */
.task-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; align-items: start; }
.task-col { max-inline-size: none; }
.task-col h3 { margin-block: 0 8px; font-size: 14px; font-weight: 700; display: flex; gap: 8px; align-items: center; }
.task-col.overdue h3 { color: var(--danger); }

/* detail drawer */
.drawer {
  inline-size: 330px; flex-shrink: 0; background: var(--surface);
  border: 1px solid var(--line); border-block-start: 2px solid var(--accent);
  border-radius: 8px;
  max-block-size: calc(100vh - 120px); display: flex; flex-direction: column;
}
.drawer-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding-block: 10px; padding-inline: 14px; border-block-end: 1px solid var(--line);
}
.drawer-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.drawer-body { padding-block: 12px; padding-inline: 14px; overflow-y: auto; }
.drawer-body h4 { margin-block: 14px 6px; font-size: 12.5px; color: var(--muted); font-weight: 700; }

.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.plain-list.two-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.plain-list.timeline li { border-inline-start: 3px solid var(--line); padding-inline-start: 8px; }
.plain-list.timeline li.out { border-inline-start-color: var(--accent); }
.muted { color: var(--muted); }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; margin-block: 8px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* reports - stat tiles read like ledger totals: a rule above the number,
   not a card doing double duty as decoration. */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-block-end: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-block-start: 2px solid var(--accent);
  border-radius: 8px;
  padding: 12px; display: flex; flex-direction: column; gap: 2px;
}
.stat.stat-bad { border-color: var(--danger); background: var(--danger-soft); }
.stat.stat-bad .stat-value { color: var(--danger); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; font-family: var(--font-num); }
.stat-hint { font-size: 11.5px; color: var(--muted); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; align-items: start; }
.two-col .card { max-inline-size: none; }
.two-col .card h3 { margin-block: 0 8px; font-size: 14px; font-weight: 700; }

/* ---- notification bell (topbar) ---- */
.bell-wrap { position: relative; }
.bell-btn {
  position: relative; background: transparent; border: 0; cursor: pointer;
  border-radius: 6px; padding: 6px 8px; font-size: 17px; line-height: 1; color: var(--ink);
}
.bell-btn:hover { background: var(--bg); }
.bell-dot {
  position: absolute; inset-block-start: 2px; inset-inline-end: 2px;
  min-inline-size: 15px; block-size: 15px; padding-inline: 3px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-family: var(--font-num);
}
.bell-panel {
  position: absolute; inset-block-start: calc(100% + 8px); inset-inline-end: 0;
  inline-size: 320px; max-inline-size: calc(100vw - 32px); max-block-size: 420px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-block-start: 2px solid var(--accent);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(21, 32, 24, .16); z-index: 50;
}
.bell-panel h3 { margin: 0; padding-block: 10px; padding-inline: 14px; font-size: 13.5px; font-weight: 700; border-block-end: 1px solid var(--line); }
.notif-item { padding-block: 10px; padding-inline: 14px; border-block-end: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.notif-item:last-child { border-block-end: 0; }
.notif-item:hover { background: var(--bg); }
.notif-item.unread { background: var(--accent-soft); }
.notif-item.unread:hover { background: var(--accent-soft); filter: brightness(0.97); }
.notif-time { color: var(--muted); font-size: 11.5px; margin-block-start: 2px; }

/* Visually hidden but still read by screen readers (the language switcher's
   label). Used by app.mjs since P1.S6 but never defined, so the word
   "Language" showed in the topbar. */
.sr-only {
  position: absolute; inline-size: 1px; block-size: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---- inbox: list | conversation | contact panel ----------------------
   Three columns on a wide screen. Below 1100px there is no room for three,
   so it becomes one pane at a time (list -> conversation -> details) with a
   back button - MEASURED 24 Sep 2026 at 375px: the fixed 280px list left the
   conversation a one-word-wide column. */
.inbox {
  display: flex; block-size: calc(100vh - 110px); min-block-size: 420px;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface);
}
.inbox-list { inline-size: 280px; border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; flex-shrink: 0; }
.inbox-filters { padding: 10px; display: flex; flex-direction: column; gap: 6px; border-block-end: 1px solid var(--line); }
.inbox-filters input { border: 1px solid var(--line); border-radius: 6px; padding-block: 7px; padding-inline: 10px; }
.inbox-filters .row { display: flex; gap: 6px; flex-wrap: wrap; }
.inbox-items { flex: 1; overflow-y: auto; }
.inbox-item { padding-block: 10px; padding-inline: 12px; border-block-end: 1px solid var(--line); cursor: pointer; }
.inbox-item.selected { background: var(--bg); }
.inbox-item .top { display: flex; justify-content: space-between; gap: 6px; font-size: 13.5px; font-weight: 600; }
.inbox-item .sub { font-size: 12px; color: var(--muted); }
.inbox-item .last { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-thread { flex: 1; display: flex; flex-direction: column; min-inline-size: 0; }
.inbox-thread-head { display: flex; align-items: center; border-block-end: 1px solid var(--line); }
.inbox-thread-head .spacer { flex: 1; }
.inbox-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-inline-size: 70%; padding-block: 8px; padding-inline: 10px; border-radius: 10px; font-size: 13.5px; overflow-wrap: anywhere; white-space: pre-wrap; }
.bubble.in { align-self: flex-start; background: var(--bg); color: var(--ink); }
.bubble.out { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.bubble.out.failed { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }
.bubble .send-error { font-size: 11.5px; margin-block-start: 4px; white-space: normal; }
.bubble.note { align-self: stretch; max-inline-size: none; background: var(--bg); }
.bubble .meta { font-size: 10.5px; opacity: .75; margin-block-start: 2px; white-space: normal; }
.inbox-composer { display: flex; gap: 8px; padding: 10px; border-block-start: 1px solid var(--line); }
.inbox-composer input { flex: 1; min-inline-size: 0; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.inbox-info { inline-size: 240px; border-inline-start: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 12px; flex-shrink: 0; overflow-y: auto; }
.inbox-info .caption { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.inbox-info .btn-box { border: 1px solid var(--line); }
.inbox-narrow-only { display: none; }

@media (max-width: 1100px) {
  .inbox-narrow-only { display: inline-block; }
  .inbox-list { inline-size: 100%; flex-shrink: 1; border-inline-end: 0; }
  .inbox.has-selection .inbox-list { display: none; }
  .inbox:not(.has-selection) .inbox-thread { display: none; }
  .inbox-info { display: none; }
  .inbox.show-info .inbox-messages, .inbox.show-info .inbox-composer, .inbox.show-info .inbox-thread > .error-text { display: none; }
  .inbox.show-info .inbox-info { display: flex; inline-size: 100%; border-inline-start: 0; flex: 1; }
  .inbox.show-info .inbox-thread { flex: 0 0 auto; }
  .bubble { max-inline-size: 85%; }
}

@media (max-width: 900px) {
  /* stretch, not flex-start: in a column, flex-start let the main area grow
     to its content's full width (the 6-column deal board = 1270px), which
     pushed the whole page sideways instead of scrolling the board. */
  .screen.with-drawer { flex-direction: column; align-items: stretch; }
  /* The detail panel opens OVER the list, not below it - below a 609-row
     customer table a tap looked like it did nothing. */
  .drawer {
    position: fixed; inset: 0; z-index: 40; inline-size: auto; max-block-size: none;
    border-radius: 0; box-shadow: 0 0 0 100vmax rgba(21, 32, 24, .35);
  }
}

/* ---- responsive down to 360px (BUILD-PLAN.md P1.S6) ---- */
@media (max-width: 640px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    inline-size: 100%;
    flex-direction: row;
    overflow-x: auto;
    padding-block: 8px;
  }
  .sidebar h1 { display: none; }
  .nav-link { white-space: nowrap; }
  .sidebar .nav-link[aria-current="page"] { border-inline-start: 0; border-block-end: 3px solid var(--accent); }
  .bell-panel { inline-size: calc(100vw - 32px); }
  .inbox { block-size: calc(100dvh - 170px); }
  .search { min-inline-size: 0; flex: 1 1 160px; }
  .content { padding: 12px; }
  .card { padding: 14px; }
}

/* ---- Task 7: calls, system lines, needs-a-person ---- */
.section-title { margin-block: 8px 0; font-size: 14px; font-weight: 700; color: var(--accent-deep); }
.nav-count {
  display: inline-block; min-inline-size: 18px; margin-inline-start: 6px; padding-inline: 5px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; text-align: center;
}
.inbox-item.needs-person { border-inline-start: 3px solid var(--danger); }
.sys-line { align-self: center; max-inline-size: 90%; text-align: center; font-size: 11.5px; color: var(--muted); padding-block: 2px; padding-inline: 10px; }
.call-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding-block: 8px; padding-inline: 12px; background: var(--accent-soft); border-block-end: 1px solid var(--line); font-size: 13px; }
.call-readonly { padding-inline: 12px; margin-block: 0 10px; }
.handoff-box { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; padding: 8px; border: 1px solid var(--danger-soft); background: var(--danger-soft); border-radius: 6px; }
.switch-row > label { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink); cursor: pointer; }
.switch-row input[type="checkbox"], .check-row input[type="checkbox"] { inline-size: auto; flex: none; padding: 0; }
