/* ─── AppShell ──────────────────────────────────────────────────────────────
   Universal layout: TopBar (fixed top) + SideBar (fixed left) + content area
   ─────────────────────────────────────────────────────────────────────────── */

.app-shell {
  min-height: 100vh;
  background-color: var(--bg-app);
  font-family: var(--font-family);
  color: var(--text-primary);
}

/* Content area — offset by topbar height and sidebar width */
.app-shell__content {
  min-height: calc(100vh - var(--topbar-height, 50px));
  padding: var(--sp-4);
  box-sizing: border-box;
  /* margin-left and padding-top set dynamically by AppShell via style= */
  transition: margin-left var(--transition-std);
  /* width: auto fills only the remaining space after margin-left (sidebar width) */
  width: auto;
  overflow-x: hidden;
}

/* ─── TopBar ────────────────────────────────────────────────────────────────
   Fixed at top, full width, above sidebar
   ─────────────────────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height, 50px);
  background-color: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  box-shadow: var(--shadow-xs);
  z-index: var(--z-topbar, 1030);
  padding: 0 var(--sp-4);
  box-sizing: border-box;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.toolbar a,
.toolbar button {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  color: var(--topbar-text);
  text-decoration: none;
  background: none;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-md);
  font-weight: var(--fw-medium);
  transition: background-color var(--transition-fast);
}

.toolbar a:hover,
.toolbar button:hover {
  background-color: color-mix(in srgb, var(--topbar-text) 10%, transparent);
}

/* ─── SideBar ───────────────────────────────────────────────────────────────
   Fixed left, full height, collapsible
   ─────────────────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--topbar-height, 50px);
  left: 0;
  height: calc(100vh - var(--topbar-height, 50px));
  background-color: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: visible;
  overflow-y: auto;
  transition: width var(--transition-std);
  z-index: var(--z-sidebar, 1020);
  box-shadow: var(--shadow-sm);
  box-sizing: border-box;
}

.sidebar.closed  { width: 60px; }
.sidebar.opened  { width: 240px; }

/* Toggle button — fixed overlay, straddles sidebar right edge */
.toggle_sidebar {
  position: fixed;
  /* `left` is set inline by AppShell (sidebar_width - 12px) */
  top: calc(var(--topbar-height, 50px) + var(--sp-4));
  width: 24px;
  height: 24px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  z-index: calc(var(--z-topbar, 1030) + 1);
  box-shadow: var(--shadow-sm);
  transition: left var(--transition-std),
              background-color var(--transition-fast),
              color var(--transition-fast);
}

.toggle_sidebar:hover {
  background-color: var(--primary-light);
  color: var(--primary);
}

.toggle_sidebar .material-symbols-outlined { font-size: 16px; }

/* Resize handle */
.sidebar-resize-handle {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  -webkit-user-select: none;
}

.sidebar-resize-handle:hover { background-color: rgba(59,130,246,0.15); }

/* Nav items */
.sidebar_content {
  padding: var(--sp-4) 0;
  flex: 1;
}

.sidebar_item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: var(--text-md);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  border-radius: 0;
  background: none;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background-color var(--transition-fast), color var(--transition-fast);
  overflow: hidden;
}

.sidebar_item:hover {
  background-color: var(--sidebar-item-hover);
  color: var(--sidebar-text-active);
}

.sidebar_item.active {
  background-color: var(--sidebar-item-active);
  color: var(--sidebar-text-active);
  border-left: 3px solid var(--accent);
}

.sidebar_item .material-symbols-outlined { font-size: 20px; flex-shrink: 0; }
.sidebar_label { font-size: var(--text-md); }

/* Scrollbar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background-color: rgba(255,255,255,0.15); border-radius: 2px; }

/* ─── Form Actions bar ──────────────────────────────────────────────────────
   Contextual toolbar at the top of the edit form — same visual style as
   .list-toolbar (flat bar, full width, bg-card, bottom border).
   ─────────────────────────────────────────────────────────────────────────── */
.form_actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.form_actions_left,
.form_actions_right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* Same compact button size as list-toolbar */
.form_actions .btn {
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--text-sm);
  gap: var(--sp-1);
}
.form_actions .btn .material-symbols-outlined { font-size: 16px; }

.page_title {
  font-size: var(--text-lg);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ─── Form fields grid ──────────────────────────────────────────────────────
   Flex-wrap container; children use .col-N classes
   ─────────────────────────────────────────────────────────────────────────── */
.form-fields {
  display: flex;
  flex-wrap: wrap;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-xs);
  gap: 0;          /* gap via col- margin */
}

/* Column grid (base-12) */
[class*="col-"] {
  flex-grow: 1;
  min-width: 0;
  box-sizing: border-box;
  padding: var(--sp-2);
}

.col-12 { flex: 0 1 100%;        min-width: 100%; }
.col-11 { flex: 0 1 91.66%;      min-width: 200px; }
.col-10 { flex: 0 1 83.33%;      min-width: 200px; }
.col-9  { flex: 0 1 75%;         min-width: 180px; }
.col-8  { flex: 0 1 66.66%;      min-width: 160px; }
.col-7  { flex: 0 1 58.33%;      min-width: 140px; }
.col-6  { flex: 0 1 50%;         min-width: 140px; }
.col-5  { flex: 0 1 41.66%;      min-width: 120px; }
.col-4  { flex: 0 1 33.33%;      min-width: 120px; }
.col-3  { flex: 0 1 25%;         min-width: 100px; }
.col-2  { flex: 0 1 16.66%;      min-width: 80px; }
.col-1  { flex: 0 1 8.33%;       min-width: 60px; }

/* ─── Separator ─────────────────────────────────────────────────────────────*/
.dynamic-form__separator {
  width: 100%;
  flex: 0 1 100%;
  padding: var(--sp-2) var(--sp-2) 0;
  box-sizing: border-box;
}

.separator-line {
  display: flex;
  align-items: center;
  border-top: 2px solid var(--separator-color);
  padding-top: var(--sp-2);
  gap: var(--sp-2);
}

.separator-label {
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  color: var(--separator-color);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────*/
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  font-weight: var(--fw-medium);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
  line-height: 1.4;
  white-space: nowrap;
}

.btn .material-symbols-outlined { font-size: 18px; }

.btn-primary {
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border-color: var(--btn-primary-bg);
}
.btn-primary:hover { background-color: var(--btn-primary-hover); border-color: var(--btn-primary-hover); }

.btn-secondary {
  background-color: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border-color: var(--btn-secondary-border);
}
.btn-secondary:hover { background-color: var(--btn-secondary-hover); }

.btn-danger {
  background-color: var(--btn-danger-bg);
  color: var(--btn-danger-text);
  border-color: var(--btn-danger-bg);
}

/* ─── Dynamic form tabs ─────────────────────────────────────────────────────*/
.df-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--sp-4);
  overflow-x: auto;
}

.df-tab {
  padding: var(--sp-3) var(--sp-5);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: var(--text-md);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.df-tab:hover { color: var(--text-primary); }

.df-tab--active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: var(--fw-semibold);
}

/* ─── Dynamic form error ─────────────────────────────────────────────────── */
.dynamic-form { width: 100%; }

/* Padded content area below the actions bar — gives breathing room to tabs + fields */
.dynamic-form__content {
  padding: var(--sp-4) var(--sp-5) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.dynamic-form__error {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--error);
  padding: var(--sp-4);
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
}

/* ─── Misc utilities ─────────────────────────────────────────────────────── */
.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;
}

/* ─── List page ──────────────────────────────────────────────────────────── */
.list-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.list-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.toolbar__title {
  font-size: var(--text-lg);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  white-space: nowrap;
  flex-shrink: 0;
}

.toolbar__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  flex: 1;
  justify-content: flex-end;
}

/* Action buttons group — adds a subtle divider before the action buttons */
.toolbar__actions-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding-left: var(--sp-3);
  border-left: 1px solid var(--border);
}

/* Slightly smaller buttons in the list toolbar */
.list-toolbar .btn {
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--text-sm);
  gap: var(--sp-1);
}
.list-toolbar .btn .material-symbols-outlined { font-size: 16px; }

.list-table-container {
  flex: 1 1 0;
  overflow: auto;
  padding: var(--sp-4);
}

.list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.list-table thead {
  background-color: var(--table-header-bg);
  position: sticky;
  top: 0;
  z-index: 1;
}

.list-table th {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-weight: var(--fw-semibold);
  font-size: var(--text-xs);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--table-header-text);
  border-bottom: 1px solid var(--table-border);
}

.list-table td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.list-row {
  cursor: pointer;
  transition: background var(--transition-fast);
}

.list-row:hover td {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
}

.list-row:last-child td { border-bottom: none; }

/* Column alignment helpers */
.align-left   { text-align: left; }
.align-center { text-align: center; }
.align-right  { text-align: right; }

.list-footer {
  flex-shrink: 0;
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--text-xs);
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.list-empty {
  padding: var(--sp-8) var(--sp-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-md);
}

/* ─── Edit page ──────────────────────────────────────────────────────────── */
.edit-page {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.edit-not-found {
  padding: var(--sp-8);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-md);
}

.edit-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-8);
  color: var(--text-muted);
  font-size: var(--text-md);
}

.edit-loading__icon {
  font-size: 2rem;
  animation: spin 1.2s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ─── ChoiceField ────────────────────────────────────────────────────────────  */
.choice-field-wrapper { position: relative; display: flex; flex-direction: column; gap: var(--sp-1); }

.choice-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-3);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  /* Lock to same height as text inputs */
  height: 38px;
  min-height: 38px;
  box-sizing: border-box;
  gap: var(--sp-2);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  font-size: var(--text-sm);
  color: var(--text-primary);
}
.choice-trigger:hover:not(.choice-trigger--disabled) { border-color: var(--primary); }
.choice-trigger:focus-within { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.choice-trigger--disabled { background: var(--bg-app); opacity: 0.6; cursor: not-allowed; }
.choice-trigger--error { border-color: var(--error, #ef4444); }
.choice-trigger__chevron { font-size: 18px; color: var(--text-muted); flex-shrink: 0; }

.choice-placeholder { color: var(--text-muted); flex: 1; }

.choice-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
  border-radius: var(--radius-sm);
  padding: 2px var(--sp-2);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  flex: 1;
}
.choice-pill__clear {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  border-radius: var(--radius-sm);
}
.choice-pill__clear:hover { color: var(--error, #ef4444); background: color-mix(in srgb, var(--error, #ef4444) 10%, transparent); }

/* Backdrop (click-outside) */
.choice-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99;
}

/* Popup panel */
.choice-popup {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md, 0 4px 16px rgba(0,0,0,.12));
  overflow: hidden;
  min-width: 220px;
}

.choice-popup__search {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.choice-popup__search-icon { color: var(--text-muted); font-size: 18px; }
.choice-popup__input {
  flex: 1;
  border: none;
  outline: none;
  background: none;
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.choice-popup__list {
  list-style: none;
  margin: 0;
  padding: var(--sp-1) 0;
  max-height: 220px;
  overflow-y: auto;
}
.choice-popup__item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.choice-popup__item:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.choice-popup__item--selected { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: var(--fw-medium); }
.choice-popup__check { font-size: 16px; color: var(--primary); flex-shrink: 0; }
.choice-popup__check-placeholder { width: 16px; flex-shrink: 0; }
.choice-popup__empty { padding: var(--sp-3) var(--sp-4); color: var(--text-muted); font-size: var(--text-sm); }

/* Create new row */
.choice-popup__create {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--border);
}
.choice-popup__create-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--text-sm);
  background: var(--bg-app);
  color: var(--text-primary);
  outline: none;
}
.choice-popup__create-input:focus { border-color: var(--primary); }
.choice-popup__create-btn { padding: var(--sp-1) var(--sp-3); font-size: var(--text-sm); white-space: nowrap; }

/* ── AllowCreate modal ───────────────────────────────────────────────────── */
.choice-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 1200;
}
.choice-modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(95vw, 860px);
  max-height: 90vh;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  z-index: 1201;
  overflow: hidden;
}
.choice-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.choice-modal__title { font-size: var(--text-md); font-weight: var(--fw-semibold); }
.choice-modal__close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: var(--sp-1); border-radius: var(--radius-sm);
  display: flex; align-items: center;
}
.choice-modal__close:hover { background: var(--bg-app); color: var(--text-primary); }
.choice-modal__body {
  overflow-y: auto;
  flex: 1;
}
.choice-modal__loading {
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-8);
  color: var(--text-muted); font-size: 32px;
}
.choice-modal__error {
  padding: var(--sp-5);
  color: var(--danger);
  font-size: var(--text-sm);
}

/* ═══════════════════════════════════════════════════════════════════════════
   DASHBOARD
   Grid: 24 columns (matches Nexus YAML Element UI sizes).
     Size: 6  → span  6 → 4 cards/row
     Size: 8  → span  8 → 3 cards/row
     Size: 12 → span 12 → 2 cards/row
     Size: 24 → span 24 → full row
   Stat tiles use a .dash-cell wrapper for container-query scaling.
   KPI/List/Chart/Text widgets sit directly in the grid (col-N on root div).
   ═══════════════════════════════════════════════════════════════════════════ */

.dashboard-page { padding: var(--sp-4); }
.dash-header    { margin-bottom: var(--sp-4); }

/* ── Grid container ──────────────────────────────────────────────────────── */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  align-items: start;    /* rows size to tallest card, others don't stretch */
  gap: var(--sp-4);
}

/* Cancel the global form flex/padding rules on every direct grid child */
.dash-grid > [class*="col-"] {
  flex: none;
  min-width: 0;
  width: 100%;
  padding: 0;
  box-sizing: border-box;
}

/* Column spans (base-24) */
.dash-grid .col-1  { grid-column: span 1; }
.dash-grid .col-2  { grid-column: span 2; }
.dash-grid .col-3  { grid-column: span 3; }
.dash-grid .col-4  { grid-column: span 4; }
.dash-grid .col-5  { grid-column: span 5; }
.dash-grid .col-6  { grid-column: span 6; }
.dash-grid .col-7  { grid-column: span 7; }
.dash-grid .col-8  { grid-column: span 8; }
.dash-grid .col-9  { grid-column: span 9; }
.dash-grid .col-10 { grid-column: span 10; }
.dash-grid .col-11 { grid-column: span 11; }
.dash-grid .col-12 { grid-column: span 12; }
.dash-grid .col-13 { grid-column: span 13; }
.dash-grid .col-14 { grid-column: span 14; }
.dash-grid .col-15 { grid-column: span 15; }
.dash-grid .col-16 { grid-column: span 16; }
.dash-grid .col-17 { grid-column: span 17; }
.dash-grid .col-18 { grid-column: span 18; }
.dash-grid .col-19 { grid-column: span 19; }
.dash-grid .col-20 { grid-column: span 20; }
.dash-grid .col-21 { grid-column: span 21; }
.dash-grid .col-22 { grid-column: span 22; }
.dash-grid .col-23 { grid-column: span 23; }
.dash-grid .col-24 { grid-column: span 24; }

.dash-not-found {
  padding: var(--sp-8);
  color: var(--text-secondary);
  text-align: center;
}

/* ── Stat tile cell wrapper ───────────────────────────────────────────────
   Wraps the <a class="stat-widget"> and provides the container-query
   context so cqi units inside scale with actual card width.              */
.dash-cell {
  container-type: inline-size;
  container-name: dash-cell;
  display: flex;           /* makes stat-widget (flex:1) stretch to full height */
  flex-direction: column;
}

/* ── Generic widget card ─────────────────────────────────────────────────── */
.dash-widget {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.dash-widget__title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--sp-1);
}

/* ── KPI widget ──────────────────────────────────────────────────────────── */
.kpi-widget { flex-direction: row; align-items: center; gap: var(--sp-4); }
.kpi-widget__icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.kpi-widget__icon .material-symbols-outlined { font-size: 28px; }
.kpi-widget__body  { flex: 1; }
.kpi-widget__value { font-size: var(--text-2xl); font-weight: 700; color: var(--text-primary); line-height: 1; }
.kpi-widget__label { font-size: var(--text-sm); color: var(--text-secondary); margin-top: var(--sp-1); }

.kpi-widget--primary .kpi-widget__icon  { background: color-mix(in srgb, var(--primary) 15%, transparent);          color: var(--primary); }
.kpi-widget--primary .kpi-widget__value { color: var(--primary); }
.kpi-widget--success .kpi-widget__icon  { background: color-mix(in srgb, var(--success,#22c55e) 15%, transparent);   color: var(--success,#22c55e); }
.kpi-widget--success .kpi-widget__value { color: var(--success,#22c55e); }
.kpi-widget--warning .kpi-widget__icon  { background: color-mix(in srgb, var(--warning,#f59e0b) 15%, transparent);   color: var(--warning,#f59e0b); }
.kpi-widget--warning .kpi-widget__value { color: var(--warning,#f59e0b); }
.kpi-widget--info    .kpi-widget__icon  { background: color-mix(in srgb, var(--info,#3b82f6) 15%, transparent);      color: var(--info,#3b82f6); }
.kpi-widget--info    .kpi-widget__value { color: var(--info,#3b82f6); }
.kpi-widget--danger  .kpi-widget__icon  { background: color-mix(in srgb, var(--danger,#ef4444) 15%, transparent);    color: var(--danger,#ef4444); }
.kpi-widget--danger  .kpi-widget__value { color: var(--danger,#ef4444); }

/* ── List widget ─────────────────────────────────────────────────────────── */
.list-widget__table { width: 100%; border-collapse: collapse; }
.list-widget__row   { border-bottom: 1px solid var(--border); }
.list-widget__row:last-child { border-bottom: none; }
.list-widget__cell  { padding: var(--sp-2) var(--sp-1); font-size: var(--text-sm); color: var(--text-primary); }

/* ── Text widget ─────────────────────────────────────────────────────────── */
.text-widget__content { font-size: var(--text-sm); color: var(--text-secondary); line-height: 1.6; margin: 0; }

/* ── Chart widget ────────────────────────────────────────────────────────── */
.chart-widget__placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-2); padding: var(--sp-6);
  color: var(--text-secondary); font-size: var(--text-sm);
}
.chart-widget__placeholder .material-symbols-outlined { font-size: 48px; opacity: 0.3; }

/* ── Stat widget ─────────────────────────────────────────────────────────────
   Navigation shortcut card. Lives inside .dash-cell (container query context)
   so cqi units scale with the card width automatically.                      */
.stat-widget {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2cqi;
  padding: 3cqi 4cqi;
  flex: 1;             /* fills the .dash-cell height */
  min-height: 80px;    /* safeguard for very narrow viewports */
  border-radius: 12px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  background: var(--primary, #4f46e5);
  color: #fff;
  /* Reset button element defaults */
  border: none;
  font-family: inherit;
  width: 100%;
}
.stat-widget:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(0,0,0,.16);
  color: #fff;
  text-decoration: none;
}
.stat-widget__icon {
  width: 12cqi;
  height: 12cqi;
  border-radius: 50%;
  background: rgba(255,255,255,.20);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-widget__icon .material-symbols-outlined { font-size: 7cqi; color: #fff; }
.stat-widget__title {
  text-align: center;
  font-size: clamp(0.65rem, 3cqi, 1rem);
  font-weight: 700;
  line-height: 1.3;
  color: #fff;
}
.stat-widget__sub {
  text-align: center;
  font-size: clamp(0.55rem, 2.2cqi, 0.82rem);
  line-height: 1.3;
  color: rgba(255,255,255,.78);
}
@container dash-cell (max-width: 100px) {
  .stat-widget__sub  { display: none; }
  .stat-widget__icon { display: none; }
}

/* Colour palette (cycles every 6 tiles) */
.dash-grid .dash-cell:nth-child(6n+1) .stat-widget { background: var(--primary, #4f46e5); }
.dash-grid .dash-cell:nth-child(6n+2) .stat-widget { background: #16a34a; }
.dash-grid .dash-cell:nth-child(6n+3) .stat-widget { background: #d97706; }
.dash-grid .dash-cell:nth-child(6n+4) .stat-widget { background: #7c3aed; }
.dash-grid .dash-cell:nth-child(6n+5) .stat-widget { background: #0891b2; }
.dash-grid .dash-cell:nth-child(6n+6) .stat-widget { background: #dc2626; }

/* ── Responsive ───────────────────────────────────────────────────────────────
   Tablet (≤900px): switch to 12-col grid, map common YAML sizes.
   Mobile (≤540px): single column, 1 card per row.                           */
@media (max-width: 900px) {
  .dash-grid { grid-template-columns: repeat(12, 1fr); }
  /* Specific mappings first (higher priority) */
  .dash-grid .col-6  { grid-column: span 6; }   /* 2/row */
  .dash-grid .col-8  { grid-column: span 6; }   /* 2/row */
  .dash-grid .col-12 { grid-column: span 12; }  /* full */
  .dash-grid .col-24 { grid-column: span 12; }  /* full */
  /* Everything else: 3 per row */
  .dash-grid > [class*="col-"] { grid-column: span 4; }
  /* Re-apply the specific ones after the generic (cascade order matters) */
  .dash-grid .col-6  { grid-column: span 6; }
  .dash-grid .col-8  { grid-column: span 6; }
  .dash-grid .col-12 { grid-column: span 12; }
  .dash-grid .col-24 { grid-column: span 12; }
}
@media (max-width: 540px) {
  .dash-grid {
    grid-template-columns: 1fr;
    gap: var(--sp-3);
  }
  .dash-grid > [class*="col-"] { grid-column: span 1; }
}

/* ── List search ─────────────────────────────────────────────────────────────── */
.list-search {
  position: relative;
  display: flex;
  align-items: center;
}
.list-search__icon {
  position: absolute;
  left: var(--sp-2);
  font-size: 18px;
  color: var(--text-secondary);
  pointer-events: none;
}
.list-search__input {
  padding: var(--sp-1) var(--sp-8) var(--sp-1) var(--sp-8);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: var(--text-sm);
  width: 220px;
  outline: none;
  transition: border-color 0.15s;
}
.list-search__input:focus { border-color: var(--primary); }
.list-search__clear {
  position: absolute;
  right: var(--sp-2);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 16px;
  padding: 0;
  line-height: 1;
}
.list-search__clear:hover { color: var(--text-primary); }

/* ── List footer / pagination ─────────────────────────────────────────────────── */
.list-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}
.list-pagination { display: flex; align-items: center; gap: var(--sp-2); }
.list-pagination__info { font-size: var(--text-sm); color: var(--text-secondary); }
.btn-sm { padding: var(--sp-1) var(--sp-2); font-size: var(--text-sm); }
.list-empty-cell { text-align: center; padding: var(--sp-6); color: var(--text-secondary); }

/* ── List filter bar ──────────────────────────────────────────────────────────── */
.list-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: color-mix(in srgb, var(--primary) 4%, var(--bg-card));
  border-bottom: 1px solid var(--border);
}
.list-filter__item {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-width: 140px;
}
.list-filter__label {
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.list-filter__input,
.list-filter__select {
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: var(--text-sm);
  outline: none;
  min-width: 140px;
  transition: border-color 0.15s;
}
.list-filter__input:focus,
.list-filter__select:focus { border-color: var(--primary); }
.list-filter__select { cursor: pointer; }
.list-filter__clear { align-self: flex-end; white-space: nowrap; }

@media (max-width: 768px) {
  .list-filter-bar { gap: var(--sp-2); }
  .list-filter__item { min-width: 100%; }
  .list-filter__input,
  .list-filter__select { width: 100%; }
}

/* ── FastFilter chips bar ─────────────────────────────────────────────────────── */
.fast-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.fast-filter__chip {
  display: inline-flex;
  align-items: center;
  padding: var(--sp-1) var(--sp-3);
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--bg-base, #f9fafb);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium, 500);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.fast-filter__chip:hover {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  border-color: var(--primary);
  color: var(--primary);
}
.fast-filter__chip--active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.fast-filter__chip--active:hover {
  background: color-mix(in srgb, var(--primary) 85%, black);
  color: #fff;
}

/* ── Form validation banner ───────────────────────────────────────────────────── */
.form-validation-banner {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: var(--sp-2) 0;
  padding: var(--sp-2) var(--sp-4);
  background: color-mix(in srgb, var(--danger, #ef4444) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger, #ef4444) 35%, transparent);
  border-radius: var(--radius-md);
  color: var(--danger, #ef4444);
  font-size: var(--text-sm);
}
.form-validation-banner .material-symbols-outlined { font-size: 18px; flex-shrink: 0; }
.btn--disabled { opacity: 0.55; }

/* ── TopBar: logo + new action buttons ─────────────────────────────────────── */
.toolbar-logo {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--topbar-text);
  text-decoration: none;
  font-weight: var(--fw-semibold);
  font-size: var(--text-md);
}
.toolbar-logo .material-symbols-outlined { font-size: 22px; }
.toolbar-logo__name { font-weight: 700; letter-spacing: 0.02em; }

/* Toolbar action buttons */
.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-2);
  background: none;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--topbar-text);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  transition: background var(--transition-fast);
  white-space: nowrap;
}
.toolbar-btn:hover { background: color-mix(in srgb, var(--topbar-text) 10%, transparent); }
.toolbar-btn__label { font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.05em; }
.toolbar-btn--lang { min-width: 52px; }
.toolbar-btn--avatar .material-symbols-outlined { font-size: 26px; }

/* ── Responsiveness ─────────────────────────────────────────────────────────── */

/* ─── Mobile: sidebar becomes overlay ──────────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar overlay mode */
  .sidebar {
    position: fixed;
    left: 0;
    z-index: var(--z-sidebar, 1020);
    transform: translateX(0);
    transition: transform var(--transition-std), width var(--transition-std);
  }
  .sidebar.closed {
    transform: translateX(-100%);
    width: 240px; /* keep width so opening slides in correctly */
  }
  .sidebar.opened {
    transform: translateX(0);
    width: 240px;
    box-shadow: 4px 0 24px rgba(0,0,0,0.18);
  }

  /* Content area fills full width on mobile */
  .app-shell__content {
    margin-left: 0 !important;
  }

  /* Sidebar overlay backdrop — injected via ::before on app-shell when sidebar opened */
  .app-shell:has(.sidebar.opened)::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: calc(var(--z-sidebar, 1020) - 1);
  }

  /* Toolbar logo name hidden on very small screens */
  .toolbar-logo__name { display: none; }

  /* Hide language label on small screens */
  .toolbar-btn--lang .toolbar-btn__label { display: none; }
}

/* ─── Tablet adjustments ────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  /* Form grid: columns wider than half collapse to full row */
  .col-8, .col-9, .col-10, .col-11, .col-12 {
    grid-column: span 12;
  }
}

/* ─── Form: responsive grid ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* All form columns go full width */
  [class^="col-"], [class*=" col-"] {
    grid-column: span 12 !important;
  }

  /* Form grid itself */
  .dynamic-form__fields {
    grid-template-columns: 1fr;
  }

  /* Form actions stack */
  .form_actions {
    flex-wrap: wrap;
    gap: var(--sp-2);
  }
  .form_actions_right {
    flex-wrap: wrap;
    gap: var(--sp-2);
  }

  /* Tabs scroll horizontally */
  .dynamic-form__tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding-bottom: var(--sp-1);
  }
}

/* ─── List page: responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* List toolbar stacks vertically on mobile */
  .list-toolbar {
    flex-wrap: wrap;
    padding: var(--sp-2) var(--sp-3);
    gap: var(--sp-2);
  }
  .toolbar__title { width: 100%; }
  .toolbar__actions {
    width: 100%;
    flex-wrap: wrap;
    gap: var(--sp-2);
    justify-content: flex-start;
  }
  .toolbar__actions-inner {
    padding-left: 0;
    border-left: none;
    flex-wrap: wrap;
    gap: var(--sp-2);
  }
  /* Search input full width */
  .list-search { width: 100%; }
  .list-search__input { width: 100%; }

  /* Table horizontal scroll */
  .list-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .list-table {
    min-width: 480px;
  }

  /* Pagination footer stacks */
  .list-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-2);
  }
}

/* ─── Dashboard: responsive grid ────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .dash-grid {
    grid-template-columns: repeat(6, 1fr);
  }
  .col-3 { grid-column: span 3; }
  .col-4 { grid-column: span 3; }
  .col-6 { grid-column: span 6; }
  .col-8, .col-9, .col-10, .col-11, .col-12 { grid-column: span 6; }
}

@media (max-width: 768px) {
  .dash-grid {
    grid-template-columns: 1fr 1fr;
  }
  .dash-widget,
  .kpi-widget { grid-column: span 1; }
  /* Wide widgets (col-8+) always full width */
  .col-8, .col-9, .col-10, .col-11, .col-12 { grid-column: span 2; }
  .col-6 { grid-column: span 2; }
}

@media (max-width: 480px) {
  .dash-grid { grid-template-columns: 1fr; }
  .dash-widget { grid-column: span 1 !important; }
}

/* ─── Choice popup: full-width on mobile ────────────────────────────────────── */
@media (max-width: 480px) {
  .choice-popup {
    position: fixed;
    left: var(--sp-4);
    right: var(--sp-4);
    top: auto;
    bottom: var(--sp-4);
    z-index: 200;
  }
  .choice-popup__list { max-height: 45vh; }
}

/* ─── Page title: responsive ────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .page_title { font-size: var(--text-md); }
  .toolbar-logo__name { display: none; }
}

/* ── Online / Offline indicator ─────────────────────────────────────────────── */
.online-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-full, 999px);
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  background: color-mix(in srgb, var(--topbar-text) 8%, transparent);
  color: var(--topbar-text);
  user-select: none;
  transition: background-color var(--transition-fast);
}

.online-indicator__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  animation: pulse-dot 2.5s ease-in-out infinite;
}

.online-indicator__dot--online  { background-color: #22c55e; }
.online-indicator__dot--offline {
  background-color: #f97316;
  animation: none;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.online-indicator__label { line-height: 1; }

@media (max-width: 640px) {
  .online-indicator__label { display: none; }
}

/* ── Toolbar: user chip + logout ────────────────────────────────────────────── */
.toolbar-user {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-md);
  color: var(--topbar-text);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  background: color-mix(in srgb, var(--topbar-text) 8%, transparent);
  max-width: 160px;
  overflow: hidden;
}
.toolbar-user__icon { font-size: 20px; flex-shrink: 0; }
.toolbar-user__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toolbar-btn--logout:hover { color: var(--danger, #ef4444); }

@media (max-width: 640px) {
  .toolbar-user__name { display: none; }
}

/* ── Login page ──────────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-app);
  background-image: radial-gradient(circle at 20% 30%, color-mix(in srgb, var(--primary) 8%, transparent) 0%, transparent 50%),
                    radial-gradient(circle at 80% 70%, color-mix(in srgb, var(--primary) 5%, transparent) 0%, transparent 50%);
  padding: var(--sp-4);
  box-sizing: border-box;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  box-shadow: var(--shadow-md);
  padding: var(--sp-8) var(--sp-8);
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--primary);
  font-weight: 800;
  font-size: var(--text-xl);
  margin-bottom: var(--sp-2);
}
.login-logo .material-symbols-outlined { font-size: 32px; }
.login-logo__name { letter-spacing: 0.03em; }

.login-title {
  font-size: var(--text-xl);
  font-weight: var(--fw-bold, 700);
  color: var(--text-primary);
  margin: 0;
}
.login-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 0;
}

.login-error {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: color-mix(in srgb, var(--danger, #ef4444) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger, #ef4444) 30%, transparent);
  border-radius: var(--radius-md);
  color: var(--danger, #ef4444);
  font-size: var(--text-sm);
}
.login-error .material-symbols-outlined { font-size: 18px; }

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.login-field__label {
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
}
.login-field__input {
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.login-field__input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.login-btn {
  width: 100%;
  justify-content: center;
  margin-top: var(--sp-1);
  padding: var(--sp-2) var(--sp-4);
}

.login-dev-hint {
  border-top: 1px solid var(--border);
  padding-top: var(--sp-3);
  display: flex;
  justify-content: center;
}
.login-dev-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.login-dev-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.login-dev-btn .material-symbols-outlined { font-size: 15px; }

/* auth-container wrapper from main.rs */
.auth-container {
  min-height: 100vh;
  background: var(--bg-app);
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════════════════════════════════ */

.toast-container {
  position: fixed;
  bottom: var(--sp-5);
  right: var(--sp-5);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
  max-width: 360px;
  width: calc(100vw - var(--sp-5) * 2);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  font-size: var(--text-sm);
  font-weight: 500;
  pointer-events: all;
  animation: toast-in 0.25s ease;
  color: #fff;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(.96); }
  to   { opacity: 1; transform: none; }
}

.toast--success { background: var(--success, #22c55e); }
.toast--error   { background: var(--danger,  #ef4444); }
.toast--info    { background: var(--primary, #6366f1); }
.toast--warning { background: var(--warning, #f59e0b); }

.toast__icon { font-size: 20px; flex-shrink: 0; }
.toast__message { flex: 1; line-height: 1.4; }
.toast__close {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,.8); padding: 0;
  display: flex; align-items: center;
  transition: color var(--transition-fast);
}
.toast__close:hover { color: #fff; }
.toast__close .material-symbols-outlined { font-size: 18px; }

@media (max-width: 480px) {
  .toast-container {
    bottom: var(--sp-3);
    right: var(--sp-3);
    left: var(--sp-3);
    width: auto;
    max-width: none;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   CONFIRM MODAL
   ═══════════════════════════════════════════════════════════════════════════ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  animation: fade-in .15s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1001;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(0,0,0,.25);
  width: min(440px, calc(100vw - 32px));
  animation: modal-in .2s cubic-bezier(.34,1.56,.64,1);
  overflow: hidden;
}

@keyframes modal-in {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 12px)) scale(.96); }
  to   { opacity: 1; transform: translate(-50%,-50%) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}
.modal-header__icon {
  font-size: 22px;
  color: var(--primary);
}
.modal-header__title {
  flex: 1;
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-primary);
}
.modal-header__close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); display: flex; align-items: center;
  padding: var(--sp-1); border-radius: var(--radius-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.modal-header__close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-body {
  padding: var(--sp-5);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.6;
}
.modal-body p { margin: 0; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

/* action button wrapper */
.action-with-confirm { display: inline-flex; }

@media (max-width: 480px) {
  .modal-footer {
    flex-direction: column-reverse;
  }
  .modal-footer .btn { width: 100%; justify-content: center; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   SORTABLE TABLE HEADERS
   ═══════════════════════════════════════════════════════════════════════════ */

.sortable-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.sortable-th:hover { background: var(--bg-hover); }

.sort-icon {
  font-size: 14px;
  vertical-align: middle;
  margin-left: 4px;
  color: var(--text-muted);
  opacity: .4;
  transition: opacity var(--transition-fast), color var(--transition-fast);
}
.sort-icon--active {
  opacity: 1;
  color: var(--primary);
}
.sortable-th:hover .sort-icon { opacity: .7; }



/* ═══════════════════════════════════════════════════════════════════════════
                                                                 HOME PAGE
   ═══════════════════════════════════════════════════════════════════════════ */
.home-page {
  padding: var(--sp-6) var(--sp-8);
  max-width: 900px;
}
.home-hero {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-2);
  margin-bottom: var(--sp-8);
}
.home-hero__icon {
  font-size: 48px;
  color: var(--primary);
  margin-bottom: var(--sp-1);
}
.home-hero__title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}
.home-hero__sub {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 0;
}

/* Quick-access tiles grid */
.home-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--sp-4);
}
.home-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-5) var(--sp-3);
  border-radius: var(--radius-md);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--text-sm);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  border: 2px solid transparent;
}
.home-tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
.home-tile__icon {
  font-size: 32px;
}
.home-tile__label {
  text-align: center;
  line-height: 1.3;
}
/* Colour variants */
.home-tile--blue   { background: color-mix(in srgb, var(--primary) 12%, var(--bg-surface)); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }
.home-tile--green  { background: color-mix(in srgb, var(--success) 12%, var(--bg-surface)); color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.home-tile--orange { background: color-mix(in srgb, var(--warning) 12%, var(--bg-surface)); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.home-tile--purple { background: color-mix(in srgb, #9b59b6 12%, var(--bg-surface)); color: #9b59b6; border-color: color-mix(in srgb, #9b59b6 30%, transparent); }
.home-tile--teal   { background: color-mix(in srgb, #17a2b8 12%, var(--bg-surface)); color: #17a2b8; border-color: color-mix(in srgb, #17a2b8 30%, transparent); }

@media (max-width: 600px) {
  .home-page { padding: var(--sp-4); }
  .home-tiles { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--sp-3); }
  .home-tile { padding: var(--sp-4) var(--sp-2); }
  .home-tile__icon { font-size: 26px; }
}

/* ═══════════════════════════════════════════════════════════════════════════
                                              DASHBOARD WIDGET IMPROVEMENTS
   ═══════════════════════════════════════════════════════════════════════════ */
.dash-widget__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}
.dash-widget__link {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  text-decoration: none;
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}
.dash-widget__link:hover { color: var(--primary); background: var(--bg-hover); }
.dash-widget__link .material-symbols-outlined { font-size: 16px; }

/* List widget table header */
.list-widget__th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  padding: var(--sp-1) var(--sp-2) var(--sp-2);
  border-bottom: 1px solid var(--border);
}


/* ---------------------------------------------------------------------------
   EDIT PAGE BREADCRUMB
   --------------------------------------------------------------------------- */

.edit-breadcrumb {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  margin-bottom: var(--sp-1);
}
.edit-breadcrumb__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.edit-breadcrumb__back {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}
.edit-breadcrumb__back:hover {
  color: var(--primary);
  background: var(--bg-hover);
}
.edit-breadcrumb__back .material-symbols-outlined {
  font-size: 18px;
}


/* ---------------------------------------------------------------------------
   404 NOT FOUND PAGE
   --------------------------------------------------------------------------- */

.not-found-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-app);
  padding: var(--sp-6);
}
.not-found-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  text-align: center;
  max-width: 420px;
}
.not-found-icon {
  font-size: 72px;
  color: var(--text-muted);
  opacity: .4;
}
.not-found-code {
  font-size: 80px;
  font-weight: 800;
  color: var(--primary);
  margin: 0;
  line-height: 1;
}
.not-found-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}
.not-found-msg {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: 0;
  line-height: 1.6;
}
.not-found-actions { margin-top: var(--sp-2); }

/* -- Inline List (Type: List EditMode: InLine) ----------------------------- */
.inline-list {
  padding: var(--sp-2) var(--sp-3) var(--sp-4);
}
.inline-list__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-3) var(--sp-3);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin-bottom: 0;
}
.inline-list__title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.inline-list__add {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
}
.inline-list__table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}
.inline-list__table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.inline-list__th {
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  white-space: nowrap;
}
.inline-list__th--del {
  width: 36px;
}
.inline-list__row:hover {
  background: var(--hover-bg);
}
.inline-list__td {
  padding: var(--sp-1) var(--sp-3);
  vertical-align: middle;
  border-bottom: 1px solid var(--border-light, color-mix(in srgb, var(--border) 50%, transparent));
}
.inline-list__td--del {
  width: 36px;
  text-align: center;
}
/* Compact inputs inside inline table cells */
.inline-list__td .field-wrapper,
.inline-list__td .field-group {
  margin: 0;
  padding: 0;
}
.inline-list__td .field-label {
  display: none; /* labels hidden inside cells � header row provides context */
}
.inline-list__td input,
.inline-list__td select,
.inline-list__td textarea {
  padding: 4px 8px;
  font-size: var(--text-sm);
  min-height: 30px;
}
.inline-list__del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
}
.inline-list__del-btn:hover {
  color: var(--danger, #dc3545);
  background: color-mix(in srgb, var(--danger, #dc3545) 10%, transparent);
}
.inline-list__del-btn .material-symbols-outlined {
  font-size: 18px;
}

.inline-list__notice {
  font-size: 0.85rem;
  color: var(--color-text-muted, #888);
  font-style: italic;
  padding: 0.25rem 0.5rem;
}

/* ── List table: Actions column ──────────────────────────────────────────── */
/* width:1% + white-space:nowrap = browser shrinks column to fit content     */
.list-th-actions,
.list-td-actions {
  width: 1%;
  white-space: nowrap;
  text-align: center;
  padding: 0 var(--sp-2);
}
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--border-radius-sm, 4px);
  background: transparent;
  cursor: pointer;
  color: var(--text-secondary, #666);
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover {
  background: var(--primary-light, #dbeafe);
  color: var(--primary-color, #3b82f6);
}
.btn-icon .material-symbols-outlined {
  font-size: 18px;
  line-height: 1;
}

/* ── List row cursor ─────────────────────────────────────────────────────── */
.list-row {
  cursor: pointer;
}

/* ── Print styles ────────────────────────────────────────────────────────── */
@media print {
  /* Hide shell chrome */
  .sidebar,
  .topbar,
  .navbar,
  .nav-sidebar,
  .list-toolbar .toolbar__actions,
  .edit-breadcrumb,
  .edit-delete-btn,
  .edit-print-btn,
  .toast-container,
  .modal-overlay,
  .confirm-modal {
    display: none !important;
  }

  /* Remove padding/shadows from layout containers */
  body, html {
    background: white !important;
    margin: 0;
    padding: 0;
  }

  .app-shell,
  .main-content,
  .page-content,
  .content-area {
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    background: white !important;
  }

  /* Form fields — plain text-like appearance */
  .field-input,
  .field-select,
  .field-textarea {
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    background: white !important;
  }

  /* Inline list table */
  .inline-list__table {
    width: 100%;
    border-collapse: collapse;
  }
  .inline-list__th,
  .inline-list__td {
    border: 1px solid #ccc !important;
  }
  .inline-list__add,
  .inline-list__del-btn,
  .inline-list__th--del,
  .inline-list__td--del {
    display: none !important;
  }

  /* Page break control */
  .form-section,
  .card {
    page-break-inside: avoid;
  }
}
