/* PSCgo — warm, low-glare palette drawn from the PSC logo (deep olive + gold). */
:root {
  --bg: #f8f4ec;
  --surface: #fffdf7;
  --surface-2: #f1ecdd;
  --border: #eadcc6;
  --text: #2b2a22;
  --muted: #6f6a55;
  --primary: #4b2e14;
  --primary-text: #fffdf7;
  --accent: #d9730d;
  --accent-soft: #fbe5cb;
  --ok: #3f7a4f;
  --ok-soft: #e1eedc;
  --warn: #9a6b0c;
  --warn-soft: #f6e7c4;
  --danger: #a94536;
  --danger-soft: #f5dcd6;
  --info: #3d6680;
  --info-soft: #dde9f0;
  --shadow: 0 1px 2px rgba(60, 52, 20, 0.06), 0 4px 16px rgba(60, 52, 20, 0.05);
  --radius: 14px;
  --font: 'Segoe UI', system-ui, -apple-system, 'Noto Sans Arabic', Tahoma, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #16150f; --surface: #1f1d15; --surface-2: #28261c; --border: #37342a; --text: #ebe7d6; --muted: #a7a188;
    --primary: #f0a347; --primary-text: #1f1a13; --accent: #f0a347; --accent-soft: #3d2a16;
    --ok: #8cc49a; --ok-soft: #22321f; --warn: #e0b35a; --warn-soft: #3a2f16; --danger: #e59483; --danger-soft: #3d221c;
    --info: #8fb8d1; --info-soft: #1d2c35; --shadow: 0 1px 2px rgba(0, 0, 0, 0.3); color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #16150f; --surface: #1f1d15; --surface-2: #28261c; --border: #37342a; --text: #ebe7d6; --muted: #a7a188;
  --primary: #f0a347; --primary-text: #1f1a13; --accent: #f0a347; --accent-soft: #3d2a16;
  --ok: #8cc49a; --ok-soft: #22321f; --warn: #e0b35a; --warn-soft: #3a2f16; --danger: #e59483; --danger-soft: #3d221c;
  --info: #8fb8d1; --info-soft: #1d2c35; --shadow: 0 1px 2px rgba(0, 0, 0, 0.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
p { margin: 0.4em 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 12px; }
/* Grid children default to their content's width; without this a wide tab strip pushes the page sideways. */
.stack > *, .grid > * { min-width: 0; }
body { overflow-x: clip; } /* clip, not hidden: hidden would break the sticky top bar */
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* ---- shell ---- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand svg { height: 30px; width: auto; color: var(--primary); }
.brand-name { font-size: 1.2rem; font-weight: 700; letter-spacing: 0.2px; color: var(--text); }
.brand-name b { color: var(--accent); font-weight: 700; }
.topnav { display: none; gap: 4px; margin-inline-start: 16px; }
.topnav a { padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 500; }
.topnav a.active { background: var(--accent-soft); color: var(--text); }
.topbar .spacer { flex: 1; }
main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 16px 16px 96px; }
footer { text-align: center; font-size: 11px; color: var(--muted); padding: 16px 16px 88px; }
.bottomnav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 6px; font-size: 11px; text-decoration: none; color: var(--muted); }
.bottomnav a.active { color: var(--text); font-weight: 600; }
.bottomnav a.active .ico { color: var(--accent); }
.bottomnav .plus .ico { background: var(--primary); color: var(--primary-text); border-radius: 50%; width: 30px; height: 30px; display: grid; place-items: center; margin-top: -4px; }
.bottomnav span:not(.ico) { line-height: 1.2; }
[dir='rtl'] .flip-rtl svg { transform: scaleX(-1); }
.ico { width: 22px; height: 22px; display: inline-grid; place-items: center; }
.ico svg { width: 20px; height: 20px; }
@media (min-width: 900px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
  main { padding-bottom: 32px; }
  footer { padding-bottom: 24px; }
}

/* ---- surfaces ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.grid { display: grid; gap: 12px; }
.grid.four { grid-template-columns: 1fr 1fr; }
@media (min-width: 700px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.four { grid-template-columns: repeat(4, 1fr); } }
a.card { text-decoration: none; }
.stat { padding: 14px; }
.stat .label { font-size: 0.8rem; color: var(--muted); }
.stat .value { font-size: 1.45rem; font-weight: 700; margin-top: 2px; }
.stat.alert .value { color: var(--danger); }
.stat a { text-decoration: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

.list { display: grid; gap: 0; }
.list > .item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.list > .item:last-child { border-bottom: 0; }
.item-link { text-decoration: none; display: block; }

.opp-card { display: block; text-decoration: none; transition: transform 0.08s ease; }
.opp-card:active { transform: scale(0.995); }
.opp-card .code { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.3px; }
.opp-card h3 { font-size: 1rem; margin: 2px 0 6px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.85rem; color: var(--muted); }

/* ---- badges ---- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.LEAD { background: var(--info-soft); color: var(--info); }
.badge.QUALIFYING { background: var(--accent-soft); color: var(--warn); }
.badge.PROPOSAL { background: var(--warn-soft); color: var(--warn); }
.badge.NEGOTIATION { background: #eadff2; color: #6b4a85; }
:root[data-theme='dark'] .badge.NEGOTIATION { background: #2e2436; color: #c8a9dd; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .badge.NEGOTIATION { background: #2e2436; color: #c8a9dd; } }
.badge.WON, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.LOST, .badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* ---- stage stepper ---- */
.stepper { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.stepper button { flex: 1 0 auto; border: 1px solid var(--border); background: var(--surface); color: var(--muted); padding: 7px 10px; border-radius: 10px; font: inherit; font-size: 0.8rem; cursor: pointer; }
.stepper button.past { background: var(--surface-2); color: var(--text); }
.stepper button.current { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.stepper button.won { background: var(--ok); border-color: var(--ok); color: #fff; }
.stepper button.lost { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ---- tabs & chips ---- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin: 16px 0 12px; scrollbar-width: none; }
.tabs button { border: 0; background: none; font: inherit; padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .count { font-size: 0.75rem; background: var(--surface-2); border-radius: 999px; padding: 0 6px; margin-inline-start: 4px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 0.85rem; cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

/* ---- forms ---- */
label.field { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }
label.field > span.req::after { content: ' *'; color: var(--danger); }
input, select, textarea {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming into the field */
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; border-color: var(--accent); }
input[type='checkbox'] { width: 20px; height: 20px; accent-color: var(--primary); flex: none; }
.help { font-size: 0.8rem; color: var(--muted); }
.error-box { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: 0.9rem; }
.ok-box { background: var(--ok-soft); color: var(--ok); padding: 10px 12px; border-radius: 10px; font-size: 0.9rem; }

button.btn, a.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: 0.9rem;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--primary); background: var(--primary); color: var(--primary-text);
  cursor: pointer; text-decoration: none; min-height: 40px;
}
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 6px 10px; min-height: 34px; }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--danger-soft); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 0.8rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---- sheet (dialog) ---- */
.overlay { position: fixed; inset: 0; background: rgba(20, 18, 8, 0.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; position: sticky; top: -18px; background: var(--surface); padding: 6px 0; z-index: 1; }
.sheet-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }

/* ---- tasks ---- */
.task { display: flex; gap: 10px; align-items: flex-start; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-title { font-weight: 500; }

/* ---- timeline ---- */
.tl { display: grid; gap: 0; }
.tl-item { display: grid; grid-template-columns: 12px 1fr; gap: 10px; padding: 8px 0; }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); margin-top: 7px; }
.tl-item.note .tl-dot { background: var(--info); }

/* ---- misc ---- */
.empty { text-align: center; padding: 24px 12px; color: var(--muted); }
.toast { position: fixed; z-index: 60; bottom: 84px; inset-inline: 16px; margin: 0 auto; max-width: 420px; padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); text-align: center; }
@media (min-width: 900px) { .toast { bottom: 24px; } }
.toast.error { background: var(--danger); color: #fff; }
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 20px; }
.auth-logo svg { height: 150px; width: auto; color: var(--text); }
.auth-logo .brand-name { font-size: 1.7rem; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
audio { width: 100%; height: 40px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width 0.2s; }
.stagebar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--surface-2); margin: 8px 0 10px; }
.stagebar > div { height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.8rem; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-inline-end: 5px; }
.qr { background: #fff; padding: 10px; border-radius: 12px; width: 240px; max-width: 100%; }
.late { color: var(--danger); font-weight: 600; }
.soon { color: var(--warn); font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: 0; }

.desktop-only { display: none !important; }
@media (min-width: 900px) { .desktop-only { display: inline-flex !important; } }
