/* RUH AI Report — Design System matching attached reference */
:root {
  --bg-app: #f1f3fa;
  --bg-card: #ffffff;
  --bg-card-subtle: #fafbfe;
  --text-main: #181c32;
  --text-muted: #8b92a9;
  --text-light: #b5b9c9;
  
  --primary: #5850ec;
  --primary-hover: #483ee6;
  --primary-light: #ecebfe;
  --primary-gradient: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  
  --color-mint: #10b981;
  --color-mint-light: #e6f9f3;
  --color-cyan: #06b6d4;
  --color-cyan-light: #e3f8fc;
  --color-coral: #ef4444;
  --color-coral-light: #feecee;
  --color-orange: #f59e0b;
  --color-orange-light: #fef5e7;
  --color-purple: #8b5cf6;
  --color-purple-light: #f3eefa;

  --border-subtle: #f0f2f7;
  --border-card: rgba(226, 232, 240, 0.8);
  --shadow-sm: 0 2px 6px rgba(100, 110, 140, 0.04);
  --shadow-md: 0 10px 25px -5px rgba(112, 118, 160, 0.07), 0 4px 10px -2px rgba(112, 118, 160, 0.04);
  --shadow-lg: 0 20px 40px rgba(99, 102, 241, 0.09);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --radius-pill: 9999px;
  
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;
  -webkit-font-smoothing: antialiased;
}

/* Master App Container */
.app-layout {
  display: flex;
  width: 100%;
  max-width: 1440px;
  min-height: 900px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 70px rgba(79, 70, 229, 0.08), 0 10px 25px rgba(0, 0, 0, 0.02);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

/* Sidebar */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: #ffffff;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 32px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 8px;
  margin-bottom: 36px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
}

.brand-logo svg {
  width: 24px;
  height: 24px;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-main);
  display: block;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  display: block;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: left;
  width: 100%;
}

.nav-icon {
  width: 20px;
  height: 20px;
  stroke: var(--text-muted);
  transition: stroke 0.2s ease;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--bg-card-subtle);
  color: var(--text-main);
}

.nav-item:hover .nav-icon {
  stroke: var(--primary);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-item.active .nav-icon {
  stroke: var(--primary);
}

.sidebar-footer {
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
}

.system-status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--color-mint);
  font-weight: 600;
  padding: 8px 12px;
  background: var(--color-mint-light);
  border-radius: var(--radius-pill);
}

.status-dot {
  width: 7px;
  height: 7px;
  background: var(--color-mint);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--color-mint);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* Main Content Area */
.main-content {
  flex: 1;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  max-height: 94vh;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 36px 20px 36px;
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-title-wrap h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-main);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.currency-tag {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* View Viewport */
.view-viewport {
  padding: 10px 36px 36px 36px;
  flex: 1;
}

.content-view {
  display: none;
}

.content-view.active {
  display: block;
  animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Metric Cards Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background: #ffffff;
  padding: 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-subtle);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.metric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.metric-icon-box {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.metric-icon-box svg {
  width: 20px;
  height: 20px;
}

.bg-mint { background: var(--color-mint-light); }
.bg-indigo { background: var(--primary-light); }
.bg-cyan { background: var(--color-cyan-light); }
.bg-coral { background: var(--color-coral-light); }
.bg-purple { background: var(--color-purple-light); }

.metric-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
}

.trend-up { background: var(--color-mint-light); color: var(--color-mint); }
.trend-down { background: var(--color-coral-light); color: var(--color-coral); }
.trend-neutral { background: var(--bg-card-subtle); color: var(--text-muted); }
.trend-net { background: var(--primary-light); color: var(--primary); }

.metric-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.metric-value {
  font-size: 19px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.text-danger { color: var(--color-coral) !important; }
.text-net { color: var(--primary) !important; }

/* Dashboard Middle Grid */
.dashboard-grid-2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

/* Card Base */
.card {
  background: #ffffff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.3px;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Chart Styles */
.chart-filter-pills {
  display: flex;
  background: var(--bg-card-subtle);
  padding: 4px;
  border-radius: var(--radius-pill);
  gap: 2px;
}

.pill-btn {
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.chart-summary-stat {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.chart-current-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.8px;
}

.chart-tag-badge {
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: var(--radius-pill);
}

.svg-chart-wrapper {
  width: 100%;
  height: 240px;
  position: relative;
}

.svg-chart {
  width: 100%;
  height: 100%;
  overflow: visible;
  cursor: crosshair;
  user-select: none;
  touch-action: none;
}

/* Ranking Card */
.ranking-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ranking-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-card-subtle);
  transition: transform 0.15s ease;
}

.ranking-item:hover {
  transform: translateX(3px);
  background: #f1f3fa;
}

.rank-manager-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rank-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #ffffff;
}

.rank-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  display: block;
}

.rank-net {
  font-size: 11px;
  color: var(--text-muted);
}

.rank-figures {
  text-align: right;
}

.rank-commission {
  font-size: 13px;
  font-weight: 800;
  color: var(--primary);
  display: block;
}

.rank-bonus-tag {
  font-size: 10px;
  font-weight: 700;
  background: var(--color-mint-light);
  color: var(--color-mint);
  padding: 2px 6px;
  border-radius: var(--radius-pill);
}

/* Tables */
.table-container {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
  padding: 14px;
  font-size: 13px;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: var(--bg-card-subtle);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
}

.status-badge.completed { background: var(--color-mint-light); color: var(--color-mint); }
.status-badge.partial_refund { background: var(--color-orange-light); color: var(--color-orange); }
.status-badge.refunded { background: var(--color-coral-light); color: var(--color-coral); }
.status-badge.mgr-active { background: var(--color-mint-light); color: var(--color-mint); }
.status-badge.mgr-inactive { background: var(--color-coral-light); color: var(--color-coral); }
.status-badge.mgr-pending { background: var(--color-orange-light); color: var(--color-orange); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: #ffffff;
  color: var(--text-main);
  border: 1px solid var(--border-card);
}

.btn-secondary:hover {
  background: var(--bg-card-subtle);
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

/* Managers Grid */
.managers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.manager-card {
  background: #ffffff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.manager-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.mgr-avatar-lg {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
}

.mgr-name-lg {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.mgr-role {
  font-size: 12px;
  color: var(--text-muted);
}

.manager-stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border-subtle);
  font-size: 13px;
}

.manager-stat-row:last-child {
  border-bottom: none;
}

/* Bonus Tiers Grid */
.bonus-tiers-display {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.bonus-tier-pill {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.bonus-tier-pill strong {
  color: var(--primary);
}

/* Calculators */
.calculators-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
}

.calc-form-group {
  margin-bottom: 16px;
}

.calc-form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.calc-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  background: #ffffff;
}

.calc-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.calc-breakdown-box {
  background: var(--bg-card-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-top: 20px;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 10px;
  color: var(--text-muted);
}

.calc-row strong {
  color: var(--text-main);
}

.calc-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 12px 0;
}

.total-row {
  font-size: 15px;
  margin-bottom: 0;
}

.total-row span {
  font-weight: 800;
  color: var(--text-main);
}

.total-row strong {
  font-size: 20px;
  font-weight: 800;
}

/* Math Calculator Keypad */
.math-display {
  background: #181c32;
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: right;
  margin-bottom: 16px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.2);
}

.math-prev-expr {
  font-size: 13px;
  color: #8b92a9;
  min-height: 18px;
  font-family: var(--font-mono);
}

.math-current-val {
  font-size: 28px;
  font-weight: 700;
  font-family: var(--font-mono);
  overflow-x: auto;
}

.math-keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.calc-btn {
  height: 52px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.calc-btn:hover {
  background: var(--bg-card-subtle);
}

.calc-btn:active {
  transform: scale(0.96);
}

.btn-func { background: #f1f3fa; color: #4b5563; }
.btn-op { background: var(--primary-light); color: var(--primary); }
.btn-equals { background: var(--primary); color: #ffffff; grid-column: span 2; }
.btn-equals:hover { background: var(--primary-hover); }

/* Reports */
.reports-summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.report-stat-box {
  background: var(--bg-card-subtle);
  padding: 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 28, 50, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #ffffff;
  width: 100%;
  max-width: 500px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: scaleUp 0.2s ease;
}

@keyframes scaleUp {
  from { transform: scale(0.95); }
  to { transform: scale(1); }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* Filters, notices, admin, details */
[hidden] { display: none !important; }

.header-flex {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.filter-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.filter-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.filter-input {
  padding: 8px 12px;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-main);
  background: #ffffff;
}

.filter-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.filter-search { min-width: 260px; flex: 1; }

.global-notice {
  margin: 0 36px 12px 36px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
  background: var(--color-orange-light);
  color: #92400e;
  border: 1px solid #fde68a;
}

.global-notice.error {
  background: var(--color-coral-light);
  color: #991b1b;
  border-color: #fecaca;
}

.admin-pill {
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-card-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.admin-pill.on { background: var(--color-mint-light); color: var(--color-mint); }

.system-status-pill.offline { background: var(--color-coral-light); color: var(--color-coral); }
.system-status-pill.offline .status-dot { background: var(--color-coral); box-shadow: 0 0 8px var(--color-coral); }

.top-bar-actions .btn svg { width: 16px; height: 16px; }

.status-badge.new { background: var(--primary-light); color: var(--primary); }
.status-badge.in_progress { background: var(--color-cyan-light); color: var(--color-cyan); }
.status-badge.cancelled { background: #f1f5f9; color: #64748b; }
.status-badge.debt { background: var(--color-coral-light); color: var(--color-coral); }
.status-badge.test-badge { background: #fef3c7; color: #92400e; }

.text-accent { color: var(--color-purple) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-mint { color: var(--color-mint) !important; }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.nowrap { white-space: nowrap; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.empty-state.error { color: var(--color-coral); }

.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  margin: 2px 4px 2px 0;
  border-radius: var(--radius-pill);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
}

.card-actions-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.btn-sm { padding: 6px 12px; font-size: 12px; }

/* "Удалить" is visually stronger than "Деактивировать" (resets the registration) */
.btn-delete { background: var(--color-coral-light); color: var(--color-coral); border: 1px solid #fecaca; }
.btn-delete:hover:not(:disabled) { background: var(--color-coral); color: #ffffff; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.link-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.notice-box {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
  background: var(--color-coral-light);
  color: #991b1b;
  border: 1px solid #fecaca;
}
.breakdown-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); margin: 14px 0 8px; }
.breakdown-row .breakdown-title:first-child { margin-top: 4px; }
#archiveTabs { flex-wrap: wrap; }

.stat-bars { display: flex; flex-direction: column; gap: 10px; }
.stat-bar-row { font-size: 12px; }
.stat-bar-label { display: flex; justify-content: space-between; margin-bottom: 4px; color: var(--text-main); font-weight: 600; }
.stat-bar-track { height: 8px; background: var(--bg-card-subtle); border-radius: var(--radius-pill); overflow: hidden; }
.stat-bar-fill { height: 100%; background: var(--primary-gradient); border-radius: var(--radius-pill); }
.stat-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin: 6px 0 10px; }

.dashboard-grid-2.equal { grid-template-columns: 1fr 1fr; }

.breakdown-row td { background: var(--bg-card-subtle); padding: 0 14px 14px 14px; }
.breakdown-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.breakdown-table th, .breakdown-table td { font-size: 12px; padding: 6px 8px; text-align: left; border-bottom: 1px dashed var(--border-subtle); background: transparent; }
.breakdown-table th { color: var(--text-muted); font-weight: 700; }

.modal-wide { max-width: 920px; }
.modal-scroll { max-height: 78vh; overflow-y: auto; }
.modal-top { z-index: 110; }
.modal-text { font-size: 14px; line-height: 1.5; margin-bottom: 16px; }
.form-error { color: var(--color-coral); font-size: 13px; min-height: 18px; }
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 14px;
  resize: vertical;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.detail-item {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.detail-item span { display: block; font-size: 11px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.detail-item strong { font-size: 14px; }
.detail-section-title { font-size: 14px; font-weight: 700; margin: 18px 0 10px; }
.detail-pre {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
  max-height: 220px;
  overflow-y: auto;
}

.salary-month-label { font-size: 12px; color: var(--text-muted); }

/* Toggle switch (Settings → registration mode) */
.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.switch-input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.switch-track {
  position: relative;
  flex-shrink: 0;
  width: 46px;
  height: 26px;
  border-radius: var(--radius-pill);
  background: #d5d9e6;
  transition: background 0.2s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.switch-input:checked + .switch-track { background: var(--primary); }
.switch-input:checked + .switch-track::after { transform: translateX(20px); }
.switch-input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--primary-light); }
.switch-input:disabled + .switch-track { opacity: 0.5; }
.switch-input:disabled ~ .switch-label { color: var(--text-muted); }
.switch-row:has(.switch-input:disabled) { cursor: not-allowed; }

/* Login screen (cloud version) */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg-app);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  padding: 32px;
}

.login-brand { margin-bottom: 24px; padding-left: 0; }
.login-title { font-size: 20px; font-weight: 700; margin-bottom: 18px; }
.login-submit { width: 100%; justify-content: center; margin-top: 8px; }

/* Utilities */
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mt-4 { margin-top: 16px; }
.p-4 { padding: 16px; }
.w-200 { width: 200px; }

/* Responsive */
@media (max-width: 1200px) {
  .metrics-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .dashboard-grid-2,
  .dashboard-grid-2.equal {
    grid-template-columns: 1fr;
  }
  .calculators-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ===== Phone & tablet (≤ 900px): full-width page, compact sticky header with a section menu ===== */
.menu-toggle { display: none; }

@media (max-width: 900px) {
  body { display: block; padding: 0; background: #f8fafc; }
  .app-layout { flex-direction: column; min-height: 100vh; border-radius: 0; box-shadow: none; border: none; overflow: visible; }

  /* Compact header: brand left, current section + menu button right */
  .sidebar {
    position: sticky; top: 0; z-index: 60;
    width: 100%; min-width: 0;
    padding: 10px 16px;
    border-right: none; border-bottom: 1px solid var(--border-subtle);
    box-shadow: 0 4px 14px rgba(100, 110, 140, 0.06);
  }
  .brand { margin-bottom: 0; padding-left: 0; gap: 10px; min-height: 44px; padding-right: 150px; }
  .brand-logo { width: 34px; height: 34px; }
  .brand-title { font-size: 17px; }
  .menu-toggle {
    display: inline-flex; align-items: center; gap: 8px;
    position: absolute; right: 16px; top: 10px; height: 44px; max-width: 150px;
    padding: 0 12px 0 14px;
    border: 1px solid var(--border-card); border-radius: var(--radius-pill);
    background: #ffffff; color: var(--text-main);
    font-family: var(--font-sans); font-size: 13px; font-weight: 700; cursor: pointer;
  }
  .menu-toggle svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--primary); }
  .menu-toggle-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar.menu-open .menu-toggle { background: var(--primary-light); border-color: transparent; color: var(--primary); }

  .nav-menu { display: none; }
  .sidebar.menu-open .nav-menu {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
    padding: 12px 0 6px; max-height: calc(100vh - 80px); overflow-y: auto;
  }
  .nav-item { padding: 12px; gap: 10px; min-height: 46px; background: var(--bg-card-subtle); }
  .nav-item span { overflow-wrap: anywhere; }
  .sidebar-footer { display: none; }
  .sidebar.menu-open .sidebar-footer { display: block; padding-top: 8px; border-top: none; }

  /* Page scrolls normally (no inner scroll box) */
  .main-content { max-height: none; overflow: visible; }
  .top-bar { position: static; flex-direction: column; align-items: stretch; gap: 12px; padding: 18px 16px 10px; }
  .page-title-wrap h1 { font-size: 22px; }
  .top-bar-actions { flex-wrap: wrap; gap: 8px; }
  .currency-tag { display: none; }
  .admin-pill { flex: 1 1 100%; text-align: center; white-space: normal; overflow-wrap: anywhere; padding: 8px 12px; }
  .top-bar-actions .btn { flex: 1 1 0; justify-content: center; min-height: 42px; padding: 10px 12px; }
  .global-notice { margin: 0 16px 12px; }
  .view-viewport { padding: 6px 16px 28px; }

  .card { padding: 16px; }
  .card-header { flex-wrap: wrap; gap: 10px; align-items: flex-start; margin-bottom: 14px; }
  .card-header > *, .header-flex > * { min-width: 0; }
  .metrics-grid { grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
  .dashboard-grid-2, .dashboard-grid-2.equal, .calculators-grid { grid-template-columns: 1fr; gap: 16px; margin-bottom: 16px; }
  .metrics-grid > *, .dashboard-grid-2 > *, .calculators-grid > *, .managers-grid > * { min-width: 0; }
  .managers-grid { grid-template-columns: 1fr; gap: 14px; margin-top: 14px; }
  .reports-summary-cards { grid-template-columns: 1fr 1fr !important; gap: 12px; }
  .table-container { -webkit-overflow-scrolling: touch; max-width: 100%; }
}

/* ===== Phones (≤ 640px) ===== */
@media (max-width: 640px) {
  .page-subtitle { display: none; }

  /* Stat cards */
  .metric-card { padding: 14px; }
  .metric-header { margin-bottom: 10px; gap: 6px; align-items: flex-start; }
  .metric-icon-box { width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0; }
  .metric-icon-box svg { width: 17px; height: 17px; }
  .metric-badge { font-size: 10px; padding: 3px 7px; text-align: right; line-height: 1.3; }
  .metric-label { font-size: 11px; }
  .metric-value { font-size: 17px; overflow-wrap: anywhere; }

  /* Filters: pills wrap into even rows, dates side by side, inputs full width */
  .filter-strip { gap: 8px; margin-bottom: 14px; }
  .chart-filter-pills { flex-wrap: wrap; border-radius: 14px; width: 100%; }
  .pill-btn { flex: 1 1 auto; min-height: 36px; padding: 8px 10px; }
  .filter-field { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .filter-field .filter-input { flex: 1; width: 100%; min-width: 0; }
  .filter-strip > select.filter-input { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .filter-search { flex: 1 1 100%; min-width: 0; }
  .header-flex { align-items: stretch; }
  .header-flex > .btn, .card-header > .btn { width: 100%; justify-content: center; }

  /* iOS: 16px inputs never trigger auto-zoom */
  .filter-input, .calc-input, .form-group input, .form-group select, .form-group textarea { font-size: 16px; }

  /* Wide tables scroll inside their card; edge shadows show there is more to the side */
  .data-table th, .data-table td { padding: 10px; font-size: 12px; white-space: nowrap; }
  .table-container {
    background:
      linear-gradient(to right, #fff 30%, rgba(255, 255, 255, 0)) 0 0,
      linear-gradient(to left, #fff 30%, rgba(255, 255, 255, 0)) 100% 0,
      radial-gradient(farthest-side at 0 50%, rgba(24, 28, 50, 0.14), transparent) 0 0,
      radial-gradient(farthest-side at 100% 50%, rgba(24, 28, 50, 0.14), transparent) 100% 0;
    background-repeat: no-repeat;
    background-size: 36px 100%, 36px 100%, 12px 100%, 12px 100%;
    background-attachment: local, local, scroll, scroll;
  }

  /* Order lists & small report tables become cards: one card per row, labelled fields */
  .data-table td[colspan] { white-space: normal; }
  .data-table.stack-mobile > thead { display: none; }
  .data-table.stack-mobile, .data-table.stack-mobile > tbody { display: block; }
  .data-table.stack-mobile > tbody > tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px;
    padding: 12px 14px; margin-bottom: 10px;
    border: 1px solid var(--border-subtle); border-radius: 12px; background: #ffffff;
  }
  .data-table.stack-mobile > tbody > tr:hover { background: #ffffff; }
  .data-table.stack-mobile > tbody > tr > td {
    display: block; padding: 0; border: none; min-width: 0;
    white-space: normal; overflow-wrap: anywhere; font-size: 13px;
  }
  .data-table.stack-mobile > tbody > tr > td::before {
    content: attr(data-label); display: block; margin-bottom: 2px;
    font-size: 10px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; color: var(--text-muted);
  }
  .data-table.stack-mobile > tbody > tr > td[data-label=""]::before { display: none; }
  .data-table.stack-mobile > tbody > tr > td:first-child { grid-column: 1 / -1; font-size: 14px; }
  .data-table.stack-mobile > tbody > tr > td[data-label=""]:last-child { grid-column: 1 / -1; }
  /* Full-width rows (empty states, notes, salary breakdowns) */
  .data-table.stack-mobile > tbody > tr:has(> td[colspan]) { display: block; border: none; padding: 0; background: transparent; }
  .data-table.stack-mobile > tbody > tr.breakdown-row { margin-top: -6px; }
  .data-table.stack-mobile > tbody > tr.breakdown-row > td { background: var(--bg-card-subtle); border-radius: 12px; padding: 4px 10px 10px; overflow-x: auto; }
  .breakdown-table th, .breakdown-table td { white-space: nowrap; }

  /* Charts & lists */
  .chart-summary-stat { flex-wrap: wrap; gap: 8px; }
  .chart-current-value { font-size: 22px; }
  .svg-chart-wrapper { height: 200px; }
  .ranking-item { gap: 10px; }
  .rank-manager-info { min-width: 0; }
  .rank-figures { flex-shrink: 0; }

  /* People cards */
  .manager-card { padding: 16px; }
  .manager-stat-row { gap: 12px; }
  .manager-stat-row > :last-child { text-align: right; overflow-wrap: anywhere; }
  .card-actions-row .btn { flex: 1 1 auto; justify-content: center; }

  /* Dialogs become bottom sheets */
  .modal-backdrop { align-items: flex-end; }
  .modal-card { max-width: none; border-radius: 18px 18px 0 0; max-height: 92vh; overflow-y: auto; }
  .modal-header, .modal-body { padding: 16px; }
  .modal-scroll { max-height: none; }
  .form-row { grid-template-columns: 1fr; }
  .modal-footer .btn { flex: 1; justify-content: center; }
  .detail-grid { grid-template-columns: 1fr 1fr; gap: 8px; }

  /* Calculators & settings */
  .calc-btn { height: 48px; }
  .math-keypad { gap: 8px; }
  .w-200 { width: 100%; }
  #settingsTiersTable [data-tier-row] > span:first-child { width: 100% !important; }
  #settingsTiersTable .calc-input { flex: 1 1 110px; width: auto !important; min-width: 0; }
  .settings-actions .btn { width: 100%; justify-content: center; }
  .login-card { padding: 24px; border-radius: 18px; }
}

/* ===== Narrow phones (≤ 380px): one date per row so dates are never cut ===== */
@media (max-width: 380px) {
  .filter-field { flex: 1 1 100%; }
  .filter-strip > select.filter-input { flex: 1 1 100%; }
}

/* ===== Very narrow phones (≤ 360px) ===== */
@media (max-width: 360px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .reports-summary-cards { grid-template-columns: 1fr !important; }
  .detail-grid { grid-template-columns: 1fr; }
  .brand-subtitle { display: none; }
}
