/*
 * Persian Open Quake — styles
 *
 * RTL layout (dir="rtl" on <html>); Leaflet maps are forced back to LTR.
 * Colours are CSS custom properties with a dark-mode override.
 * Sections: font · tokens · base · top bar · layout · form · map ·
 *           tables/log · results · toast
 */

/* ---------- font (bundled, no CDN) ---------- */
@font-face {
  font-family: "Vazirmatn";
  src: url("vendor/fonts/Vazirmatn.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

/* ---------- design tokens ---------- */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1c2230;
  --muted: #5d6677;
  --line: #e1e4ea;
  --accent: #b4441c;
  --accent-ink: #ffffff;
  --region: #2563eb;
  --source: #e8710a;
  --ok: #1f7a46;
  --warn: #a15c00;
  --bad: #b42318;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --panel: #1b2029;
    --ink: #e7eaf0;
    --muted: #9aa3b2;
    --line: #2d3442;
    --accent: #f08a5d;
    --accent-ink: #1b1209;
    --shadow: none;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Vazirmatn", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.7;
}
button, input, select { font: inherit; color: inherit; }
code { font-family: Consolas, monospace; font-size: .9em; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 30px; color: var(--accent); line-height: 1; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 700; }
.brand .sub { margin: 0; font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 8px;
  cursor: pointer; color: var(--muted); font-weight: 500;
}
.tab:hover:not(:disabled) { background: var(--bg); color: var(--ink); }
.tab.active { background: var(--accent); color: var(--accent-ink); }
.tab:disabled { opacity: .4; cursor: default; }
.engine-pill {
  margin-inline-start: auto; font-size: 12px; padding: 4px 10px; border-radius: 99px;
  border: 1px solid var(--line); color: var(--muted);
}
.engine-pill.ok::before { content: "● "; color: var(--ok); }
.engine-pill.bad::before { content: "● "; color: var(--bad); }

/* ---------- layout ---------- */
main { padding: 16px 20px 40px; max-width: 1500px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.panel h2 { font-size: 16px; margin: 0 0 8px; }
.split { display: grid; grid-template-columns: minmax(340px, 480px) 1fr; gap: 16px; align-items: start; }
.split.results { grid-template-columns: 1fr minmax(340px, 520px); }
@media (max-width: 960px) { .split, .split.results { grid-template-columns: 1fr; } }

/* ---------- form ---------- */
.form { max-height: calc(100vh - 110px); overflow-y: auto; }
fieldset {
  border: 1px solid var(--line); border-radius: 8px; margin: 0 0 12px; padding: 10px 12px 12px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px;
}
legend { font-weight: 700; padding: 0 6px; font-size: 14px; }
fieldset > .hint, fieldset > .checks, fieldset > .btnrow, .full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 2px; }
input[type=number], input:not([type]), select {
  border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 6px 8px; color: var(--ink);
  width: 100%;
}
input[type=number] { direction: ltr; text-align: right; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.c-region { color: var(--region); }
.c-source { color: var(--source); }
.checks { display: flex; flex-direction: column; gap: 2px; }
.chk { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 13.5px; cursor: pointer; }
.mode-switch { display: flex; gap: 16px; margin-bottom: 12px; }
.mode-switch label { flex-direction: row; gap: 6px; color: var(--ink); cursor: pointer; }
.actions, .btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
.actions { position: sticky; bottom: -16px; background: var(--panel); padding: 10px 0 2px; }

button.primary, button.ghost {
  border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 500; font-size: 14px;
}
button.primary { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); }
button.primary:disabled { opacity: .6; cursor: progress; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.ghost:hover { border-color: var(--muted); }
button.ghost.active { border-color: var(--accent); color: var(--accent); }
button.danger { color: var(--bad); border-color: var(--bad); }
.error {
  background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad);
  border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; font-size: 13.5px;
}

/* ---------- map ---------- */
.mapwrap { position: relative; padding: 0; overflow: hidden; }
.map { height: calc(100vh - 110px); min-height: 420px; border-radius: var(--radius); }
.split.results .map { height: 560px; }
.draw-hint {
  position: absolute; top: 10px; inset-inline-start: 50%; transform: translateX(50%);
  background: var(--ink); color: var(--panel); padding: 6px 12px; border-radius: 99px;
  font-size: 13px; z-index: 500; margin: 0;
}
/* Leaflet's tile/pane positioning assumes LTR; keep the map LTR, popups RTL */
.map, .leaflet-container { direction: ltr; font-family: inherit; }
.leaflet-tooltip, .leaflet-popup-content { direction: rtl; text-align: right; }
.legend {
  position: absolute; bottom: 12px; right: 12px; z-index: 500; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 170px;
}
.legend .bar { height: 10px; border-radius: 3px; margin: 4px 0; direction: ltr; }
.legend .ticks { display: flex; justify-content: space-between; direction: ltr; color: var(--muted); }

/* ---------- tables, log ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 500; font-size: 13px; }
.table tr.sel { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.table td.actions-cell { white-space: nowrap; text-align: left; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid currentColor; }
.badge.complete { color: var(--ok); }
.badge.executing, .badge.submitted, .badge.created { color: var(--warn); }
.badge.failed, .badge.aborted, .badge.deleted { color: var(--bad); }
.log {
  background: var(--bg); border-radius: 6px; padding: 10px; max-height: 360px; overflow: auto;
  font-size: 12px; line-height: 1.5; margin: 0; white-space: pre-wrap;
}

/* ---------- results ---------- */
.controls { display: flex; gap: 12px; flex-wrap: wrap; }
.controls label { flex-direction: row; align-items: center; gap: 6px; }
.controls select { width: auto; }
.charts { display: flex; flex-direction: column; gap: 12px; }
.chartbox { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.chartbox h3 { font-size: 13.5px; margin: 0 0 4px; font-weight: 500; }
.outputs { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.outputs li { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.outputs a { color: var(--accent); text-decoration: none; font-size: 13px; }

/* ---------- auth: login card, user box, quota ---------- */
[hidden] { display: none !important; }
body.signed-out .auth-only { display: none !important; }
.top-end { margin-inline-start: auto; display: flex; align-items: center; gap: 12px; }
.top-end .engine-pill { margin-inline-start: 0; }
.user-box { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.admin-badge { font-size: 11.5px; padding: 1px 8px; border-radius: 99px; border: 1px solid var(--accent); color: var(--accent); }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; }
.login-wrap { min-height: calc(100vh - 70px); display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 10px; margin: 0; }
.login-card h2 { margin: 0; font-size: 17px; }
.login-card .primary { margin-top: 4px; padding: 9px; }
.login-card a { color: var(--accent); }
.quota { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.quota .card { background: var(--bg); border-radius: 8px; padding: 8px 12px; }
.quota .k { font-size: 12px; color: var(--muted); }
.quota .v { font-size: 18px; font-weight: 600; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 2000;
  background: var(--ink); color: var(--panel); padding: 10px 18px; border-radius: 8px; font-size: 14px;
}
