/* Realpipe v2 — base + components */

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

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

h1, h2, h3, h4, h5, h6 { font-weight: 600; line-height: var(--lh-tight); margin: 0; }
h1 { font-size: var(--fs-22); letter-spacing: -0.01em; }
h2 { font-size: var(--fs-18); }
h3 { font-size: var(--fs-16); }
p { margin: 0; }

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

hr { border: 0; border-top: var(--border); margin: var(--s-4) 0; }

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

kbd {
  background: var(--surface-sunken);
  border: var(--border);
  border-radius: var(--r-sm);
  padding: 1px 5px;
  font-size: 0.85em;
  color: var(--text-muted);
}

.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: absolute;
  left: var(--s-2);
  top: -48px;
  background: var(--accent);
  color: var(--text-on-accent);
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-sm);
  z-index: var(--z-palette);
}
.skip-link:focus { top: var(--s-2); }

/* ======== LAYOUT ========================================= */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.app-sidebar {
  background: var(--surface-sunken);
  border-right: var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: var(--z-sticky);
}

.app-sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-4);
  border-bottom: var(--border-subtle);
  font-weight: 700;
  font-size: var(--fs-14);
  color: var(--text);
  letter-spacing: -0.01em;
}

.app-sidebar__brand-logo {
  display: block;
  height: 30px;
  width: auto;
  max-width: 100%;
}

.auth-card__brand-logo {
  display: block;
  height: 40px;
  width: auto;
  max-width: 100%;
}

.app-sidebar__brand-mark {
  width: 22px; height: 22px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--accent), var(--blue-700));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.15) inset;
}

.app-sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-3) var(--s-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.app-sidebar__section-label {
  padding: var(--s-3) var(--s-3) var(--s-1);
  font-size: var(--fs-11);
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  color: var(--text-muted);
  border-radius: var(--r-sm);
  font-size: var(--fs-13);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
}
.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-item__icon {
  width: 16px; height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.9;
}
.nav-item__label { flex: 1; }
.nav-item__badge {
  background: var(--surface-hover);
  color: var(--text-muted);
  border-radius: var(--r-full);
  padding: 1px 7px;
  font-size: var(--fs-11);
  font-weight: 600;
}

.app-sidebar__footer {
  padding: var(--s-3);
  border-top: var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--text-muted);
  font-size: var(--fs-12);
}
.app-sidebar__footer .btn-icon { margin-left: auto; }

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

.app-topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: var(--border);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0 var(--s-5);
}

.app-topbar__crumbs {
  font-size: var(--fs-13);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
}
.app-topbar__crumbs a { color: var(--text-muted); }
.app-topbar__crumbs a:hover { color: var(--text); text-decoration: none; }
.app-topbar__crumbs .sep { color: var(--text-subtle); }
.app-topbar__crumb-current { color: var(--text); font-weight: 500; }

.app-topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.topbar-search {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 0 var(--s-3);
  height: 30px;
  background: var(--surface-sunken);
  border: var(--border);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: var(--fs-13);
  min-width: 200px;
  cursor: pointer;
}
.topbar-search:hover { border-color: var(--border-strong-color); color: var(--text); }
.topbar-search kbd { margin-left: auto; }

.user-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 4px var(--s-2) 4px 4px;
  border-radius: var(--r-full);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: var(--fs-13);
}
.user-menu:hover { border-color: var(--border-color); color: var(--text); background: var(--surface-hover); }
.user-avatar {
  width: 24px; height: 24px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--text-on-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-11);
  font-weight: 700;
}

.app-content {
  padding: var(--s-5) var(--s-6);
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  margin-bottom: var(--s-5);
  flex-wrap: wrap;
}
.page-header__title { flex: 1; min-width: 0; }
.page-header__title h1 { margin: 0; }
.page-header__subtitle {
  color: var(--text-muted);
  font-size: var(--fs-13);
  margin-top: 2px;
}
.page-header__actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
}

/* ======== BUTTONS ======================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: 32px;
  padding: 0 var(--s-3);
  font-size: var(--fs-13);
  font-weight: 500;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.btn--sm { height: 28px; padding: 0 var(--s-2); font-size: var(--fs-12); }
.btn--lg { height: 38px; padding: 0 var(--s-4); font-size: var(--fs-14); }

.btn--primary {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-color);
}
.btn--secondary:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border-strong-color); }

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn--ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

.btn--danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn--danger:hover:not(:disabled) { background: var(--danger-hover); border-color: var(--danger-hover); }

.btn--subtle-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}
.btn--subtle-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-icon {
  width: 30px; height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.btn-icon:hover { background: var(--surface-hover); color: var(--text); }
.btn-icon svg { width: 16px; height: 16px; }

/* ======== FORM FIELDS ==================================== */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}
.field__label {
  font-size: var(--fs-12);
  color: var(--text-muted);
  font-weight: 500;
}
.field__hint { font-size: var(--fs-12); color: var(--text-subtle); }
.field__error { font-size: var(--fs-12); color: var(--danger); }

.input, .select, .textarea {
  width: 100%;
  height: 32px;
  padding: 0 var(--s-3);
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: var(--fs-13);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.textarea { height: auto; min-height: 72px; padding: var(--s-2) var(--s-3); line-height: var(--lh-body); resize: vertical; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 8l5 5 5-5' stroke='%236b7280' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; padding-right: 30px; }

.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong-color); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.input[disabled], .select[disabled], .textarea[disabled] {
  background: var(--surface-sunken);
  color: var(--text-subtle);
  cursor: not-allowed;
}

.input--search {
  padding-left: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Ccircle cx='9' cy='9' r='6' stroke='%239ca3af' stroke-width='1.75'/%3E%3Cpath d='M13.5 13.5 17 17' stroke='%239ca3af' stroke-width='1.75' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 8px center;
  background-size: 16px;
}

.field-row {
  display: flex;
  gap: var(--s-2);
  align-items: flex-end;
}

.checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ======== CARD / PANEL =================================== */

.card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-md);
  padding: var(--s-5);
}
.card--flat { border: var(--border); padding: var(--s-4); }
.card--sunken { background: var(--surface-sunken); border: var(--border); }
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding-bottom: var(--s-3);
  border-bottom: var(--border-subtle);
  margin-bottom: var(--s-4);
}
.card__title {
  font-size: var(--fs-14);
  font-weight: 600;
}

/* ======== BADGE / CHIP / STATUS ========================== */

.badge, .chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  height: 22px;
  padding: 0 var(--s-2);
  border-radius: var(--r-full);
  font-size: var(--fs-12);
  font-weight: 500;
  border: var(--border);
  background: var(--surface);
  color: var(--text-muted);
  white-space: nowrap;
  line-height: 1;
}
.badge--neutral { }
.badge--success { color: var(--success); border-color: rgba(22,163,74,0.25); background: var(--success-soft); }
.badge--warning { color: var(--warning); border-color: rgba(217,119,6,0.25); background: var(--warning-soft); }
.badge--danger { color: var(--danger); border-color: rgba(220,38,38,0.25); background: var(--danger-soft); }
.badge--accent { color: var(--accent); border-color: var(--accent-border); background: var(--accent-soft); }
.badge--solid {
  background: var(--gray-9);
  color: #fff;
  border-color: transparent;
}

.status-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: var(--r-full);
  background: var(--text-subtle);
}
.status-dot--success { background: var(--success); }
.status-dot--warning { background: var(--warning); }
.status-dot--danger { background: var(--danger); }
.status-dot--accent { background: var(--accent); }

/* ======== KPI TILE ======================================= */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}

.kpi-tile {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  text-decoration: none;
  color: inherit;
}
.kpi-tile:hover { border-color: var(--border-strong-color); background: var(--surface-hover); text-decoration: none; }
.kpi-tile.is-active { border-color: var(--accent); background: var(--accent-soft); }
.kpi-tile__label {
  color: var(--text-muted);
  font-size: var(--fs-12);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kpi-tile__value {
  color: var(--text);
  font-size: var(--fs-28);
  font-weight: 700;
  line-height: 1;
  margin: var(--s-1) 0;
  letter-spacing: -0.02em;
}
.kpi-tile__hint { color: var(--text-subtle); font-size: var(--fs-12); }

/* ======== TABLE ========================================== */

.table-wrap {
  border: var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-13);
}
.table thead th {
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: var(--fs-12);
  font-weight: 600;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--s-2) var(--s-3);
  border-bottom: var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.table tbody td {
  padding: var(--s-3);
  border-bottom: var(--border-subtle);
  color: var(--text);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr {
  transition: background var(--dur-fast) var(--ease);
}
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr.is-selected { background: var(--accent-soft); }
.table tbody tr.is-selected td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.table--dense tbody td { padding: var(--s-2) var(--s-3); }
.table__empty {
  padding: var(--s-8) var(--s-4);
  text-align: center;
  color: var(--text-muted);
}

.table-cell--right { text-align: right; }
.table-cell--nowrap { white-space: nowrap; }
.table-row-link {
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
}
.table-row-link:hover { color: var(--accent); text-decoration: none; }

/* ======== TOOLBAR ======================================== */

.toolbar {
  display: flex;
  align-items: flex-end;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-3);
}
.toolbar__filters { display: flex; gap: var(--s-3); flex-wrap: wrap; align-items: flex-end; }
.toolbar__spacer { flex: 1; }
.toolbar .input, .toolbar .select { height: 32px; font-size: var(--fs-13); }
.toolbar .input--search { min-width: 260px; }

.toolbar-field {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--fs-11);
  color: var(--text-muted);
  min-width: 0;
}
.toolbar-field > span {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  font-size: var(--fs-11);
}
.toolbar-field--search { flex: 1 1 260px; max-width: 420px; }
.toolbar-field--compact { min-width: 120px; }

/* ======== PAGINATION ===================================== */

.pagination {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-top: var(--border-subtle);
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--fs-13);
}
.pagination__info { flex: 1; }

/* ======== SEGMENTED CONTROL (status tabs) ================ */

.segmented {
  display: inline-flex;
  background: var(--surface-sunken);
  border: var(--border);
  border-radius: var(--r-md);
  padding: 2px;
  gap: 2px;
}
.segmented__option {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  height: 26px;
  padding: 0 var(--s-3);
  font-size: var(--fs-12);
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.segmented__option:hover { color: var(--text); }
.segmented__option.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--sh-1);
}
.segmented__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  padding: 0 5px;
  height: 18px;
  border-radius: var(--r-full);
  background: var(--surface-hover);
  color: var(--text-muted);
  font-size: var(--fs-11);
  font-weight: 600;
}
.segmented__option.is-active .segmented__count { background: var(--accent-soft); color: var(--accent); }

/* `.segmented--status` is the dashboard's primary KPI now (the top tile
   grid was removed). Bump it up a notch so the counts are scannable from
   across the room and clearly clickable. */
.segmented--status { padding: 4px; gap: 4px; }
.segmented--status .segmented__option {
  height: 38px;
  padding: 0 var(--s-4);
  font-size: var(--fs-13);
  font-weight: 600;
  gap: var(--s-3);
}
.segmented--status .segmented__count {
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  font-size: var(--fs-12);
  font-weight: 700;
}

/* ======== MODAL ========================================== */

.modal-scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-4);
  z-index: var(--z-modal);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease);
}
.modal-scrim.is-open { opacity: 1; pointer-events: auto; }

/* Scope v2 panel styles to direct children of .modal-scrim so bare
 * .modal (used by legacy report #defectModal et al. as a scrim) isn't
 * hijacked. */
.modal-scrim > .modal {
  width: min(560px, 100%);
  max-height: min(86vh, 720px);
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(8px);
  transition: transform var(--dur-base) var(--ease);
}
.modal-scrim.is-open > .modal { transform: translateY(0); }

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-4);
  border-bottom: var(--border-subtle);
}
.modal__title { font-size: var(--fs-16); font-weight: 600; }
.modal__body {
  padding: var(--s-4);
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-top: var(--border-subtle);
  background: var(--surface-sunken);
}

/* ======== DRAWER (right-side) ============================ */

.drawer-scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: var(--z-drawer);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease);
}
.drawer-scrim.is-open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(520px, 100%);
  background: var(--surface);
  border-left: var(--border);
  box-shadow: var(--sh-3);
  z-index: calc(var(--z-drawer) + 1);
  transform: translateX(100%);
  transition: transform var(--dur-base) var(--ease);
  display: flex;
  flex-direction: column;
}
.drawer.is-open { transform: translateX(0); }

/* ======== TOAST ========================================== */

.toast-wrap {
  position: fixed;
  bottom: var(--s-5);
  right: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  z-index: var(--z-toast);
  max-width: 360px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  color: var(--text);
  font-size: var(--fs-13);
  box-shadow: var(--sh-2);
  display: flex;
  gap: var(--s-2);
  pointer-events: auto;
  animation: toast-in var(--dur-base) var(--ease);
}
.toast--success { border-left: 3px solid var(--success); }
.toast--error { border-left: 3px solid var(--danger); }
.toast--info { border-left: 3px solid var(--accent); }
.toast--warning { border-left: 3px solid var(--warning); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ======== SKELETON ======================================= */

.skel {
  display: inline-block;
  height: 1em;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-sunken), var(--surface-hover), var(--surface-sunken));
  background-size: 200% 100%;
  animation: skel-shimmer 1.2s infinite linear;
  color: transparent;
  min-width: 60px;
}
.skel--sm { height: 12px; }
.skel--md { height: 16px; }
.skel--lg { height: 22px; }
.skel--block { display: block; }
@keyframes skel-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.kpi-tile.is-loading .kpi-tile__value,
.kpi-tile.is-loading .kpi-tile__hint {
  display: inline-block;
  background: linear-gradient(90deg, var(--surface-sunken), var(--surface-hover), var(--surface-sunken));
  background-size: 200% 100%;
  animation: skel-shimmer 1.2s infinite linear;
  color: transparent;
  border-radius: var(--r-sm);
}

/* ======== EMPTY STATE ==================================== */

.empty-state {
  padding: var(--s-10) var(--s-4);
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
}
.empty-state__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-full);
  background: var(--surface-sunken);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-subtle);
}
.empty-state__title { font-size: var(--fs-14); font-weight: 600; color: var(--text); }

/* ======== ALERT / BANNER ================================= */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  border: var(--border);
  background: var(--surface);
  font-size: var(--fs-13);
  color: var(--text);
}
.alert--error { border-color: rgba(220,38,38,0.25); background: var(--danger-soft); color: var(--danger); }
.alert--warning { border-color: rgba(217,119,6,0.25); background: var(--warning-soft); color: var(--warning); }
.alert--success { border-color: rgba(22,163,74,0.25); background: var(--success-soft); color: var(--success); }

/* ======== COMMAND PALETTE ================================ */

.palette-scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: var(--z-palette);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 96px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease);
}
.palette-scrim.is-open { opacity: 1; pointer-events: auto; }
.palette {
  width: min(560px, 100%);
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  overflow: hidden;
  transform: translateY(-6px);
  transition: transform var(--dur-base) var(--ease);
}
.palette-scrim.is-open .palette { transform: translateY(0); }
.palette__search {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-bottom: var(--border);
  color: var(--text-muted);
}
.palette__search input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-14);
  outline: none;
}
.palette__list {
  max-height: 360px;
  overflow-y: auto;
  padding: var(--s-2);
}
.palette__group { padding: var(--s-1) var(--s-2) var(--s-1); color: var(--text-subtle); font-size: var(--fs-11); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.palette__item {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-2);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: var(--fs-13);
  cursor: pointer;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  text-decoration: none;
}
.palette__item .shortcut {
  margin-left: auto;
  color: var(--text-subtle);
  font-size: var(--fs-11);
}
.palette__item.is-active, .palette__item:hover { background: var(--surface-hover); }
.palette__item.is-active { color: var(--text); }

/* ======== AUTH LAYOUT ==================================== */

.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s-6);
  background: var(--bg-subtle);
}
.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  padding: var(--s-6);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}
.auth-card__brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-weight: 700;
  font-size: var(--fs-16);
  color: var(--text);
  margin-bottom: var(--s-2);
}
.auth-card__title { font-size: var(--fs-18); font-weight: 600; }
.auth-card__subtitle { color: var(--text-muted); font-size: var(--fs-13); margin-top: 2px; }
.auth-card__actions { display: flex; flex-direction: column; gap: var(--s-2); }
.auth-card__footer {
  text-align: center;
  font-size: var(--fs-13);
  color: var(--text-muted);
  margin-top: var(--s-2);
}

/* ======== BULK ACTION BAR (sticky bottom) ================ */

.bulk-bar {
  position: fixed;
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: var(--border);
  box-shadow: 0 -8px 20px rgba(17, 24, 39, 0.08);
  padding: var(--s-3) var(--s-5);
  display: flex;
  align-items: center;
  gap: var(--s-4);
  flex-wrap: wrap;
  z-index: var(--z-sticky);
  animation: bulkbar-up var(--dur-base) var(--ease);
}
@keyframes bulkbar-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
[data-theme="dark"] .bulk-bar { box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.4); }
.bulk-bar[hidden] { display: none; }
.bulk-bar__count {
  display: inline-flex;
  align-items: baseline;
  gap: var(--s-1);
  font-size: var(--fs-13);
  color: var(--text-muted);
}
.bulk-bar__count strong {
  color: var(--text);
  font-size: var(--fs-16);
  font-weight: 700;
}
.bulk-bar__actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin-left: auto;
}
@media (max-width: 768px) {
  .bulk-bar { left: 0; }
}

/* ======== RESPONSIVE ===================================== */

@media (max-width: 1024px) {
  .app-content { padding: var(--s-4); }
  .app-topbar { padding: 0 var(--s-4); }
}

@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 80vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease);
  }
  .app-shell.sidebar-open .app-sidebar { transform: translateX(0); }
  .app-shell.sidebar-open::after {
    content: "";
    position: fixed; inset: 0;
    background: var(--scrim);
    z-index: calc(var(--z-sticky) - 1);
  }
  .app-topbar { padding: 0 var(--s-3); }
  .app-topbar__crumbs { font-size: var(--fs-12); }
  .topbar-search { min-width: 0; padding: 0 var(--s-2); }
  .topbar-search .sr-text { display: none; }
  .kpi-tile__value { font-size: var(--fs-22); }
}

@media (max-width: 520px) {
  .auth-card { padding: var(--s-4); }
  .page-header__actions { width: 100%; }
}

/* ======== UTILITY ======================================== */

.stack-2 { display: flex; flex-direction: column; gap: var(--s-2); }
.stack-3 { display: flex; flex-direction: column; gap: var(--s-3); }
.stack-4 { display: flex; flex-direction: column; gap: var(--s-4); }
.row-2 { display: flex; gap: var(--s-2); align-items: center; }
.row-3 { display: flex; gap: var(--s-3); align-items: center; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.text-right { text-align: right; }
.text-nowrap { white-space: nowrap; }
.hide { display: none !important; }
.flex-1 { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

/* ======== FORM LAYOUT ==================================== */
/* Systematic form primitives — replaces per-page inline style="" layout. */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-4) var(--s-4);
}
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field--span-2 { grid-column: span 2; }
.field--span-all { grid-column: 1 / -1; }
@media (max-width: 768px) {
  .form-grid, .form-grid--3 { grid-template-columns: 1fr; }
  .field--span-2 { grid-column: auto; }
}

.form-section { display: flex; flex-direction: column; gap: var(--s-4); }
.form-section + .form-section {
  margin-top: var(--s-6);
  padding-top: var(--s-5);
  border-top: var(--border-subtle);
}
.form-section__title {
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}
.form-section__desc { font-size: var(--fs-12); color: var(--text-muted); margin-top: -10px; }

.form-actions {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  align-items: center;
  padding-top: var(--s-4);
}
.form-actions--start { justify-content: flex-start; }
.form-actions .form-actions__note { margin-right: auto; font-size: var(--fs-12); color: var(--text-subtle); }

.field__label .req { color: var(--danger); margin-left: 2px; }
.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.14);
}
.field.has-error .field__hint { display: none; }
.field .field__error[data-when-error] { display: none; }
.field.has-error .field__error[data-when-error] { display: block; }

.input-affix { position: relative; display: flex; align-items: center; }
.input-affix .input { width: 100%; }
.input-affix__suffix {
  position: absolute;
  right: 10px;
  color: var(--text-subtle);
  font-size: var(--fs-12);
  pointer-events: none;
}
.input-affix--btn .input { padding-right: 34px; }
.input-affix__action {
  position: absolute;
  right: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border: 0; border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
}
.input-affix__action:hover { background: var(--surface-hover); color: var(--text); }

/* ======== CHARTS (rpCharts) ============================== */

.rp-chart { display: flex; flex-direction: column; gap: var(--s-2); min-width: 0; }
.rp-chart__stage { position: relative; min-width: 0; }
.rp-chart__stage svg { display: block; max-width: 100%; }

.rp-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  font-size: var(--fs-12);
  color: var(--text-muted);
}
.rp-chart-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.rp-chart-legend__swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.rp-chart-legend__line { width: 14px; height: 2.5px; border-radius: 2px; flex: none; }

.rp-chart-tip {
  position: absolute;
  z-index: var(--z-sticky);
  pointer-events: none;
  background: var(--surface-raised);
  border: var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-2);
  padding: var(--s-2) var(--s-3);
  font-size: var(--fs-12);
  color: var(--text-muted);
  min-width: 120px;
  max-width: 260px;
}
.rp-chart-tip__title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.rp-chart-tip__row { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.rp-chart-tip__key { width: 10px; height: 2.5px; border-radius: 2px; flex: none; }
.rp-chart-tip__value { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.rp-chart-tip__name { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chart-card { display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
/* display:flex above beats the UA [hidden] rule — restate it, or the
   insights persona switch (운영실무/투자자/지자체) can't hide these cards
   and their tables again after revealing them. Same guard for .kpi-tile. */
.chart-card[hidden],
.kpi-tile[hidden] { display: none; }
.chart-card__title { font-size: var(--fs-13); font-weight: 600; color: var(--text); }
.chart-card__subtitle { font-size: var(--fs-12); color: var(--text-muted); margin-top: -8px; }
.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-5);
}
@media (max-width: 1024px) { .chart-grid { grid-template-columns: 1fr; } }

.kpi-tile__delta { font-size: var(--fs-12); font-weight: 600; }
.kpi-tile__delta--up { color: var(--success); }
.kpi-tile__delta--down { color: var(--danger); }
.kpi-tile__spark { margin-top: var(--s-1); height: 32px; }

/* ======== AUDIT STATUS =================================== */

.audit-status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-12); font-weight: 500; }
.audit-status::before { content: ""; width: 8px; height: 8px; border-radius: 999px; background: var(--text-subtle); }
.audit-status--ok { color: var(--success); }
.audit-status--ok::before { background: var(--success); }
.audit-status--short { color: var(--danger); }
.audit-status--short::before { background: var(--danger); }
.audit-status--long { color: var(--warning); }
.audit-status--long::before { background: var(--warning); }
.audit-status--unlinked { color: var(--text-muted); }
.audit-status--no_length { color: var(--text-muted); }

/* key-value rows (runtime snapshots, meta panels) */
.kv-list { display: flex; flex-direction: column; gap: var(--s-3); }
.kv-row { display: flex; justify-content: space-between; gap: var(--s-3); align-items: baseline; }
.kv-row__key { color: var(--text-subtle); font-size: var(--fs-13); }
.kv-row__value { font-weight: 600; text-align: right; word-break: break-all; }

.split-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(240px, 1fr);
  gap: var(--s-5);
}
@media (max-width: 900px) { .split-2 { grid-template-columns: 1fr; } }
