:root {
  --bg: #f3f6f5;
  --surface: #ffffff;
  --surface-muted: #f7f9f8;
  --ink: #17302f;
  --muted: #657573;
  --line: #dfe7e5;
  --teal-950: #123c3a;
  --teal-800: #1b5752;
  --teal-600: #258178;
  --teal-100: #dff2ee;
  --blue: #3976d4;
  --orange: #e49336;
  --purple: #7e65c7;
  --red: #c84e4e;
  --shadow: 0 10px 30px rgba(25, 55, 52, .07);
  --radius: 16px;
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

button, input, select { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 264px;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  background: linear-gradient(175deg, #153f3d 0%, #0f302f 100%);
  color: #fff;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 22px;
  border-bottom: 1px solid rgba(255,255,255,.11);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: #7fd0c3;
  color: #113c39;
}

.brand-mark svg,
.nav-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand strong { display: block; font-size: 15px; letter-spacing: -.1px; }
.brand span { display: block; margin-top: 2px; color: #b8d1ce; font-size: 11px; }

.nav-list { display: grid; gap: 7px; margin-top: 24px; }

.nav-button {
  width: 100%;
  min-height: 47px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 13px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #c8dcda;
  cursor: pointer;
  text-align: left;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

.nav-button:hover { background: rgba(255,255,255,.07); color: #fff; transform: translateX(2px); }
.nav-button.active { background: #f2faf8; color: #174b47; box-shadow: 0 9px 24px rgba(0,0,0,.13); }

.sidebar-status {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  background: rgba(255,255,255,.05);
}

.sidebar-status strong,
.sidebar-status span { display: block; }
.sidebar-status strong { font-size: 12px; }
.sidebar-status div > span { margin-top: 1px; color: #a9c8c5; font-size: 10px; }

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #e6b45a;
  box-shadow: 0 0 0 4px rgba(230,180,90,.14);
}

.status-dot.online { background: #75d7aa; box-shadow: 0 0 0 4px rgba(117,215,170,.14); }
.status-dot.error { background: #f07e7e; box-shadow: 0 0 0 4px rgba(240,126,126,.14); }

.main-content { min-height: 100vh; margin-left: 264px; padding: 0 30px 40px; }

.topbar {
  min-height: 103px;
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.section-heading h2,
.panel h3 { margin: 0; }
.topbar h1 { margin-top: 2px; font-size: 25px; letter-spacing: -.5px; }

.eyebrow {
  margin: 0;
  color: var(--teal-600);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.mobile-menu { display: none; border: 0; background: transparent; font-size: 24px; }

.month-toolbar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 9px;
}

.month-toolbar label { color: var(--muted); font-size: 12px; font-weight: 650; }

input, select {
  min-height: 40px;
  border: 1px solid #cad8d5;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}

input:focus, select:focus { border-color: var(--teal-600); box-shadow: 0 0 0 3px rgba(37,129,120,.12); }

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}

.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.button.primary { background: var(--teal-800); color: #fff; box-shadow: 0 6px 16px rgba(27,87,82,.17); }
.button.primary:hover { background: #144944; }
.button.secondary { border-color: #c9d8d5; background: #fff; color: var(--teal-800); }
.button.secondary:hover { background: #f2f8f6; }
.button.danger { border-color: #efcaca; background: #fff6f5; color: #a23b3b; }
.button-row { display: flex; gap: 9px; flex-wrap: wrap; }

.view { display: none; padding-top: 28px; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: .35; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.section-heading h2 { margin-top: 4px; font-size: 22px; letter-spacing: -.4px; }
.data-badge { padding: 7px 11px; border-radius: 999px; background: #e6efed; color: #52706c; font-size: 11px; font-weight: 700; }
.data-badge.live { background: #dff3ea; color: #217155; }

.alert-banner {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid #ebd8ae;
  border-radius: 11px;
  background: #fff8e8;
  color: #72531e;
  font-size: 12px;
}

.hidden { display: none !important; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 15px;
}

.kpi-card {
  position: relative;
  min-height: 130px;
  overflow: hidden;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--card-accent); }
.kpi-card::after { content: ""; position: absolute; width: 72px; height: 72px; right: -25px; top: -27px; border-radius: 50%; background: color-mix(in srgb, var(--card-accent) 11%, transparent); }
.accent-teal { --card-accent: var(--teal-600); }
.accent-blue { --card-accent: var(--blue); }
.accent-orange { --card-accent: var(--orange); }
.accent-purple { --card-accent: var(--purple); }
.accent-red { --card-accent: var(--red); }
.kpi-label { display: block; color: var(--muted); font-size: 11px; font-weight: 650; }
.kpi-card strong { display: block; margin: 13px 0 5px; font-size: clamp(20px, 2vw, 27px); letter-spacing: -.7px; }
.kpi-card small { color: #83918f; font-size: 10px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, .8fr); gap: 15px; margin-top: 15px; }

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chart-panel, .peak-panel, .mapping-panel, .schedule-panel { padding: 20px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.panel h3 { font-size: 14px; }
.panel-heading p, .settings-card p, .backup-card p, .storage-panel p, .action-panel p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.chart-legend, .schedule-legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 10px; }
.chart-legend span, .schedule-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-line { width: 16px; height: 3px; border-radius: 3px; background: #ccc; }
.legend-line.teal { background: var(--teal-600); }
.legend-line.blue { background: var(--blue); }
.legend-line.orange { background: var(--orange); }
.canvas-wrap { position: relative; height: 265px; margin-top: 17px; }
.canvas-wrap.small { height: 215px; }
canvas { width: 100%; height: 100%; }

.rank-list { margin-top: 13px; }
.rank-item { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid #edf1f0; }
.rank-item:last-child { border-bottom: 0; }
.rank-number { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 8px; background: #edf5f3; color: var(--teal-800); font-size: 10px; font-weight: 800; }
.rank-info strong, .rank-info span { display: block; }
.rank-info strong { font-size: 11px; }
.rank-info span { color: var(--muted); font-size: 9px; }
.rank-value { font-size: 11px; font-weight: 750; }

.empty-state { display: grid; place-items: center; min-height: 180px; color: #84928f; text-align: center; font-size: 12px; }
.empty-cell { padding: 30px !important; color: #84928f; text-align: center !important; }

.action-panel { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 15px; padding: 18px 20px; background: linear-gradient(105deg, #eff8f6, #fff); }

.heat-legend { display: flex; align-items: center; gap: 3px; color: var(--muted); font-size: 9px; }
.heat-legend i { width: 16px; height: 10px; border-radius: 3px; }
.heat-legend i:nth-of-type(1) { background: #edf6f4; }
.heat-legend i:nth-of-type(2) { background: #c7e7e1; }
.heat-legend i:nth-of-type(3) { background: #86c9be; }
.heat-legend i:nth-of-type(4) { background: #3c998e; }
.heat-legend i:nth-of-type(5) { background: #15534e; }

.heatmap-shell { overflow: auto; padding: 18px; }
.heatmap-grid { display: grid; gap: 4px; width: max-content; min-width: 100%; }
.heatmap-label, .heatmap-hour, .heat-cell { min-width: 34px; height: 26px; display: grid; place-items: center; border-radius: 5px; font-size: 9px; }
.heatmap-label { position: sticky; left: 0; z-index: 2; min-width: 104px; justify-content: start; padding-left: 6px; background: #fff; color: #425c59; font-weight: 650; }
.heatmap-hour { color: var(--muted); font-weight: 650; }
.heat-cell { cursor: default; color: transparent; transition: transform .12s ease; }
.heat-cell.closed { background: repeating-linear-gradient(135deg,#f4f6f5,#f4f6f5 4px,#e7ecea 4px,#e7ecea 8px); }
.heat-cell:hover { transform: scale(1.1); outline: 2px solid #fff; box-shadow: 0 0 0 3px var(--teal-600); z-index: 3; }

.mapping-panel { margin-top: 15px; }
.table-scroll { overflow: auto; margin-top: 15px; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.data-table th { position: sticky; top: 0; z-index: 1; padding: 10px 12px; border-bottom: 1px solid #d9e3e1; background: #f5f8f7; color: #536865; text-align: left; font-size: 9px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; white-space: nowrap; }
.data-table td { padding: 11px 12px; border-bottom: 1px solid #edf1f0; text-align: left; font-size: 11px; vertical-align: middle; }
.data-table tbody tr:hover td { background: #f9fbfa; }
.source-pill { display: inline-flex; margin: 2px 4px 2px 0; padding: 3px 6px; border-radius: 999px; background: #e9f3f1; color: #376a65; font-size: 9px; }
.confidence { display: flex; align-items: center; gap: 7px; }
.confidence-bar { width: 55px; height: 5px; overflow: hidden; border-radius: 5px; background: #e8eeed; }
.confidence-bar i { display: block; height: 100%; background: var(--teal-600); }

.schedule-heading { align-items: center; }
.schedule-summary { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-bottom: 15px; }
.schedule-summary article { padding: 13px 15px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.schedule-summary span, .schedule-summary strong { display: block; }
.schedule-summary span { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .5px; }
.schedule-summary strong { margin-top: 5px; font-size: 17px; }
.schedule-panel { padding-bottom: 10px; }
.schedule-legend { justify-content: flex-end; margin-bottom: 12px; }
.shift-chip { width: 12px; height: 8px; border-radius: 3px; }
.shift-chip.morning { background: #d8efe9; }
.shift-chip.evening { background: #e7e0fa; }
.shift-chip.off { background: #edf0ef; }
.shift-chip.saturday { border: 1px solid #dfaa5d; background: #fff1da; }
.schedule-scroll { max-height: 620px; overflow: auto; }
.schedule-empty { min-height: 280px; }
.schedule-table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
.schedule-table th, .schedule-table td { border-right: 1px solid #e6ecea; border-bottom: 1px solid #e6ecea; }
.schedule-table thead th { position: sticky; top: 0; z-index: 5; min-width: 64px; padding: 8px 4px; background: #f3f7f6; color: #526966; font-size: 9px; text-align: center; }
.schedule-table thead th:first-child { left: 0; z-index: 7; min-width: 180px; text-align: left; padding-left: 12px; }
.schedule-table tbody th { position: sticky; left: 0; z-index: 4; min-width: 180px; padding: 8px 12px; background: #fff; text-align: left; }
.schedule-table tbody th strong, .schedule-table tbody th small { display: block; }
.schedule-table tbody th strong { font-size: 10px; }
.schedule-table tbody th small { color: var(--muted); font-size: 8px; font-weight: 500; }
.schedule-table td { min-width: 64px; height: 43px; padding: 4px; background: #fff; text-align: center; cursor: pointer; }
.schedule-table td:hover { outline: 2px solid var(--teal-600); outline-offset: -2px; }
.schedule-table .weekend-head { background: #fff6e8; color: #8c601f; }
.schedule-cell { height: 32px; display: grid; place-items: center; border-radius: 6px; font-size: 8px; font-weight: 750; line-height: 1.1; }
.schedule-cell.morning { background: #dff3ee; color: #246a61; }
.schedule-cell.evening { background: #ebe5fa; color: #634b9d; }
.schedule-cell.off { background: #f0f2f1; color: #87918f; }
.schedule-cell.closed { background: repeating-linear-gradient(135deg,#f4f5f5,#f4f5f5 5px,#ecefee 5px,#ecefee 10px); color: #9aa3a1; }
.schedule-cell.saturday { box-shadow: inset 0 0 0 1px #e1aa56; }
.schedule-cell.issue { box-shadow: inset 0 0 0 2px #d85959; }
.issue-list { margin-bottom: 14px; padding: 10px 13px; border: 1px solid #efc9c9; border-radius: 11px; background: #fff6f5; color: #873b3b; font-size: 11px; }
.issue-list ul { margin: 4px 0 0; padding-left: 18px; }

.staff-table input, .staff-table select { min-height: 34px; width: 100%; min-width: 110px; padding: 6px 8px; font-size: 11px; }
.staff-table input[type="checkbox"] { min-height: 16px; width: 16px; min-width: 16px; }
.staff-table .name-input { min-width: 190px; }
.icon-button { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid #dce5e3; border-radius: 8px; background: #fff; cursor: pointer; }
.icon-button.danger { color: var(--red); }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.settings-card { padding: 20px; }
.settings-card h3 { margin-bottom: 15px; }
.form-grid { display: grid; gap: 13px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid label, .settings-card > label, .modal label { display: grid; gap: 6px; color: #526865; font-size: 10px; font-weight: 700; }
.check-row { display: flex !important; align-items: center; grid-template-columns: auto 1fr; margin-top: 16px; }
.check-row input { min-height: 16px; width: 16px; }
.save-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; background: linear-gradient(110deg,#eff8f6,#fff); }

.backup-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 15px; }
.backup-card { padding: 24px; text-align: center; }
.backup-card p { max-width: 430px; min-height: 48px; margin: 8px auto 18px; }
.backup-icon { width: 48px; height: 48px; display: grid; place-items: center; margin: 0 auto 13px; border-radius: 15px; font-size: 24px; font-weight: 300; }
.backup-icon.export { background: #dff3ee; color: #1c766c; }
.backup-icon.import { background: #e7edfa; color: #466db0; }
.file-button input { display: none; }
.storage-panel { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 15px; padding: 19px 22px; }

.modal { width: min(440px, calc(100vw - 28px)); padding: 0; border: 0; border-radius: 16px; box-shadow: 0 25px 70px rgba(14,42,40,.28); }
.modal::backdrop { background: rgba(13,35,34,.48); backdrop-filter: blur(2px); }
.modal form { display: grid; gap: 14px; padding: 21px; }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 3px; }
.modal-heading h3 { margin: 3px 0 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 5px; }
.field-hint { margin: -7px 0 0; color: var(--muted); font-size: 10px; }

.loading-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 12px; background: rgba(244,248,247,.85); backdrop-filter: blur(2px); color: var(--teal-800); font-weight: 700; }
.spinner { width: 35px; height: 35px; border: 3px solid #cfe1de; border-top-color: var(--teal-600); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 110; display: grid; gap: 8px; }
.toast { min-width: 250px; max-width: 390px; padding: 12px 14px; border: 1px solid #cfe0dd; border-radius: 11px; background: #fff; box-shadow: 0 14px 35px rgba(20,50,47,.17); font-size: 11px; animation: toast-in .2s ease; }
.toast.success { border-left: 4px solid #42a67a; }
.toast.error { border-left: 4px solid #d25a5a; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .peak-panel { min-height: 260px; }
  .month-toolbar label { display: none; }
}

@media (max-width: 920px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 15px 0 40px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .main-content { margin-left: 0; padding: 0 18px 32px; }
  .mobile-menu { display: block; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .topbar { min-height: auto; padding: 16px 0; flex-wrap: wrap; }
  .topbar > div:nth-of-type(1) { flex: 1; }
  .topbar h1 { font-size: 21px; }
  .month-toolbar { width: 100%; margin: 0; }
  .month-toolbar input { flex: 1; min-width: 0; }
  .kpi-grid, .schedule-summary, .backup-grid { grid-template-columns: 1fr 1fr; }
  .kpi-card { min-height: 118px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .schedule-heading { flex-direction: row; }
  .chart-legend { display: none; }
  .form-grid.two { grid-template-columns: 1fr; }
  .save-card, .storage-panel, .action-panel { align-items: stretch; flex-direction: column; }
}

@media (max-width: 450px) {
  .main-content { padding-inline: 12px; }
  .kpi-grid, .schedule-summary, .backup-grid { grid-template-columns: 1fr; }
  .month-toolbar { align-items: stretch; flex-direction: column; }
  .month-toolbar .button { width: 100%; }
  .schedule-heading { flex-direction: column; }
}
