/* ==========================================================================
   رصيفي الذكي | SMART BERTH — نظام التصميم الأساسي
   Design tokens, base layer, layout shell. Light + dark (operations room).
   ========================================================================== */

/* ------------------------------ 1. Tokens ------------------------------- */
:root {
  color-scheme: light;

  /* Identity — sand, stone, olive, brass */
  --sand-50: #faf8f3;
  --sand-100: #f4f1e9;
  --sand-200: #e9e4d7;
  --sand-300: #dad3c1;
  --stone-400: #b3ab99;
  --stone-500: #8b8474;
  --olive-500: #5f6b52;
  --olive-600: #4c5742;
  --olive-700: #3b4434;
  --brass-400: #c2a35c;
  --brass-500: #9d7f3f;
  --brass-600: #7d6531;
  --ink-900: #22251f;
  --ink-700: #3c3f36;
  --ink-500: #676b5f;

  /* Semantic surfaces */
  --bg: #eeece5;
  --bg-deep: #e4e1d7;
  --surface: #fbfaf6;
  --surface-2: #f4f2ea;
  --surface-3: #ece9de;
  --line: #d9d5c7;
  --line-strong: #c3bda9;

  /* Semantic text */
  --text: var(--ink-900);
  --text-soft: #5d6156;
  --text-mute: #82867a;
  --text-invert: #fbfaf6;

  /* Accents */
  --accent: var(--olive-600);
  --accent-soft: #dfe3d6;
  --accent-ink: #ffffff;
  --brass: var(--brass-500);
  --brass-soft: #f0e6cd;

  /* Status */
  --ok: #4f7350;
  --ok-soft: #dcead9;
  --warn: #9a7327;
  --warn-soft: #f6ecd5;
  --danger: #98453f;
  --danger-soft: #f6dedb;
  --info: #3f6273;
  --info-soft: #dbe7ed;
  --idle: #7d8174;
  --idle-soft: #e6e5dc;

  /* Elevation */
  --shadow-1: 0 1px 2px rgba(34, 37, 31, .05), 0 2px 8px rgba(34, 37, 31, .04);
  --shadow-2: 0 2px 6px rgba(34, 37, 31, .06), 0 12px 32px rgba(34, 37, 31, .07);
  --shadow-3: 0 18px 60px rgba(34, 37, 31, .18);
  --ring: 0 0 0 3px rgba(95, 107, 82, .28);

  /* Geometry */
  --r-xs: 6px;
  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 18px;
  --r-xl: 26px;
  --r-full: 999px;

  /* Rhythm */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 22px;
  --sp-6: 30px;
  --sp-7: 42px;
  --sp-8: 60px;

  --nav-w: 268px;
  --top-h: 66px;
  --page-max: 1360px;

  --font-ar: "IBM Plex Sans Arabic", "Noto Sans Arabic", "Dubai", "Segoe UI", Tahoma, system-ui, sans-serif;
  --font-en: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --font: var(--font-ar);

  --speed: 180ms;
  --ease: cubic-bezier(.22, .61, .36, 1);
}

/* Dark — "غرفة العمليات" / operations room */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #12151a;
  --bg-deep: #0d1014;
  --surface: #1a1e24;
  --surface-2: #20252c;
  --surface-3: #272d35;
  --line: #303741;
  --line-strong: #414a56;

  --text: #e9eae4;
  --text-soft: #b9bdb3;
  --text-mute: #878d84;
  --text-invert: #12151a;

  --accent: #93a884;
  --accent-soft: #29332a;
  --accent-ink: #11160f;
  --brass: #cdad64;
  --brass-soft: #332d1c;

  --ok: #7fa878;
  --ok-soft: #22301f;
  --warn: #cfa75a;
  --warn-soft: #332a17;
  --danger: #d98079;
  --danger-soft: #37211f;
  --info: #7fa7bd;
  --info-soft: #1d2a33;
  --idle: #8b9188;
  --idle-soft: #262b2f;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 2px 8px rgba(0, 0, 0, .45), 0 18px 40px rgba(0, 0, 0, .35);
  --shadow-3: 0 24px 70px rgba(0, 0, 0, .6);
  --ring: 0 0 0 3px rgba(147, 168, 132, .35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12151a;
    --bg-deep: #0d1014;
    --surface: #1a1e24;
    --surface-2: #20252c;
    --surface-3: #272d35;
    --line: #303741;
    --line-strong: #414a56;
    --text: #e9eae4;
    --text-soft: #b9bdb3;
    --text-mute: #878d84;
    --text-invert: #12151a;
    --accent: #93a884;
    --accent-soft: #29332a;
    --accent-ink: #11160f;
    --brass: #cdad64;
    --brass-soft: #332d1c;
    --ok: #7fa878;
    --ok-soft: #22301f;
    --warn: #cfa75a;
    --warn-soft: #332a17;
    --danger: #d98079;
    --danger-soft: #37211f;
    --info: #7fa7bd;
    --info-soft: #1d2a33;
    --idle: #8b9188;
    --idle-soft: #262b2f;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 2px 8px rgba(0, 0, 0, .45), 0 18px 40px rgba(0, 0, 0, .35);
    --shadow-3: 0 24px 70px rgba(0, 0, 0, .6);
    --ring: 0 0 0 3px rgba(147, 168, 132, .35);
  }
}

/* -------------------------------- 2. Base ------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

html[lang="en"] { --font: var(--font-en); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 {
  margin: 0;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -.01em;
  color: var(--text);
}

h1 { font-size: clamp(22px, 2.4vw, 30px); }
h2 { font-size: clamp(18px, 1.8vw, 22px); }
h3 { font-size: 16px; }

p { margin: 0; }

a {
  color: inherit;
  text-decoration: none;
  transition: color var(--speed) var(--ease);
}

a:hover { color: var(--accent); }

img { max-width: 100%; display: block; }

code, kbd, samp, .mono {
  font-family: var(--font-mono);
  font-size: .86em;
  letter-spacing: .02em;
  direction: ltr;
  unicode-bidi: embed;
}

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

button { cursor: pointer; }

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--r-sm);
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ------------------------------ 3. Utility ------------------------------ */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  inset-inline-start: 50%;
  top: -60px;
  transform: translateX(50%);
  z-index: 200;
  padding: 10px 20px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 0 0 var(--r-md) var(--r-md);
  font-weight: 700;
  transition: top var(--speed) var(--ease);
}

.skip-link:focus { top: 0; color: var(--accent-ink); }

.stack { display: grid; gap: var(--sp-4); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.nowrap { white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }
.hide { display: none !important; }

.eyebrow {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--brass);
}

.muted { color: var(--text-mute); }
.soft { color: var(--text-soft); }

/* ------------------------------ 4. Shell -------------------------------- */
.shell {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* -- Side navigation -- */
.sidenav {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border-inline-end: 1px solid var(--line);
  z-index: 40;
}

.sidenav::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--brass), transparent 45%, var(--accent));
  opacity: .5;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  height: var(--top-h);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand:hover { color: inherit; }

.brand-mark {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  background: linear-gradient(145deg, var(--accent), var(--olive-700));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}

.brand-mark svg { width: 22px; height: 22px; }

.brand-text { display: grid; min-width: 0; }
.brand-text strong {
  font-size: 13.5px;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-text small {
  font-size: 10.5px;
  color: var(--text-mute);
  letter-spacing: .04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
}

.nav-group + .nav-group { margin-top: var(--sp-4); }

.nav-group > h4 {
  margin: 0 var(--sp-2) var(--sp-2);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-mute);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 9px var(--sp-3);
  margin-bottom: 2px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-soft);
  border: 1px solid transparent;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}

.nav-link svg { width: 17px; height: 17px; flex: 0 0 auto; opacity: .85; }

.nav-link:hover {
  background: var(--surface-3);
  color: var(--text);
}

.nav-link[aria-current="page"] {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--text);
}

.nav-link[aria-current="page"] svg { color: var(--accent); opacity: 1; }

.nav-foot {
  flex: 0 0 auto;
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  border-top: 1px solid var(--line);
}

.link-status {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--r-md);
  background: var(--surface-3);
  font-size: 11.5px;
  color: var(--text-soft);
}

.pulse-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent);
  animation: pulse 2.6s infinite;
  flex: 0 0 auto;
}

.pulse-dot.offline { background: var(--warn); animation: none; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* -- Top bar -- */
.main-col { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 35;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  height: var(--top-h);
  padding: 0 var(--sp-5);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-title { display: grid; min-width: 0; overflow: hidden; }
.topbar-title small { font-size: 10.5px; color: var(--text-mute); letter-spacing: .05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-tools { margin-inline-start: auto; display: flex; align-items: center; gap: var(--sp-2); }

.icon-btn {
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-soft);
  transition: all var(--speed) var(--ease);
}

.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); border-color: var(--line-strong); }

.lang-btn {
  height: 38px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--speed) var(--ease);
}

.lang-btn:hover { background: var(--surface-3); color: var(--text); }

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px 6px 4px 4px;
  border-radius: var(--r-full);
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.user-chip .avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
}

.user-chip .who { display: grid; line-height: 1.25; max-width: 190px; }
.user-chip .who strong { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who small { font-size: 10px; color: var(--text-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 1080px) { .user-chip .who { display: none; } }

/* Mobile nav trigger */
.nav-toggle { display: none; }

@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidenav {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(300px, 86vw);
    transform: translateX(var(--nav-off, 110%));
    transition: transform 260ms var(--ease);
    box-shadow: var(--shadow-3);
  }
  html[dir="rtl"] .sidenav { --nav-off: 110%; }
  html[dir="ltr"] .sidenav { --nav-off: -110%; }
  .sidenav.open { transform: translateX(0); }
  .nav-toggle { display: grid; }
  .nav-scrim {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 9, .45);
    backdrop-filter: blur(2px);
    z-index: 39;
  }
}

/* -- Page container -- */
.page {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-8);
  animation: rise 320ms var(--ease) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 640px) {
  .page { padding: var(--sp-5) var(--sp-4) var(--sp-7); }
  .topbar { padding: 0 var(--sp-4); gap: var(--sp-2); }
  .topbar-title small { display: none; }
  .topbar-title strong { font-size: 13.5px; }
  .topbar-tools { gap: 4px; }
  .lang-btn, .icon-btn { height: 34px; }
  .icon-btn { width: 34px; }
  .user-chip { padding: 3px; }
}

.page-foot {
  margin-top: var(--sp-7);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-mute);
}
