/* ==========================================================================
   Vopreki Studio Control Center — Swiss Telemetry UI
   Adaptive across: Fold Cover (<=400px), Phone (<=679px),
   Galaxy Z Fold Unfolded Master-Detail (680px..1120px), Desktop (1121px+)
   ========================================================================== */

:root {
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --surface-hover: #F1F5F9;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --text: #0F172A;
  --text-2: #475569;
  --text-3: #64748B;
  --accent: #1D4ED8;
  --accent-hover: #1E40AF;
  --accent-soft: #EFF6FF;
  --accent-border: #BFDBFE;
  --ok: #059669;
  --ok-soft: #ECFDF5;
  --warn: #D97706;
  --warn-soft: #FFFBEB;
  --danger: #DC2626;
  --danger-soft: #FEF2F2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --sidebar-w: 236px;
  --topbar-h: 64px;
  --bottom-nav-h: 64px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Roboto', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0B0F15;
  --surface: #121821;
  --surface-2: #17202C;
  --surface-hover: #1D2837;
  --border: #243041;
  --border-strong: #33435B;
  --text: #F1F5F9;
  --text-2: #94A3B8;
  --text-3: #64748B;
  --accent: #4C82FB;
  --accent-hover: #6B99FF;
  --accent-soft: rgba(76, 130, 251, 0.14);
  --accent-border: rgba(76, 130, 251, 0.35);
  --ok: #34D399;
  --ok-soft: rgba(52, 211, 153, 0.14);
  --warn: #FBBF24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --danger: #F87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.5);
}

*, *::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: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100%;
}

.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.muted { color: var(--text-2); }
.danger-text { color: var(--danger) !important; }
.ok-text { color: var(--ok) !important; }
.warn-text { color: var(--warn) !important; }

/* --------------------------------------------------------------------------
   Login View
   -------------------------------------------------------------------------- */
.login-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--accent);
  color: #FFFFFF;
  font-weight: 800;
  font-size: 20px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}

.login-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-sub {
  margin: 2px 0 0;
  color: var(--text-2);
  font-size: 13px;
}

.login-meta {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-3);
}

/* --------------------------------------------------------------------------
   App Shell & Navigation
   -------------------------------------------------------------------------- */
.app-shell {
  display: flex;
  min-height: 100dvh;
  width: 100%;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
  padding: 16px 12px;
  z-index: 20;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.brand-name {
  display: block;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}

.brand-caption {
  display: block;
  font-size: 12px;
  color: var(--text-3);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item, .icon-btn-labeled {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 44px;
  padding: 0 11px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.nav-item:hover, .icon-btn-labeled:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-border);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-icon svg { width: 19px; height: 19px; }

.badge-pill {
  margin-left: auto;
  background: var(--danger);
  color: #FFF;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 24px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mobile-brand-dot {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: #FFF;
  font-weight: 800;
  font-size: 15px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.page-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-subtitle {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mobile-only { display: none; }

.content-root {
  padding: 20px 24px 32px;
  max-width: 1420px;
  width: 100%;
  margin: 0 auto;
}

/* --------------------------------------------------------------------------
   Controls, Buttons, Inputs, Badges
   -------------------------------------------------------------------------- */
.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.08s ease;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger {
  background: var(--danger-soft);
  border-color: rgba(220, 38, 38, 0.35);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #FFFFFF; }

.btn-ok {
  background: var(--ok-soft);
  border-color: rgba(5, 150, 105, 0.35);
  color: var(--ok);
}
.btn-ok:hover { background: var(--ok); color: #FFFFFF; }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-sm { min-height: 34px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn-lg { min-height: 46px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { width: 40px; padding: 0; }
.btn-icon svg { width: 17px; height: 17px; }

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: end; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 11.5px; color: var(--text-3); }

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-width: 0;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  font: inherit;
  font-size: 14px;
  padding: 9px 12px;
  min-height: 42px;
  outline: none;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

textarea {
  min-height: 112px;
  resize: vertical;
  line-height: 1.5;
}

textarea.code-area {
  font-family: var(--font-mono);
  font-size: 12.5px;
  min-height: 150px;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.toggle-row-title { font-weight: 600; font-size: 13.5px; }
.toggle-row-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.16s ease;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: #FFF;
  border-radius: 50%;
  transition: transform 0.16s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch.danger input:checked + .switch-slider { background: var(--danger); }

.chip-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  cursor: pointer;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFF;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.tag.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.inline-alert {
  padding: 10px 13px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
}
.inline-alert.error { background: var(--danger-soft); color: var(--danger); }
.inline-alert.ok { background: var(--ok-soft); color: var(--ok); }
.inline-alert.info { background: var(--accent-soft); color: var(--accent); }

/* --------------------------------------------------------------------------
   Cards, KPI Grid, Charts & Tables
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-2);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.kpi-label {
  font-size: 12.5px;
  color: var(--text-2);
  font-weight: 500;
}

.kpi-value {
  margin-top: 6px;
  font-size: 24px;
  font-weight: 750;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.kpi-foot {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.section-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chart-wrap {
  width: 100%;
  overflow: hidden;
}

.chart-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--text-2);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.apps-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.app-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.app-card-name {
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-card-pkg {
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 2px;
  word-break: break-all;
}

.app-metrics-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.mini-stat-label { font-size: 11px; color: var(--text-3); }
.mini-stat-val { font-size: 14px; font-weight: 700; margin-top: 2px; }

.progress-track {
  width: 100%;
  height: 6px;
  background: var(--surface-hover);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 5px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-fill.warn { background: var(--warn); }
.progress-fill.danger { background: var(--danger); }

.app-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   Master-Detail Layout (Built specifically for Galaxy Z Fold + Desktop)
   -------------------------------------------------------------------------- */
.master-detail {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.master-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.master-head {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.master-list {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 230px);
  overflow-y: auto;
}

.list-row {
  appearance: none;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  padding: 13px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  transition: background 0.12s ease;
}

.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface-hover); }
.list-row.active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.list-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.list-row-title {
  font-weight: 650;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-row-sub {
  font-size: 12px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.mobile-back-btn { display: none; margin-bottom: 12px; }

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--border);
}

.action-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-3);
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table tr:last-child td { border-bottom: none; }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.two-col-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.feedback-card {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 11px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--text-2);
}

/* --------------------------------------------------------------------------
   Bottom Navigation, Sheets, Modals & Toasts
   -------------------------------------------------------------------------- */
.bottom-nav { display: none; }

.sheet-backdrop, .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.sheet-backdrop {
  align-items: flex-end;
  padding: 0;
}

.bottom-sheet {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 12px 16px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-md);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  margin: 0 auto 12px;
}

.sheet-title { margin: 0 0 10px; font-size: 16px; font-weight: 700; }

.sheet-list { display: flex; flex-direction: column; gap: 6px; }

.sheet-row {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 11px;
  cursor: pointer;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-title { margin: 0; font-size: 16px; font-weight: 700; }
.modal-body { padding: 18px; }

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}

.toast {
  background: var(--text);
  color: var(--surface);
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
}
.toast.ok { background: var(--ok); color: #FFF; }
.toast.error { background: var(--danger); color: #FFF; }

/* ==========================================================================
   RESPONSIVE BREAKPOINT 1: Samsung Galaxy Z Fold Unfolded / Tablet
   (680px .. 1120px) — Compact Icon Rail + Native Dual-Pane Master-Detail
   ========================================================================== */
@media (max-width: 1120px) and (min-width: 680px) {
  .sidebar {
    width: 72px;
    padding: 14px 10px;
    align-items: center;
  }
  .sidebar-head {
    padding: 4px 0 14px;
    justify-content: center;
  }
  .sidebar-brand-text,
  .nav-label { display: none; }
  .nav-item, .icon-btn-labeled {
    width: 48px;
    height: 48px;
    padding: 0;
    justify-content: center;
    position: relative;
  }
  .badge-pill {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    font-size: 10px;
    padding: 0 4px;
  }
  .topbar { padding: 0 16px; }
  .content-root { padding: 16px 16px 28px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .apps-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Fold hinge-friendly center gutter (24px) between left list and right editor */
  .master-detail {
    grid-template-columns: minmax(225px, 0.85fr) minmax(0, 1.15fr);
    gap: 24px;
  }
  .form-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col-grid { grid-template-columns: 1fr; }
}

/* ==========================================================================
   RESPONSIVE BREAKPOINT 2: Smartphone & Galaxy Z Fold Cover Screen (<= 679px)
   ========================================================================== */
@media (max-width: 679px) {
  .sidebar { display: none; }
  .mobile-only { display: inline-flex; }
  .mobile-brand-dot { display: flex; }

  .topbar {
    height: 58px;
    padding: 0 12px;
  }
  .page-title { font-size: 15.5px; }
  .page-subtitle { display: none; }

  .content-root {
    padding: 12px 12px calc(var(--bottom-nav-h) + 22px + env(safe-area-inset-bottom));
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .kpi-card { padding: 12px; }
  .kpi-value { font-size: 19px; }

  .apps-grid { grid-template-columns: 1fr; gap: 12px; }
  .two-col-grid { grid-template-columns: 1fr; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }

  /* On phone, Master-Detail switches smoothly between List view and Detail view */
  .master-detail {
    display: block;
  }
  .master-detail[data-mobile-view="list"] .detail-pane { display: none; }
  .master-detail[data-mobile-view="detail"] .master-pane { display: none; }
  .master-detail[data-mobile-view="detail"] .mobile-back-btn { display: inline-flex; }
  .master-list { max-height: none; }
  .detail-pane { padding: 14px; }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 40;
  }

  .bnav-item {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-3);
    font: inherit;
    font-size: 10.5px;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    padding: 4px 2px;
  }
  .bnav-item svg { width: 20px; height: 20px; }
  .bnav-item.active { color: var(--accent); }

  .toast-stack {
    right: 12px;
    left: 12px;
    bottom: calc(var(--bottom-nav-h) + 12px + env(safe-area-inset-bottom));
    max-width: none;
  }
}

/* Ultra-narrow Fold Cover & compact smartphone topbar (<= 480px) */
@media (max-width: 480px) {
  .topbar {
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
    padding: 9px 12px;
    row-gap: 8px;
  }
  .topbar-left { flex: 1 1 150px; min-width: 0; }
  .topbar-left > div { min-width: 0; }
  .page-title { overflow: hidden; text-overflow: ellipsis; }
  .topbar-actions { margin-left: auto; }
  .topbar-actions:has(#period-picker:not(.hidden)) {
    width: 100%;
    justify-content: space-between;
  }
}

/* Ultra-narrow Fold Cover screen (<= 380px) */
@media (max-width: 380px) {
  .segmented .seg-btn { padding: 0 9px; font-size: 12px; }
  .kpi-value { font-size: 17px; }
  .app-metrics-row { gap: 4px; }
  .mini-stat-val { font-size: 13px; }
}

/* --------------------------------------------------------------------------
   Enhanced Controls: Loaders, Alerts, Interactive Chart, SKU Editor, Archive
   -------------------------------------------------------------------------- */
.theme-icon-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.theme-icon-slot svg { width: 18px; height: 18px; }

.loading-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 28px 20px;
  color: var(--text-2);
}

.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: vopreki-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes vopreki-spin {
  to { transform: rotate(360deg); }
}

.warning-banner {
  background: var(--warn-soft);
  border: 1px solid rgba(217, 119, 6, 0.35);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
}

.warning-banner strong { color: var(--warn); }

.app-card.archived {
  opacity: 0.65;
  border-style: dashed;
}

.chart-selected-bar {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.chart-day-col { cursor: pointer; }
.chart-day-col:hover .chart-bar-bg { fill: var(--accent-soft); }

.kpi-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.sku-box {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sku-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sku-row-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 1fr 0.8fr 0.75fr auto;
  gap: 8px;
  align-items: end;
}

.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-input-wrap input[type="color"] {
  width: 42px;
  height: 42px;
  padding: 3px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface-2);
  cursor: pointer;
  flex-shrink: 0;
}

.emergency-box {
  border: 1px solid rgba(220, 38, 38, 0.35);
  background: var(--danger-soft);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

@media (max-width: 900px) {
  .sku-row-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .kpi-grid-3 { grid-template-columns: 1fr; gap: 8px; }
  .sku-row-grid { grid-template-columns: 1fr; }
}
