/* ===== OD-LAYOUT-PRIMITIVES v1 — structure only ===== */
@layer od-layout {
  [hidden]:not([hidden="until-found" i]) { display: none !important; }
  dialog:not([open]) { display: none !important; }

  :where(.od-stack,.od-row,.od-row-top,.od-cluster,.od-grid,.od-field,.od-stat,.od-cell,.od-tile) > :where(*) { min-width: 0; }

  .od-stack   { display: flex; flex-direction: column; gap: var(--od-gap, 8px); }
  .od-row     { display: flex; align-items: center; gap: var(--od-gap, 8px); }
  .od-row-top { display: flex; align-items: flex-start; gap: var(--od-gap, 8px); }
  .od-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--od-gap, 8px); }
  .od-fill    { flex: 1 1 0; min-width: 0; }
  .od-fixed   { flex: none; }
  .od-grid    { display: grid; gap: var(--od-gap, 12px); grid-template-columns: repeat(var(--od-cols, 3), minmax(0, 1fr)); }

  .od-stat, .od-field, .od-cell { display: grid; gap: var(--od-gap, 2px); }
  :where(.od-stat,.od-field,.od-cell) > :where(*) { display: block; }
  .od-tile { display: grid; grid-template-rows: auto 1fr; }
  :where(.od-tile) > :where(*) { display: block; }

  .od-media { display: block; width: 100%; height: auto; aspect-ratio: var(--od-ratio, auto); }
  .od-media-cover { object-fit: cover; }

  .od-icon { display: inline-block; inline-size: var(--od-icon-size, 1em); block-size: var(--od-icon-size, 1em); flex: none; }

  .od-truncate { display: block; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .od-clamp-2, .od-clamp-3 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
  .od-clamp-2 { -webkit-line-clamp: 2; }
  .od-clamp-3 { -webkit-line-clamp: 3; }
  .od-lines-2 { min-height: calc(2 * 1.4em); }
  .od-nowrap  { white-space: nowrap; }
  .od-keep    { word-break: keep-all; overflow-wrap: anywhere; }

  .od-screen { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }
  .od-scroll { overflow-y: auto; overscroll-behavior: contain; min-height: 0; }

  .od-rail { display: flex; gap: var(--od-gap, 8px); overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none;
             padding-inline: var(--od-rail-pad, 16px); scroll-padding-inline: var(--od-rail-pad, 16px); }
  .od-rail::-webkit-scrollbar { display: none; }
  :where(.od-rail) > :where(*) { flex: none; scroll-snap-align: start; }
  :where(.od-rail) > :where(:last-child) { margin-inline-end: var(--od-rail-pad, 16px); }

  .od-spacer { flex: none; visibility: hidden; pointer-events: none; }
  .od-touch  { min-width: 44px; min-height: 44px; }
}
:root [hidden]:where(:not([hidden="until-found" i])) { display: none; }
/* ===== /OD-LAYOUT-PRIMITIVES v1 ===== */

/* ===== Design tokens ===== */
:root {
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --surface-sunken: #F8F9FB;
  --border: #E2E6ED;
  --border-strong: #CBD2DE;
  --text: #121826;
  --text-muted: #5B6472;
  --text-faint: #8A93A3;

  --primary: #15264D;
  --primary-strong: #0D1733;
  --primary-contrast: #FFFFFF;

  --accent: #1A7F68;
  --accent-soft: #E3F3EE;
  --accent-strong: #0F5C4A;

  --warning: #B4740E;
  --warning-soft: #FBF0DD;
  --danger: #B3362C;
  --danger-soft: #FAE6E3;

  --sidebar-bg: #0E1A33;
  --sidebar-text: #C7CEDD;
  --sidebar-text-active: #FFFFFF;
  --sidebar-hover: #16284A;
  --sidebar-active: #1C3254;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --font-display: "Manrope", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, sans-serif;

  --topbar-h: 64px;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; margin: 0; color: var(--text); letter-spacing: -0.01em; }
p { margin: 0; }
a { color: inherit; }
button { font-family: inherit; }
img { max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ===== App shell ===== */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}

/* ----- Sidebar ----- */
.sidebar {
  grid-area: sidebar;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: var(--space-4) var(--space-3) var(--space-5);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-5);
}
.sidebar-brand .mark {
  width: 32px; height: 32px; flex: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-family: var(--font-display); font-weight: 800; font-size: 12px;
}
.sidebar-brand .name { font-family: var(--font-display); font-weight: 700; color: #fff; font-size: 15px; }
.sidebar-brand .sub { font-size: 12px; color: var(--sidebar-text); display: block; margin-top: 1px; }

.property-switcher {
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%; margin-bottom: var(--space-4);
  padding: 9px 10px; border-radius: var(--radius-md);
  background: var(--sidebar-hover); border: 1px solid rgba(255,255,255,0.08);
  cursor: pointer; text-align: left;
}
.property-switcher:hover { background: var(--sidebar-active); }
.property-switcher .ps-icon {
  width: 26px; height: 26px; flex: none; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.08); color: var(--sidebar-text-active);
  display: flex; align-items: center; justify-content: center;
}
.property-switcher .ps-icon .od-icon { width: 15px; height: 15px; }
.property-switcher .ps-label { font-size: 10.5px; color: var(--sidebar-text); text-transform: uppercase; letter-spacing: 0.04em; }
.property-switcher .ps-name { font-size: 13px; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.property-switcher .ps-chevron { margin-left: auto; flex: none; color: var(--sidebar-text); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  background: transparent;
  border: none;
  text-align: left;
  width: 100%;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 150ms ease, color 150ms ease;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-text-active); }
.nav-item .od-icon { color: inherit; opacity: 0.85; }
.nav-item.active .od-icon { opacity: 1; }

.sidebar-footer {
  margin-top: var(--space-5);
  padding: var(--space-3);
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: var(--accent-soft); color: var(--accent-strong);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; font-family: var(--font-display);
}
.sidebar-footer .who { font-size: 13px; color: #fff; font-weight: 600; }
.sidebar-footer .role { font-size: 12px; color: var(--sidebar-text); }

/* ----- Topbar ----- */
.topbar {
  grid-area: topbar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-crumb { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.topbar-menu-btn { display: none; }
.topbar-title { font-family: var(--font-display); font-weight: 700; font-size: 17px; }
.topbar-sub { color: var(--text-faint); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); flex: none; }
.icon-btn {
  width: 38px; height: 38px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  cursor: pointer; position: relative;
}
.icon-btn:hover { background: var(--surface-sunken); color: var(--text); }
.icon-btn .dot {
  position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--surface);
}

/* ----- Main / content ----- */
.main { grid-area: main; min-width: 0; overflow-y: auto; }
.view { padding: var(--space-6) var(--space-6) var(--space-8); max-width: 1180px; }
.view-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}
.view-header h1 { font-size: 24px; }
.view-header .desc { color: var(--text-muted); font-size: 14px; margin-top: 4px; max-width: 60ch; }
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-muted); font-size: 13px; font-weight: 600;
  background: none; border: none; cursor: pointer; padding: 6px 2px; margin-bottom: var(--space-3);
}
.back-link:hover { color: var(--text); }

/* ----- Buttons ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-md);
  font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid transparent;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
  min-height: 40px;
}
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-strong); }
.btn-primary:disabled { background: var(--border-strong); color: var(--text-faint); cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-sunken); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-sunken); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #972c24; }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 32px; }

/* ----- Cards / stats ----- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.stat-grid { --od-cols: 4; --od-gap: 14px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-4);
  cursor: pointer;
  text-align: left;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
  --od-gap: 6px;
}
.stat-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.stat-icon {
  width: 34px; height: 34px; border-radius: var(--radius-md); flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent-strong); margin-bottom: var(--space-2);
}
.stat-card.is-warning .stat-icon { background: var(--warning-soft); color: var(--warning); }
.stat-card.is-danger .stat-icon { background: var(--danger-soft); color: var(--danger); }
.stat-card.is-success .stat-icon { background: var(--accent-soft); color: var(--accent-strong); }
.stat-card.is-neutral .stat-icon { background: var(--surface-sunken); color: var(--text-muted); }
.stat-card .stat-value { font-family: var(--font-display); font-size: 22px; font-weight: 800; }
.stat-card .stat-label { color: var(--text-muted); font-size: 13px; }

/* ----- Section ----- */
.section-title { font-size: 15px; font-weight: 700; font-family: var(--font-display); margin-bottom: var(--space-3); }
.section { margin-bottom: var(--space-6); }

/* ----- List rows ----- */
.list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: var(--surface); }
.list-row {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  width: 100%;
  border-left: none; border-right: none; border-top: none;
  transition: background 150ms ease;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface-sunken); }
.list-row .row-icon {
  width: 38px; height: 38px; border-radius: var(--radius-md); flex: none;
  background: var(--surface-sunken); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; color: var(--text-muted);
}
.row-main { --od-gap: 2px; }
.row-title { font-weight: 600; font-size: 14px; }
.row-sub { font-size: 13px; color: var(--text-faint); }
.row-end { --od-gap: 4px; align-items: flex-end; text-align: right; }
.row-chevron { color: var(--text-faint); flex: none; }

/* ----- Badges ----- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  white-space: nowrap;
}
.badge-neutral { background: var(--surface-sunken); color: var(--text-muted); border: 1px solid var(--border); }
.badge-success { background: var(--accent-soft); color: var(--accent-strong); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

/* ----- Tabs ----- */
.tabs { display: flex; gap: var(--space-2); border-bottom: 1px solid var(--border); margin-bottom: var(--space-5); overflow-x: auto; }
.tab-btn {
  background: none; border: none; cursor: pointer;
  padding: 10px 4px; margin-right: var(--space-5);
  font-size: 14px; font-weight: 600; color: var(--text-faint);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ----- Detail layout ----- */
.detail-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--space-5); align-items: start; }
.field-row { display: grid; grid-template-columns: 140px 1fr; gap: var(--space-3); padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.field-row:last-child { border-bottom: none; }
.field-row .k { color: var(--text-faint); }
.field-row .v { font-weight: 600; }

/* ----- Timeline ----- */
.timeline { display: flex; flex-direction: column; }
.tl-step { display: flex; gap: var(--space-3); position: relative; padding-bottom: var(--space-5); }
.tl-step:last-child { padding-bottom: 0; }
.tl-step::before {
  content: ""; position: absolute; left: 13px; top: 28px; bottom: 0; width: 2px; background: var(--border);
}
.tl-step:last-child::before { display: none; }
.tl-dot {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: var(--surface-sunken); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center; color: var(--text-faint); z-index: 1;
}
.tl-step.done .tl-dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.tl-step.current .tl-dot { background: var(--primary); border-color: var(--primary); color: #fff; }
.tl-body { --od-gap: 2px; padding-top: 3px; }
.tl-title { font-weight: 700; font-size: 14px; }
.tl-date { font-size: 12.5px; color: var(--text-faint); }
.tl-note { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ----- Forms ----- */
.form-field { --od-gap: 6px; margin-bottom: var(--space-4); }
.form-field label { font-size: 13px; font-weight: 600; color: var(--text); }
.form-field .hint { font-size: 12px; color: var(--text-faint); }
.form-field input, .form-field textarea, .form-field select {
  font: inherit; padding: 10px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  width: 100%;
}
.form-field input:focus, .form-field textarea:focus, .form-field select:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
.checkbox-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13.5px; }
.checkbox-row input { width: 18px; height: 18px; flex: none; }

/* ----- Toast / banner ----- */
.banner {
  display: flex; align-items: center; gap: var(--space-3);
  background: var(--accent-soft); color: var(--accent-strong);
  border: 1px solid #BFE4D8; border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4); margin-bottom: var(--space-5); font-size: 14px; font-weight: 600;
}

/* ----- Empty state ----- */
.empty-state { text-align: center; padding: var(--space-7) var(--space-4); color: var(--text-faint); }
.empty-state .od-icon { color: var(--text-faint); margin-bottom: var(--space-2); }

/* ----- Dialog / modal ----- */
dialog.modal {
  border: none; border-radius: var(--radius-lg); padding: 0;
  width: min(480px, calc(100vw - 32px)); box-shadow: var(--shadow-md);
}
dialog.modal::backdrop { background: rgba(15, 23, 42, 0.45); }
.modal-body { padding: var(--space-5); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5) 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); margin-top: var(--space-4); }

/* ----- Mobile sidebar drawer ----- */
.sidebar-scrim { display: none; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .stat-grid { --od-cols: 2; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 30;
    transform: translateX(-100%); transition: transform 200ms ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim {
    display: block; position: fixed; inset: 0; background: rgba(15,23,42,0.5);
    z-index: 25; opacity: 0; pointer-events: none; transition: opacity 200ms ease;
  }
  .sidebar-scrim.open { opacity: 1; pointer-events: auto; }
  .topbar-menu-btn { display: flex; }
  .view { padding: var(--space-4) var(--space-4) var(--space-7); }
  .stat-grid { --od-cols: 2; }
}

@media (max-width: 480px) {
  .stat-grid { --od-cols: 1; }
  .field-row { grid-template-columns: 1fr; gap: 2px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
