/* Cargo Load Planner — interface styles.
   Logical properties throughout so the Dari (RTL) layout mirrors itself. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --accent: #1d4ed8;
  --accent-ink: #1e3a8a;
  --accent-soft: #eef4ff;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --bad: #b91c1c;
  --bad-soft: #fef2f2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .18);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
        "Noto Sans", Tahoma, "Liberation Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

[dir="rtl"] body { font-family: Tahoma, "Segoe UI", "Noto Naskh Arabic", "Iranian Sans", Arial, sans-serif; }

h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.num, td.num, .mono { font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: .93em; }

/* ---------------------------------------------------------------- top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--ink);
  letter-spacing: -.02em;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand svg { color: var(--accent); }

.nav { display: flex; gap: 4px; }
.nav a {
  padding: 7px 13px;
  border-radius: 8px;
  color: var(--ink-2);
  font-weight: 500;
  font-size: .94rem;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

.topbar-right { margin-inline-start: auto; display: flex; align-items: center; gap: 14px; }

.lang { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lang a {
  padding: 5px 10px;
  font-size: .82rem;
  color: var(--muted);
  font-weight: 600;
  border-inline-end: 1px solid var(--line);
}
.lang a:last-child { border-inline-end: 0; }
.lang a:hover { background: var(--surface-2); text-decoration: none; }
.lang a.on { background: var(--accent); color: #fff; }

.who { color: var(--muted); font-size: .88rem; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
form.inline { display: inline; margin: 0; }

.page {
  flex: 1;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 22px 48px;
}
.page.narrow { max-width: 760px; }

.foot {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .82rem;
  background: var(--surface);
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }

.row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 8px; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--muted); }
.dim { color: var(--muted); }
.small { font-size: .84rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }
.mt-s { margin-top: 8px; }
.mb { margin-bottom: 16px; }
.hidden { display: none !important; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  font-size: .92rem;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .06s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(29, 78, 216, .3);
}
.btn.primary:hover { background: #1a45c0; border-color: #1a45c0; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); border-color: #fecaca; background: var(--bad-soft); }
.btn.danger:hover { background: #fee2e2; }
.btn.small { padding: 6px 11px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn.icon { padding: 6px 8px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: .85rem; font-weight: 550; color: var(--ink-2); margin-bottom: 5px; }
label.field > span .opt { color: var(--muted); font-weight: 400; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=search],
select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  font-size: .94rem;
  color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, .13);
}
textarea { resize: vertical; min-height: 110px; font-family: var(--mono); font-size: .85rem; }
select { cursor: pointer; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ---------------------------------------------------------------- alerts */

.alert {
  padding: 11px 14px;
  border-radius: 8px;
  font-size: .9rem;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert.error { background: var(--bad-soft); border-color: #fecaca; color: var(--bad); }
.alert.ok { background: var(--ok-soft); border-color: #a7f3d0; color: var(--ok); }
.alert.warn { background: var(--warn-soft); border-color: #fde68a; color: var(--warn); }
.alert.info { background: var(--accent-soft); border-color: #bfdbfe; color: var(--accent-ink); }

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

table.grid { width: 100%; border-collapse: collapse; font-size: .91rem; }
table.grid th {
  text-align: start;
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: var(--surface-2);
}
table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid tr:last-child td { border-bottom: 0; }
table.grid td.right, table.grid th.right { text-align: end; }
table.grid td.act { width: 42px; text-align: end; }

.scroll { overflow-x: auto; }

/* ---------------------------------------------------------------- auth */

.auth-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 20px 80px; }
.auth-card { width: 100%; max-width: 420px; padding: 30px 32px 26px; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); font-size: .93rem; margin-bottom: 22px; }
.auth-foot { text-align: center; margin-top: 16px; font-size: .9rem; color: var(--muted); }

/* ---------------------------------------------------------------- dashboard */

.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow);
}
.stat .k { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 1.65rem; font-weight: 680; letter-spacing: -.02em; margin-top: 3px; }
.stat .v small { font-size: .55em; font-weight: 550; color: var(--muted); margin-inline-start: 5px; }

.empty {
  text-align: center;
  padding: 56px 24px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
}
.empty h2 { margin-bottom: 6px; }
.empty p { color: var(--muted); max-width: 420px; margin: 0 auto 18px; }

/* ---------------------------------------------------------------- planner */

.plan-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.plan-title {
  font-size: 1.4rem;
  font-weight: 680;
  letter-spacing: -.02em;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 5px 9px;
  margin-inline-start: -9px;
  background: transparent;
  width: 100%;
  max-width: 520px;
  font-family: inherit;
}
.plan-title:hover { border-color: var(--line); }
.plan-title:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px rgba(29,78,216,.13); outline: none; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px 14px;
  flex: 1;
}
.meta-grid label { display: block; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.meta-grid input, .meta-grid select { padding: 7px 9px; font-size: .89rem; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 10px 15px;
  font: inherit;
  font-weight: 550;
  font-size: .93rem;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: -1px;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .badge { display: inline-block; background: var(--accent-soft); color: var(--accent-ink); border-radius: 20px; padding: 0 7px; font-size: .75rem; margin-inline-start: 5px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }

/* cargo grid */
.cargo-table { min-width: 900px; }
.cargo-table th { padding: 8px 6px; text-transform: none; letter-spacing: 0; font-size: .8rem; }
.cargo-table td { padding: 4px 5px; }
.cargo-table input[type=text], .cargo-table input[type=number] {
  padding: 6px 7px;
  font-size: .87rem;
  border-color: transparent;
  background: transparent;
  border-radius: 6px;
  min-width: 52px;
}
.cargo-table input:hover { border-color: var(--line-strong); background: var(--surface); }
.cargo-table input:focus { border-color: var(--accent); background: var(--surface); }
.cargo-table td.c-num input { text-align: end; font-variant-numeric: tabular-nums; }
.cargo-table input.swatch { width: 30px; height: 26px; padding: 0; border: 1px solid var(--line-strong); border-radius: 6px; cursor: pointer; }
.cargo-table tr.row-del td { color: var(--muted); }
.cargo-table .del {
  border: 0; background: none; cursor: pointer; color: var(--muted);
  font-size: 1.1rem; line-height: 1; padding: 4px 7px; border-radius: 6px;
}
.cargo-table .del:hover { color: var(--bad); background: var(--bad-soft); }
.cargo-table tbody tr:hover { background: var(--accent-soft); }

/* ---------------------------------------------------------------- results */

.res-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 12px; margin-bottom: 18px; }
.res-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  background: var(--surface);
}
.res-card .k { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.res-card .v { font-size: 1.5rem; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.res-card .v small { font-size: .55em; color: var(--muted); font-weight: 550; margin-inline-start: 5px; }
.res-card.accent { background: var(--accent-soft); border-color: #c7d7fe; }
.res-card.accent .v { color: var(--accent-ink); }

.bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }
.bar > i.ok { background: var(--ok); }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }

.viewer-wrap { display: grid; grid-template-columns: 1fr 280px; gap: 16px; }
.viewer {
  position: relative;
  background: linear-gradient(180deg, #fbfdff 0%, #eef2f7 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 440px;
}
.viewer canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.viewer canvas:active { cursor: grabbing; }
.viewer .hud {
  position: absolute;
  inset-block-start: 10px;
  inset-inline-start: 12px;
  font-size: .78rem;
  color: var(--muted);
  background: rgba(255,255,255,.85);
  padding: 4px 9px;
  border-radius: 6px;
  pointer-events: none;
  backdrop-filter: blur(4px);
}
.viewer .view-tools {
  position: absolute;
  inset-block-start: 10px;
  inset-inline-end: 10px;
  display: flex;
  gap: 5px;
  background: rgba(255,255,255,.9);
  padding: 4px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(15,23,42,.12);
}
.viewer .view-tools button {
  border: 0; background: none; font: inherit; font-size: .8rem; font-weight: 550;
  padding: 4px 8px; border-radius: 5px; cursor: pointer; color: var(--ink-2);
}
.viewer .view-tools button:hover { background: var(--surface-2); }
.viewer .view-tools button.on { background: var(--accent); color: #fff; }
.viewer .legend {
  position: absolute;
  inset-block-end: 10px;
  inset-inline-start: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  max-width: 70%;
  font-size: .75rem;
  background: rgba(255,255,255,.85);
  padding: 6px 9px;
  border-radius: 6px;
  backdrop-filter: blur(4px);
}
.viewer .legend span { display: inline-flex; align-items: center; gap: 4px; }
.viewer .legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

.side-panel { display: flex; flex-direction: column; gap: 12px; }
.cont-list { display: flex; flex-direction: column; gap: 6px; }
.cont-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; background: var(--surface); font-size: .88rem;
}
.cont-item:hover { border-color: var(--line-strong); }
.cont-item.on { border-color: var(--accent); background: var(--accent-soft); }
.cont-item .n { font-weight: 650; }
.cont-item .fill { margin-inline-start: auto; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .82rem; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; font-size: .88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 550; text-align: end; }

.gauge { position: relative; height: 90px; }
.gauge .track {
  position: absolute; inset-inline: 0; top: 44px; height: 10px; border-radius: 5px;
  background: linear-gradient(90deg, var(--bad) 0%, var(--warn) 26%, var(--ok) 40%, var(--ok) 60%, var(--warn) 74%, var(--bad) 100%);
  opacity: .28;
}
.gauge .safe {
  position: absolute; top: 40px; height: 18px; border-inline: 2px solid var(--ok);
  background: rgba(4,120,87,.09); border-radius: 3px;
}
.gauge .needle {
  position: absolute; top: 36px; width: 3px; height: 26px; background: var(--ink);
  border-radius: 2px; transform: translateX(-50%);
}
.gauge .needle::after {
  content: ""; position: absolute; inset-block-start: -5px; inset-inline-start: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--ink);
}
.gauge .label-l, .gauge .label-r {
  position: absolute; top: 66px; font-size: .74rem; color: var(--muted);
}
.gauge .label-l { inset-inline-start: 0; }
.gauge .label-r { inset-inline-end: 0; }

/* sequence */
.seq-wrap { max-height: 620px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.seq-wrap table.grid th { position: sticky; top: 0; z-index: 1; }
.step-chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: .75rem; font-weight: 700;
}
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-inline-end: 6px; vertical-align: middle; }

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

.modal-back {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: 12px; width: 100%; max-width: 640px;
  box-shadow: 0 20px 60px rgba(15,23,42,.3); max-height: 90vh; display: flex; flex-direction: column;
}
.modal header { padding: 18px 20px 10px; }
.modal .body { padding: 0 20px 10px; overflow: auto; }
.modal footer { padding: 14px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; }

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

.toast {
  position: fixed;
  inset-block-end: 22px;
  inset-inline-end: 22px;
  background: var(--ink);
  color: #fff;
  padding: 11px 16px;
  border-radius: 9px;
  font-size: .9rem;
  box-shadow: 0 10px 30px rgba(15,23,42,.3);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s, transform .18s;
  z-index: 200;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--bad); }

/* ---------------------------------------------------------------- report */

.report { max-width: 980px; margin: 0 auto; }
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; border-bottom: 2px solid var(--ink); padding-bottom: 14px; margin-bottom: 20px; }
.report-head .meta { text-align: end; font-size: .85rem; color: var(--muted); line-height: 1.7; }
.report h2 { margin: 26px 0 10px; font-size: 1.02rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.report table.grid { font-size: .85rem; }
.report .sign-row { display: flex; gap: 60px; margin-top: 46px; }
.report .sign-row div { flex: 1; border-top: 1px solid var(--line-strong); padding-top: 7px; font-size: .82rem; color: var(--muted); }

@media print {
  .topbar, .foot, .no-print, .tabs { display: none !important; }
  body { background: #fff; }
  .page { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; }
  .report h2 { break-after: avoid; }
  table.grid tr { break-inside: avoid; }
  @page { margin: 14mm; }
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1100px) {
  .viewer-wrap { grid-template-columns: 1fr; }
  .viewer { min-height: 380px; }
}
@media (max-width: 860px) {
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { gap: 10px; padding: 0 14px; flex-wrap: wrap; height: auto; padding-block: 9px; }
  .who { display: none; }
  .page { padding: 16px 14px 40px; }
  .nav a { padding: 6px 9px; font-size: .87rem; }
  .brand span { display: none; }
}
@media (max-width: 560px) {
  .stat-row { grid-template-columns: 1fr 1fr; }
  .plan-head { gap: 10px; }
  .meta-grid { grid-template-columns: 1fr 1fr; }
}
