/* Raptool Check — design system
   Restrained, high-contrast, no gradients. Light and dark from one token set. */

:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #e8ebf0;
  --border:    #dfe3e9;
  --border-2:  #c8cfd8;
  --text:      #0e1620;
  --text-2:    #55606e;
  --text-3:    #8a94a1;

  --accent:      #0b6bcb;
  --accent-ink:  #ffffff;
  --accent-soft: #e7f0fb;
  --accent-line: #a9c9ee;

  --ok:        #1a7f4b;
  --ok-soft:   #e3f4ea;
  --warn:      #b06a00;
  --warn-soft: #fdf0dc;
  --bad:       #c0392f;
  --bad-soft:  #fbe7e5;
  --info:      #2b6f8f;
  --info-soft: #e3f1f6;
  --muted-soft:#eceff3;

  --sidebar-bg:    #0f1d2e;
  --sidebar-text:  #c3ccd8;
  --sidebar-hover: #17293e;
  --sidebar-active:#1d3247;

  --radius:   10px;
  --radius-s: 7px;
  --radius-l: 14px;
  --shadow-1: 0 1px 2px rgba(14,22,32,.06), 0 1px 3px rgba(14,22,32,.04);
  --shadow-2: 0 4px 12px rgba(14,22,32,.08), 0 1px 3px rgba(14,22,32,.06);
  --shadow-3: 0 16px 48px rgba(14,22,32,.18);

  --sidebar-w: 232px;
  --header-h:  56px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg:        #0c131c;
  --surface:   #121b26;
  --surface-2: #17212e;
  --surface-3: #1e2a39;
  --border:    #253346;
  --border-2:  #33455c;
  --text:      #e8edf4;
  --text-2:    #9fadbf;
  --text-3:    #6e7f93;

  --accent:      #4f9df2;
  --accent-ink:  #061422;
  --accent-soft: #14283c;
  --accent-line: #2b4f75;

  --ok:        #4ec98a;  --ok-soft:  #12301f;
  --warn:      #e0a33c;  --warn-soft:#332507;
  --bad:       #f0756a;  --bad-soft: #3a1512;
  --info:      #63b6d6;  --info-soft:#0e2a35;
  --muted-soft:#1c2733;

  --sidebar-bg:    #0a121c;
  --sidebar-hover: #14202e;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 4px 14px rgba(0,0,0,.45);
  --shadow-3: 0 18px 50px rgba(0,0,0,.6);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.011em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p  { margin: 0 0 10px; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .92em; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(0.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); background: var(--accent); }
.btn-danger  { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.07); background: var(--bad); }
.btn-ghost   { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; border-radius: var(--radius); }
.btn-block { width: 100%; }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-s) 0 0 var(--radius-s); margin-left: 0; }
.btn-group .btn:last-child  { border-radius: 0 var(--radius-s) var(--radius-s) 0; }
.btn-group .btn.is-on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); z-index: 1; }

/* ------------------------------------------------------------------- inputs */
.field { display: block; margin-bottom: 14px; }
.field > label, .label {
  display: block; margin-bottom: 5px;
  font-size: 12px; font-weight: 500; color: var(--text-2);
}
.input, .select, .textarea {
  width: 100%; height: 34px; padding: 0 10px;
  border: 1px solid var(--border-2); border-radius: var(--radius-s);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 13px;
  transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; min-height: 76px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none; padding-right: 28px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%238a94a1' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid {
  border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft);
}
.field-error { margin-top: 4px; font-size: 12px; color: var(--bad); }
.hint { margin-top: 4px; font-size: 12px; color: var(--text-3); }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.check input[type=checkbox], .check input[type=radio] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; cursor: pointer; }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border-2); border-radius: 22px; transition: background .15s;
}
.switch span::before {
  content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(16px); }

.row  { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* -------------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.card-head h2 { flex: 1; }
.card-body { padding: 16px; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ------------------------------------------------------------------- tables */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-weight: 500; font-size: 11.5px;
  letter-spacing: .03em; text-transform: uppercase; color: var(--text-3);
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 2; white-space: nowrap;
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text-2); }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table-wrap { overflow: auto; }

/* ------------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 21px; padding: 0 8px; border-radius: 11px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
  background: var(--muted-soft); color: var(--text-2);
}
.badge.ok      { background: var(--ok-soft);   color: var(--ok); }
.badge.warn    { background: var(--warn-soft); color: var(--warn); }
.badge.bad     { background: var(--bad-soft);  color: var(--bad); }
.badge.info    { background: var(--info-soft); color: var(--info); }
.badge.accent  { background: var(--accent-soft); color: var(--accent); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.pill-count {
  display: inline-block; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--surface-3); color: var(--text-2);
  font-size: 11px; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums;
}
.pill-count.bad { background: var(--bad); color: #fff; }

.sev-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.sev-rectified { background: var(--ok); }
.sev-deviation { background: var(--warn); }
.sev-serious   { background: var(--bad); }

.avatar {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: #fff; background: var(--accent);
  text-transform: uppercase; letter-spacing: .02em;
}
.avatar.sm { width: 21px; height: 21px; font-size: 9.5px; }
.avatar.lg { width: 38px; height: 38px; font-size: 14px; }
.avatar.xl { width: 56px; height: 56px; font-size: 20px; }
/* v12: a photo covers the initials (they stay underneath, for a photo that fails to load) */
.avatar { position: relative; overflow: hidden; }
.avatar.has-photo { color: transparent; background: var(--surface-2) !important; }
.avatar .avatar-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; border-radius: 50%; display: block;
}

/* v4.14.0: overlapping avatars (UI.avatarStack) — each sits on a ring of the row's own background */
.av-stack { display: inline-flex; align-items: center; vertical-align: middle; }
.av-stack > .avatar { box-shadow: 0 0 0 2px var(--surface); cursor: default; }
.av-stack > .avatar + .avatar { margin-left: -7px; }
.av-stack > .av-group { background: var(--accent-soft); color: var(--accent); }
.av-stack > .av-more { background: var(--surface-3); color: var(--text-2); font-weight: 600; text-transform: none; letter-spacing: 0; }

/* v4.14.0: the page guide — an (i) next to the page title and its popover (UI.guideButton) */
.guide-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--text-3); cursor: pointer;
  transition: background .12s, color .12s;
}
.guide-btn:hover, .guide-btn.is-open { background: var(--accent-soft); color: var(--accent); }
.guide-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.guide-pop {
  position: fixed; z-index: 90; top: 0; left: 0; box-sizing: border-box;
  width: max-content; max-width: min(420px, calc(100vw - 24px)); overflow-y: auto; overscroll-behavior: contain;
  padding: 12px 16px 14px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-l); box-shadow: var(--shadow-3);
  font-size: 13.5px; line-height: 1.5; text-align: left; white-space: normal;
}
.guide-pop:focus { outline: none; }
.guide-pop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.guide-head { display: flex; align-items: center; gap: 8px; margin: 0 -6px 6px 0; }
.guide-ico { display: inline-flex; color: var(--accent); flex: none; }
.guide-title { flex: 1; margin: 0; font-size: 14px; font-weight: 650; }
.guide-x {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; padding: 0; border: 0; border-radius: var(--radius-s);
  background: transparent; color: var(--text-3); cursor: pointer; visibility: hidden;
}
.guide-pop.is-pinned .guide-x { visibility: visible; }
.guide-x:hover { background: var(--surface-2); color: var(--text); }
.guide-body p { margin: 0 0 8px; color: var(--text-2); }
.guide-body ul { margin: 0 0 8px; padding-left: 18px; }
.guide-body li { margin: 0 0 5px; color: var(--text); }
.guide-body li::marker { color: var(--accent); }
.guide-body > :last-child { margin-bottom: 0; }

/* --------------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 8px 12px; border: none; background: none; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 500; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 7px;
}
.tab:hover { color: var(--text); }
.tab.is-on { color: var(--accent); border-bottom-color: var(--accent); }

/* ------------------------------------------------------------------- layout */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  height: var(--header-h); flex: none; display: flex; align-items: center; gap: 9px;
  padding: 0 16px; color: #fff; font-weight: 600; font-size: 14.5px;
  letter-spacing: -0.01em; border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-brand .mark { width: 22px; height: 22px; flex: none; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.sidebar-group { margin-bottom: 14px; }
.sidebar-group-label {
  padding: 4px 8px; font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase;
  color: rgba(255,255,255,.34); font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: var(--radius-s);
  color: var(--sidebar-text); font-size: 13px; cursor: pointer;
  text-decoration: none; margin-bottom: 1px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.is-on { background: rgba(255,255,255,.1); color: #fff; font-weight: 500; }
.nav-item svg { width: 16px; height: 16px; flex: none; opacity: .8; }
.nav-item .pill-count { margin-left: auto; background: rgba(255,255,255,.14); color: #fff; }
.sidebar-foot { flex: none; padding: 10px; border-top: 1px solid rgba(255,255,255,.07); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: 12px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { flex: none; }
.topbar-title { display: flex; align-items: center; gap: 4px; flex: none; }      /* v4.14.0: the page title and its (i) */
.topbar-guide { display: inline-flex; flex: none; }
.topbar .spacer { flex: 1; }
.content { padding: 20px; flex: 1; }
.content-narrow { max-width: 900px; }

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .input, .toolbar .select { height: 32px; width: auto; min-width: 140px; }
.toolbar .search { min-width: 220px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-6 { grid-template-columns: repeat(6, minmax(0,1fr)); }
@media (max-width: 1200px) { .grid-6 { grid-template-columns: repeat(3, minmax(0,1fr)); } .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 800px)  { .grid-2, .grid-3, .grid-4, .grid-6 { grid-template-columns: 1fr; } }

/* -------------------------------------------------------------------- tiles */
.tile { padding: 14px 16px; }
.tile-label { font-size: 12px; color: var(--text-2); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.tile-value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile-sub { margin-top: 5px; font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.delta { font-size: 12px; font-weight: 500; }
.delta.up   { color: var(--ok); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--text-3); }

/* ------------------------------------------------------------------- modals */
.overlay {
  position: fixed; inset: 0; background: rgba(9,15,23,.46);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 100; backdrop-filter: blur(1.5px);
}
.modal {
  background: var(--surface); border-radius: var(--radius-l);
  box-shadow: var(--shadow-3); width: 100%; max-width: 560px;
  max-height: calc(100vh - 48px); display: flex; flex-direction: column;
  border: 1px solid var(--border);
}
.modal.wide { max-width: 860px; }
.modal.xwide { max-width: 1120px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px; overflow: auto; flex: 1; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.drawer-wrap { position: fixed; inset: 0; z-index: 100; display: flex; justify-content: flex-end; background: rgba(9,15,23,.36); }
.drawer { width: 560px; max-width: 100vw; background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; box-shadow: var(--shadow-3); }

/* ------------------------------------------------------------------- toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-s); box-shadow: var(--shadow-2);
  padding: 10px 14px; font-size: 13px; max-width: 380px;
  animation: toast-in .16s ease-out;
}
.toast.ok  { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* -------------------------------------------------------------------- empty */
.empty { padding: 48px 20px; text-align: center; color: var(--text-3); }
.empty svg { width: 34px; height: 34px; opacity: .45; margin-bottom: 10px; }
.empty h3 { color: var(--text-2); margin-bottom: 4px; }

.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border-2);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; display: flex; justify-content: center; }

.skeleton { background: var(--surface-3); border-radius: 5px; animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* ------------------------------------------------------------------ helpers */
.muted    { color: var(--text-2); }
.muted-2  { color: var(--text-3); }
.small    { font-size: 12px; }
.xsmall   { font-size: 11px; }
.strong   { font-weight: 600; }
.tnum     { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex     { display: flex; align-items: center; gap: 8px; }
.flex-col { display: flex; flex-direction: column; }
.between  { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wrap     { flex-wrap: wrap; }
.spacer   { flex: 1; }
.hidden   { display: none !important; }
.mt-0{margin-top:0}.mt-1{margin-top:6px}.mt-2{margin-top:12px}.mt-3{margin-top:18px}.mt-4{margin-top:26px}
.mb-0{margin-bottom:0}.mb-1{margin-bottom:6px}.mb-2{margin-bottom:12px}.mb-3{margin-bottom:18px}
.sep { height: 1px; background: var(--border); margin: 14px 0; }
.vsep { width: 1px; align-self: stretch; background: var(--border); margin: 0 4px; }

/* ------------------------------------------------- alert strip (operator app) */
.m-topbar { flex: none; }
.m-topbar.hidden { display: none; }
