/* Sea Containers NZ — Connected Hub
   Original design system, rooted in the client's brand:
   - Primary:  #1FA7E6  (hero cyan-blue)
   - Deep:     #0E2A47  (navy footer)
   - Paper:    warm off-white
*/

:root {
  --brand-cyan: #1FA7E6;
  --brand-cyan-600: #1489BF;
  --brand-cyan-50: #E8F5FC;
  --navy: #0E2A47;
  --navy-800: #13345A;
  --navy-700: #1B4270;
  --navy-500: #4B6989;

  --ink-900: #0E2A47;
  --ink-700: #33445A;
  --ink-500: #6B7A8D;
  --ink-400: #8E9AAB;
  --ink-300: #B6BECB;
  --ink-200: #D5DBE3;
  --ink-100: #EAEDF2;
  --ink-50:  #F4F6F9;

  --paper: #FAFBFC;
  --paper-warm: #F6F4EF;
  --card: #FFFFFF;
  --line: #E4E8EE;
  --line-soft: #EEF1F5;

  --ok: #2F9E6B;
  --ok-bg: #E6F4EC;
  --warn: #C58A12;
  --warn-bg: #FBF1D8;
  --err: #C5413A;
  --err-bg: #FBE9E7;
  --info: #1FA7E6;
  --info-bg: #E8F5FC;

  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;
  --radius-xl: 14px;

  --shadow-sm: 0 1px 0 rgba(14,42,71,0.04), 0 1px 2px rgba(14,42,71,0.04);
  --shadow: 0 1px 2px rgba(14,42,71,0.04), 0 4px 16px rgba(14,42,71,0.06);
  --shadow-lg: 0 8px 32px rgba(14,42,71,0.12), 0 2px 6px rgba(14,42,71,0.06);

  --font-sans: "Open Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

[data-theme="dark"] {
  --paper: #0A1726;
  --paper-warm: #0A1726;
  --card: #0F2338;
  --line: #1B3450;
  --line-soft: #162C45;

  --ink-900: #F4F6F9;
  --ink-700: #C8D2DE;
  --ink-500: #8E9AAB;
  --ink-400: #6B7A8D;
  --ink-300: #4B6989;
  --ink-200: #2B4364;
  --ink-100: #16304A;
  --ink-50:  #0F2338;

  --navy: #1FA7E6;
  --navy-800: #0F2338;
  --navy-700: #16304A;

  --brand-cyan-50: #0F2B40;

  --ok-bg: #0F2E23;
  --warn-bg: #2E2414;
  --err-bg: #2E1716;
  --info-bg: #0F2B40;

  --shadow-sm: 0 1px 0 rgba(0,0,0,0.3);
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 4px 16px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink-900);
  background: var(--paper);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}

button { font-family: inherit; cursor: pointer; border: 0; background: transparent; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; overflow: hidden; }

.rail {
  background: var(--navy);
  color: #DDE8F2;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--navy-800);
}
[data-theme="dark"] .rail { background: #081324; border-right-color: #10273E; }

.rail-header {
  padding: 18px 18px 14px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.rail-header .logo-mark {
  width: 34px; height: 34px; flex: none;
  background: #fff; border-radius: 6px; padding: 4px;
  display: grid; place-items: center;
}
.rail-header .logo-mark img { width: 100%; height: 100%; object-fit: contain; }
.rail-header h1 { font-size: 13.5px; margin: 0; color: #fff; font-weight: 700; letter-spacing: 0.02em; }
.rail-header h1 small {
  display: block; font-size: 10.5px; color: rgba(255,255,255,0.55);
  font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; margin-top: 2px;
}

.rail-section { padding: 14px 8px 4px; }
.rail-section-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: rgba(255,255,255,0.42); padding: 0 10px 6px;
}
.rail-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px; border-radius: 6px;
  color: rgba(255,255,255,0.78);
  font-size: 13px; font-weight: 500; text-align: left;
  transition: background .12s, color .12s;
}
.rail-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.rail-item.active { background: var(--brand-cyan); color: #fff; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08); }
.rail-item .rail-ico { width: 16px; height: 16px; flex: none; opacity: 0.85; }
.rail-item.active .rail-ico { opacity: 1; }
.rail-item .rail-sub {
  margin-left: auto; font-size: 10.5px;
  background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.9);
  padding: 1px 6px; border-radius: 999px; font-weight: 600;
}
.rail-item.active .rail-sub { background: rgba(255,255,255,0.22); }

.rail-foot {
  margin-top: auto; padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 11.5px; color: rgba(255,255,255,0.5);
  display: flex; align-items: center; gap: 8px;
}
.rail-foot .dot { width: 7px; height: 7px; border-radius: 50%; background: #3fd69a; box-shadow: 0 0 0 3px rgba(63,214,154,0.18); }

/* ---------- Main + topbar ---------- */
.main { display: flex; flex-direction: column; overflow: hidden; background: var(--paper); }
.topbar {
  height: 52px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 20px; background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar .crumbs { font-size: 12.5px; color: var(--ink-500); display: flex; align-items: center; gap: 6px; }
.topbar .crumbs b { color: var(--ink-900); font-weight: 600; }
.topbar .sep { color: var(--ink-300); }
.topbar-search {
  margin-left: 16px; flex: 1; max-width: 420px; position: relative;
}
.topbar-search input {
  width: 100%; height: 32px; padding: 0 10px 0 30px;
  background: var(--ink-50); border: 1px solid transparent; border-radius: 6px;
  outline: none; font-size: 12.5px;
}
.topbar-search input:focus { border-color: var(--brand-cyan); background: var(--card); }
.topbar-search .mag {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 13px; height: 13px; color: var(--ink-400);
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-btn {
  height: 30px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--line);
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; background: var(--card); color: var(--ink-700);
}
.topbar-btn:hover { border-color: var(--ink-300); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--brand-cyan); color: #fff;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}

.view { flex: 1; overflow: auto; }
.view-inner { max-width: 1440px; margin: 0 auto; padding: 24px 28px 48px; }
.view h2.page-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.01em; }
.view .page-sub { color: var(--ink-500); font-size: 13px; margin: 0 0 20px; }

/* ---------- Generic cards / tables ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-head {
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.card-head h3 { font-size: 13px; font-weight: 700; margin: 0; letter-spacing: -0.005em; }
.card-head .count { color: var(--ink-500); font-size: 12px; font-weight: 500; }
.card-head .right { margin-left: auto; display: flex; gap: 6px; }

.muted { color: var(--ink-500); }
.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }

/* Source chip — shows which system a field comes from */
.src-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 6px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--ink-500);
  font-size: 10px; font-weight: 600; letter-spacing: 0.02em; font-family: var(--font-mono);
  text-transform: none;
  vertical-align: middle;
}
.src-chip::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-400);
}
.src-chip[data-src="Cin7"]::before { background: #7A5FCD; }
.src-chip[data-src="Xero"]::before { background: #17B2E0; }
.src-chip[data-src="Adobe Sign"]::before { background: #E5502F; }
.src-chip[data-src="OneDrive"]::before { background: #0364B8; }
.src-chip[data-src="Website"]::before { background: #2F9E6B; }
.src-chip[data-src="SMS"]::before { background: #C58A12; }
.src-chip[data-src="Outlook"]::before { background: #0364B8; }
.src-chip[data-src="Hub"]::before { background: var(--brand-cyan); }

/* Status pills */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--ink-100); color: var(--ink-700);
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.err { background: var(--err-bg); color: var(--err); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.no-dot::before { display: none; }

/* Buttons */
.btn {
  height: 32px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--line);
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-900); background: var(--card);
  transition: background .1s, border-color .1s, transform .02s;
}
.btn:hover { background: var(--ink-50); border-color: var(--ink-300); }
.btn:active { transform: translateY(0.5px); }
.btn.primary { background: var(--brand-cyan); border-color: var(--brand-cyan); color: #fff; }
.btn.primary:hover { background: var(--brand-cyan-600); border-color: var(--brand-cyan-600); }
.btn.dark { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.dark:hover { background: var(--navy-800); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-700); }
.btn.ghost:hover { background: var(--ink-100); }
.btn.sm { height: 26px; padding: 0 8px; font-size: 11.5px; }
.btn.lg { height: 40px; padding: 0 16px; font-size: 13.5px; }
.btn.icon-only { width: 32px; padding: 0; justify-content: center; }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th {
  text-align: left; font-weight: 600; color: var(--ink-500);
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--ink-50);
}
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.tbl tbody tr:hover td { background: var(--ink-50); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl td .row-label { font-weight: 600; color: var(--ink-900); }
.tbl td .row-meta { color: var(--ink-500); font-size: 11.5px; }

/* Field labels */
.field-label {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
  font-size: 11px; font-weight: 600; color: var(--ink-500);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.field-value { font-size: 13px; color: var(--ink-900); }
.field-value.big { font-size: 15px; font-weight: 600; }

/* Focus reset */
*:focus-visible { outline: 2px solid var(--brand-cyan); outline-offset: 1px; }

/* Scrollbars */
.view::-webkit-scrollbar, .scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.view::-webkit-scrollbar-thumb, .scroll::-webkit-scrollbar-thumb { background: var(--ink-200); border-radius: 999px; border: 2px solid var(--paper); }
.view::-webkit-scrollbar-thumb:hover { background: var(--ink-300); }

/* Phone stage */
.phone-stage {
  background: linear-gradient(180deg, var(--ink-100), var(--ink-50));
  border-radius: var(--radius-lg); border: 1px solid var(--line);
  display: grid; place-items: center; padding: 32px;
}
[data-theme="dark"] .phone-stage { background: linear-gradient(180deg, #0A1726, #0F2338); }

/* TV dashboard */
.tv {
  background: #081324; color: #E8F1FA; min-height: 100%;
  padding: 24px; display: grid; gap: 16px; grid-template-columns: 2fr 1fr;
  grid-auto-rows: min-content;
}
.tv-card { background: #0F2338; border: 1px solid #1B3450; border-radius: 12px; padding: 16px; }
.tv-card h4 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: #8EA7C4; font-weight: 700; }
.tv-big { font-family: var(--font-mono); font-size: 44px; font-weight: 600; letter-spacing: -0.02em; }
.tv-delta-up { color: #3FD69A; font-size: 12px; font-weight: 600; }
.tv-delta-down { color: #FF7A7A; font-size: 12px; font-weight: 600; }

/* Flow banner — shown when a guided flow is active */
.flow-banner {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 10px 14px;
  border-radius: 10px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 12px;
  font-size: 12.5px; z-index: 40;
  max-width: 90vw;
}
.flow-banner .flow-step {
  font-family: var(--font-mono); font-size: 11px; background: rgba(255,255,255,0.12);
  padding: 2px 6px; border-radius: 4px;
}
.flow-banner .flow-next {
  height: 28px; padding: 0 10px; border-radius: 6px; background: var(--brand-cyan); color: #fff;
  font-weight: 600; font-size: 12px;
}
.flow-banner .flow-close { color: rgba(255,255,255,0.6); padding: 0 4px; }

/* Animated bits */
@keyframes slide-in {
  from { transform: translateY(6px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}
.slide-in { animation: slide-in .24s ease both; }

@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: 200px 0; }
}

/* A few helpers */
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.hidden { display: none !important; }

/* ---------- Mobile / narrow viewports ----------
   This is a desktop dashboard demo. On mobile we collapse the left rail
   into a horizontal scrolling strip, hide the topbar search, and let
   wide content (tables, multi-col grids) scroll horizontally rather
   than blowing out the viewport. */
@media (max-width: 820px) {
  body { font-size: 13.5px; }

  /* App shell stacks: rail on top, main below.
     minmax(0, 1fr) prevents the column from growing to fit non-wrapping
     content (the role buttons), which would push the whole layout wider
     than the viewport. */
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .rail, .main { min-width: 0; }

  /* Rail becomes a compact top bar with horizontally scrollable role chips */
  .rail {
    flex-direction: column;
    border-right: none;
    border-bottom: 1px solid var(--navy-800);
  }
  .rail-header { padding: 12px 14px; }
  .rail-header h1 { font-size: 13px; }
  .rail-header h1 small { font-size: 9.5px; }

  /* Hide footer + the "Systems the Hub sits on" section on mobile.
     :first-of-type / :nth-of-type count among all div siblings — rail-header
     is also a div, which breaks those selectors. Target by content with :has. */
  .rail-foot { display: none; }
  .rail-section:not(:has(.rail-item)) { display: none; }

  /* Role buttons become a horizontal scroll strip */
  .rail-section:has(.rail-item) {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    padding: 8px 12px;
    -webkit-overflow-scrolling: touch;
  }
  .rail-section:has(.rail-item) .rail-section-label { display: none; }
  .rail .rail-item {
    display: inline-flex;
    width: auto;
    flex: none;
    white-space: nowrap;
  }

  /* Main + topbar */
  .main { overflow: visible; }
  .topbar {
    height: auto;
    min-height: 48px;
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar-search { display: none; }
  .topbar-right { gap: 6px; margin-left: auto; }
  .topbar-btn { height: 28px; padding: 0 8px; font-size: 11.5px; }
  .avatar { width: 26px; height: 26px; font-size: 10.5px; }

  .view { overflow: visible; }
  .view-inner { padding: 16px 14px 40px; }
  .view h2.page-title { font-size: 18px; }
  .view .page-sub { font-size: 12.5px; }

  /* Make multi-column inline grids stack on mobile.
     Components use inline `gridTemplateColumns` so we force single column.
     This is broad on purpose — applies to any grid declared via inline style. */
  .view [style*="grid-template-columns"],
  .view [style*="gridTemplateColumns"] {
    grid-template-columns: 1fr !important;
  }

  /* Tables: let them scroll horizontally rather than blow out width */
  .tbl { font-size: 12px; }
  .card { overflow-x: auto; }

  /* Phone stage padding */
  .phone-stage { padding: 16px; }

  /* TV dashboard stacks single column on mobile.
     Override its own inline padding too (set as style={{padding: 24}}). */
  .tv {
    grid-template-columns: 1fr !important;
    padding: 14px !important;
    gap: 12px;
  }
  .tv-big { font-size: 32px; }
  .tv-card { padding: 12px; }

  /* Flow banner sticks to bottom, full-width */
  .flow-banner {
    bottom: 8px;
    left: 8px;
    right: 8px;
    transform: none;
    max-width: none;
    flex-wrap: wrap;
    font-size: 12px;
    padding: 8px 10px;
  }
}

/* Extra-narrow phones */
@media (max-width: 420px) {
  .view-inner { padding: 12px 10px 32px; }
  .topbar-btn span { display: none; } /* icons only */
  .rail-header h1 small { display: none; }
}
