/* Nexlink Operation — design tokens & shared components
   Direction: Linear/Height × finance back-office · light · indigo/slate */

@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap");

:root {
  --bg: oklch(0.975 0.008 265);
  --surface: oklch(0.995 0.003 265);
  --surface-2: oklch(0.96 0.01 265);
  --fg: oklch(0.24 0.035 265);
  --muted: oklch(0.52 0.025 265);
  --border: oklch(0.88 0.015 265);
  --border-strong: oklch(0.78 0.02 265);
  --accent: oklch(0.42 0.11 275);
  --accent-fg: oklch(0.99 0.01 275);
  --accent-soft: oklch(0.94 0.03 275);
  --sidebar: oklch(0.22 0.04 270);
  --sidebar-fg: oklch(0.92 0.01 270);
  --sidebar-muted: oklch(0.65 0.02 270);
  --ok: oklch(0.52 0.13 150);
  --ok-soft: oklch(0.94 0.04 150);
  --warn: oklch(0.68 0.14 75);
  --warn-soft: oklch(0.95 0.04 85);
  --fail: oklch(0.55 0.18 25);
  --fail-soft: oklch(0.95 0.03 25);
  --pending: oklch(0.72 0.01 265);
  --shadow-sm: 0 1px 2px oklch(0.3 0.03 265 / 0.06);
  --shadow-md: 0 4px 16px oklch(0.3 0.03 265 / 0.08);
  --radius: 8px;
  --radius-sm: 6px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sp-1: oklch(0.72 0.08 230);
  --sp-2: oklch(0.62 0.1 250);
  --sp-3: oklch(0.55 0.12 270);
  --sp-5: oklch(0.5 0.13 290);
  --sp-8: oklch(0.48 0.14 320);
  --sp-13: oklch(0.45 0.15 25);
  --topbar-h: 52px;
  --sidebar-w: 232px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 550;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}
.btn-primary:hover:not(:disabled) {
  background: oklch(0.36 0.11 275);
  color: var(--accent-fg);
}
.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--fg);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--fg);
}
.btn-danger {
  background: var(--fail);
  color: oklch(0.99 0.01 25);
}
.btn-danger:hover:not(:disabled) {
  background: oklch(0.48 0.18 25);
  color: oklch(0.99 0.01 25);
}
.btn-success {
  background: var(--ok);
  color: oklch(0.99 0.01 150);
}
.btn-success:hover:not(:disabled) {
  background: oklch(0.45 0.13 150);
  color: oklch(0.99 0.01 150);
}
.btn-lg { min-height: 44px; padding: 0 18px; font-size: 14px; }
.btn-block { width: 100%; }

/* —— Form —— */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.field .req::after { content: " *"; color: var(--fail); }
.input, .select, .textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:hover, .select:hover, .textarea:hover {
  border-color: var(--border-strong);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }

/* —— Badges —— */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.badge-neutral { background: var(--surface-2); color: var(--muted); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: oklch(0.45 0.12 65); }
.badge-fail { background: var(--fail-soft); color: var(--fail); }
.badge-mono {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: -0.02em;
}

.sp-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 22px;
  padding: 0 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: white;
}
.sp-1 { background: var(--sp-1); }
.sp-2 { background: var(--sp-2); }
.sp-3 { background: var(--sp-3); }
.sp-5 { background: var(--sp-5); }
.sp-8 { background: var(--sp-8); }
.sp-13 { background: var(--sp-13); }

.cat-tag {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.deadline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 550;
  font-family: var(--mono);
  background: var(--surface-2);
  color: var(--muted);
}
.deadline.overdue {
  background: var(--fail-soft);
  color: var(--fail);
}
.deadline.soon {
  background: var(--warn-soft);
  color: oklch(0.45 0.12 65);
}

.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.avatar-lg { width: 36px; height: 36px; font-size: 13px; }

/* —— Cards —— */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 16px; }

/* —— AND-gate lights —— */
.and-gate {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.and-light {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
}
.and-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 2px oklch(0 0 0 / 0.08);
}
.and-dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.and-dot.off { background: var(--fail); box-shadow: 0 0 0 3px var(--fail-soft); }
.and-dot.pending { background: var(--pending); }

.and-gate-mini {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.and-gate-mini .and-dot {
  width: 8px;
  height: 8px;
  box-shadow: none;
}
.and-gate-mini .and-dot.on { box-shadow: none; }
.and-gate-mini .and-dot.off { box-shadow: none; }

/* —— Layout shell —— */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
  min-height: 0;
}
.app-shell.is-login {
  display: block;
  height: auto;
  min-height: 100vh;
}
.app-shell.is-mobile { background: var(--bg); }

.sidebar {
  grid-row: 1 / -1;
  background: var(--sidebar);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 4px;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
}
.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: oklch(0.55 0.14 275);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  color: white;
  font-family: var(--mono);
}
.sidebar-brand h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.sidebar-brand p {
  margin: 0;
  font-size: 11px;
  color: var(--sidebar-muted);
}
.nav-section {
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
  padding: 14px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--sidebar-fg);
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  opacity: 0.82;
}
.nav-item:hover {
  background: oklch(1 0 0 / 0.08);
  opacity: 1;
  color: var(--sidebar-fg);
}
.nav-item.active {
  background: oklch(1 0 0 / 0.12);
  opacity: 1;
  color: white;
}
.nav-item svg { flex-shrink: 0; opacity: 0.85; }
.nav-item.mobile-only { display: none; }

.topbar {
  grid-column: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.topbar-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-menu {
  position: relative;
}
.user-menu-trigger {
  border: none;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.user-menu-trigger:hover {
  filter: brightness(1.08);
}
.user-menu-trigger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  min-width: 200px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.user-menu-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.user-menu-meta strong {
  font-size: 13px;
  font-weight: 650;
  color: var(--fg);
}
.user-menu-meta span {
  font-size: 11px;
  color: var(--muted);
}
.user-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.user-menu-item:hover {
  background: var(--surface-2);
  color: var(--fg);
}
.user-menu-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.user-menu-item-danger {
  color: var(--fail);
}
.user-menu-item-danger:hover {
  background: var(--fail-soft);
  color: var(--fail);
}
.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}
.main {
  grid-column: 2;
  overflow: auto;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

/* —— Screen —— */
.screen { display: none; min-height: 100%; }
.screen.active { display: block; }
.screen-pad { padding: 20px 24px 40px; }

.phone-frame {
  max-width: 390px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  position: relative;
}
.phone-status {
  height: 44px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 20px 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--mono);
  background: var(--surface);
}
.phone-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.phone-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  flex: 1;
}
.phone-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 100px;
}
.phone-footer {
  position: sticky;
  bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: oklch(1 0 0 / 0.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-header h2 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.page-header .sub {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-bar .select, .filter-bar .input {
  min-height: 34px;
  width: auto;
  min-width: 140px;
}
.filter-bar .spacer { flex: 1; }

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
}
.banner-warn {
  background: var(--warn-soft);
  border: 1px solid oklch(0.85 0.06 85);
  color: oklch(0.4 0.1 60);
}
.banner-fail {
  background: var(--fail-soft);
  border: 1px solid oklch(0.85 0.05 25);
  color: var(--fail);
}
.banner-ok {
  background: var(--ok-soft);
  border: 1px solid oklch(0.85 0.05 150);
  color: var(--ok);
}
.banner-locked {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: oklch(0.98 0.005 265); }
table.data .num {
  font-family: var(--mono);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
}
table.data .net {
  font-weight: 650;
  color: var(--accent);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat-card .label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 550;
  margin: 0 0 8px;
}
.stat-card .value {
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-family: var(--mono);
  margin: 0;
  line-height: 1.1;
}
.stat-card .hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0.2 0.03 265 / 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(520px, 100%);
  max-height: min(90vh, 720px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 650; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.chip-option {
  min-height: 64px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px;
  transition: border-color 0.12s, background 0.12s;
}
.chip-option:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}
.chip-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.chip-option .sp {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 650;
}
.chip-option .tier {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.progress {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 72px;
  margin-top: 8px;
}
.bar-chart .bar {
  flex: 1;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 4px;
  opacity: 0.85;
  position: relative;
}
.bar-chart .bar-label {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--muted);
  font-weight: 550;
  white-space: nowrap;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--fg);
}
.icon-btn:hover { background: var(--surface-2); }

@media (max-width: 900px) {
  /* Include .is-mobile: QC screens keep topbar/sidebar, so they need the same
     1-column shell. Excluding them left grid at sidebar-w + 1fr and squeezed
     chrome into the 232px track, causing page-level horizontal overflow. */
  .app-shell:not(.is-login) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }
  .sidebar {
    grid-row: auto;
    grid-column: 1;
    order: 3;
    flex-direction: row;
    flex-wrap: nowrap;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: hidden;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 0;
    justify-content: space-between;
  }
  .sidebar-brand, .nav-section { display: none; }
  .nav-item {
    flex-direction: column;
    flex: 1 1 0;
    gap: 2px;
    min-width: 0;
    max-width: none;
    min-height: 52px;
    font-size: 9px;
    line-height: 1.15;
    padding: 4px 2px;
    justify-content: center;
    text-align: center;
    white-space: normal;
    word-break: break-word;
    hyphens: auto;
  }
  .nav-item svg {
    width: 14px;
    height: 14px;
  }
  .nav-item.mobile-only { display: flex; }
  .topbar, .main { grid-column: 1; min-width: 0; max-width: 100%; }
  .screen-pad { padding: 14px 12px 24px; }

  /* Outer topbar already shows title/role — drop fake device status bar */
  .phone-status { display: none; }
  .phone-frame {
    max-width: none;
    width: 100%;
    min-height: 0;
    flex: 1;
    box-shadow: none;
  }
}
