:root {
  color-scheme: light;
  --navy-950: #08263f;
  --navy-900: #0b3558;
  --navy-800: #134b70;
  --teal-700: #0b6477;
  --teal-600: #0b7d8d;
  --teal-100: #dff4f4;
  --sky-50: #f2f8fb;
  --slate-900: #172b3a;
  --slate-700: #425b6b;
  --slate-500: #708493;
  --slate-300: #cbd8df;
  --slate-200: #dce6eb;
  --slate-100: #edf3f6;
  --white: #ffffff;
  --amber-700: #9a5b00;
  --amber-100: #fff2cd;
  --red-700: #a52a2a;
  --red-100: #ffe7e5;
  --green-700: #126349;
  --green-100: #dff5e9;
  --purple-700: #6941a5;
  --purple-100: #f0e7ff;
  --shadow: 0 12px 34px rgba(8, 38, 63, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; background: var(--sky-50); }

body {
  margin: 0;
  min-width: 320px;
  color: var(--slate-900);
  background:
    radial-gradient(circle at 10% 0%, rgba(11, 125, 141, 0.08), transparent 28rem),
    var(--sky-50);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

button, input { font: inherit; }

button { touch-action: manipulation; }

button:focus-visible, input:focus-visible, [role="button"]:focus-visible {
  outline: 3px solid rgba(11, 125, 141, 0.32);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 999;
  top: 0.5rem;
  left: 0.5rem;
  transform: translateY(-160%);
  padding: 0.65rem 0.9rem;
  border-radius: 0.5rem;
  color: var(--white);
  background: var(--navy-900);
}

.skip-link:focus { transform: translateY(0); }

.app-header {
  padding-top: env(safe-area-inset-top);
  color: var(--white);
  background: linear-gradient(112deg, var(--navy-950), var(--navy-900) 58%, #0b596a);
  border-bottom: 4px solid #26a8a7;
}

.header-inner {
  width: min(1440px, calc(100% - 2rem));
  min-height: 86px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
}

.brand { display: flex; align-items: center; gap: 0.9rem; }
.brand img { flex: 0 0 auto; filter: drop-shadow(0 5px 12px rgba(0,0,0,0.16)); }
.eyebrow { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; color: #aadddf; }
.brand-title { margin-top: 0.1rem; font-size: clamp(1.2rem, 2vw, 1.55rem); font-weight: 760; letter-spacing: -0.02em; }
.header-badges { display: flex; align-items: center; justify-content: flex-end; gap: 0.6rem; flex-wrap: wrap; }
.privacy-badge, .version-badge, .catalog-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 32px;
  padding: 0.34rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
.privacy-badge { color: #d5ffef; background: rgba(15, 128, 101, 0.34); border: 1px solid rgba(156, 255, 224, 0.22); }
.privacy-badge span { color: #62e6b5; font-size: 0.65rem; }
.version-badge { color: #dcebf4; background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.16); }
.catalog-chip { color: var(--teal-700); background: var(--teal-100); border: 1px solid #b8dddd; }
.catalog-chip.missing { color: var(--amber-700); background: var(--amber-100); border-color: #f0d68d; }
.catalog-actions { display: flex; align-items: center; justify-content: flex-end; gap: 0.55rem; flex-wrap: wrap; }

.page-shell { width: min(1440px, calc(100% - 2rem)); margin: 1.4rem auto 2.5rem; }

.workspace-card, .panel, .empty-dashboard {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--slate-200);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.workspace-card { padding: clamp(1rem, 2.2vw, 1.75rem); }
.section-heading, .dashboard-toolbar, .panel-heading, .detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.section-heading h1, .section-heading h2, .dashboard-toolbar h2 { display: inline; margin: 0 0 0 0.5rem; font-size: clamp(1.25rem, 2vw, 1.62rem); letter-spacing: -0.02em; }
.section-heading p, .panel-heading p { max-width: 850px; margin: 0.42rem 0 0; color: var(--slate-700); }
.step-number { color: var(--teal-700); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.06em; }

.week-controls {
  margin-top: 1.35rem;
  padding: 1rem;
  display: grid;
  grid-template-columns: minmax(165px, 220px) auto minmax(165px, 220px) minmax(240px, 1fr);
  align-items: end;
  gap: 0.75rem;
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  border-radius: 14px;
}
.week-controls label { display: grid; gap: 0.35rem; }
.week-controls label span { font-size: 0.82rem; font-weight: 760; color: var(--slate-700); }
.week-controls input {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.7rem;
  color: var(--slate-900);
  background: var(--white);
  border: 1px solid var(--slate-300);
  border-radius: 9px;
}
.date-arrow { align-self: center; padding-top: 1.2rem; color: var(--teal-700); font-weight: 800; }
.week-note { align-self: center; color: var(--slate-700); font-size: 0.9rem; }

.dropzone {
  min-height: 132px;
  margin-top: 1rem;
  padding: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  text-align: left;
  color: var(--navy-900);
  background: repeating-linear-gradient(135deg, #f8fcfd, #f8fcfd 12px, #f2f9fa 12px, #f2f9fa 24px);
  border: 2px dashed #8fc7ce;
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}
.dropzone:hover, .dropzone.dragging { background: var(--teal-100); border-color: var(--teal-600); transform: translateY(-1px); }
.dropzone strong { display: block; font-size: 1.03rem; }
.dropzone span { display: block; margin-top: 0.2rem; color: var(--slate-700); font-size: 0.9rem; }
.upload-symbol {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  color: var(--white);
  background: linear-gradient(145deg, var(--teal-600), var(--navy-800));
  border-radius: 14px;
  font-size: 1.55rem;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(11, 100, 119, 0.22);
}

.table-frame { position: relative; margin-top: 1rem; overflow: hidden; border: 1px solid var(--slate-200); border-radius: 12px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; background: var(--white); }
.data-table th, .data-table td { padding: 0.72rem 0.8rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--slate-200); }
.data-table th { color: #365263; background: #edf4f6; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.015em; white-space: nowrap; }
.data-table td { font-size: 0.9rem; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #f8fbfc; }
.data-table .number { text-align: right; white-space: nowrap; }
.money { font-variant-numeric: tabular-nums; }
.check-column { width: 56px; text-align: center !important; }
.file-table td:first-child { text-align: center; }
.file-table input[type="checkbox"] { width: 19px; height: 19px; accent-color: var(--teal-600); }
.file-name { max-width: 520px; overflow-wrap: anywhere; font-weight: 700; }
.subtle { margin-top: 0.12rem; color: var(--slate-500); font-size: 0.78rem; }
.table-empty { padding: 1.1rem; text-align: center; color: var(--slate-500); background: var(--white); }
.icon-button, .text-button { border: 0; cursor: pointer; }
.icon-button { width: 34px; height: 34px; border-radius: 8px; color: var(--slate-700); background: var(--slate-100); font-size: 1.25rem; }
.icon-button:hover { color: var(--red-700); background: var(--red-100); }
.text-button { padding: 0.4rem 0.55rem; color: var(--red-700); background: transparent; font-weight: 700; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0.15rem 0.48rem;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 800;
  white-space: nowrap;
}
.pill.success { color: var(--green-700); background: var(--green-100); }
.pill.warning { color: var(--amber-700); background: var(--amber-100); }
.pill.danger { color: var(--red-700); background: var(--red-100); }
.pill.neutral { color: var(--slate-700); background: var(--slate-100); }
.pill.new { color: var(--purple-700); background: var(--purple-100); }

.primary-actions, .export-actions, .history-actions { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; }
.primary-actions { margin-top: 1rem; justify-content: flex-end; }
.button {
  min-height: 44px;
  padding: 0.62rem 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 760;
  transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: 0.48; }
.button.primary { color: var(--white); background: linear-gradient(135deg, var(--teal-700), var(--navy-800)); box-shadow: 0 7px 18px rgba(11, 100, 119, 0.18); }
.button.secondary { color: var(--white); background: var(--navy-800); }
.button.ghost { color: var(--navy-900); background: var(--white); border-color: var(--slate-300); }
.button.small { min-height: 36px; padding: 0.42rem 0.7rem; font-size: 0.8rem; }

.empty-dashboard { margin-top: 1rem; padding: 2.6rem 1rem; text-align: center; box-shadow: none; border-style: dashed; }
.empty-dashboard h2 { margin: 0.45rem 0 0; font-size: 1.1rem; }
.empty-dashboard p { margin: 0.3rem 0 0; color: var(--slate-500); }
.empty-icon { width: 54px; height: 54px; margin: 0 auto; display: grid; place-items: center; color: var(--teal-700); background: var(--teal-100); border-radius: 16px; font-size: 1.65rem; }

#dashboard { scroll-margin-top: 1rem; margin-top: 1.2rem; }
.dashboard-toolbar { align-items: center; padding: 0 0.2rem 1rem; }
.dashboard-toolbar h2 span { color: var(--teal-700); font-size: 0.78em; font-weight: 650; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.85rem; }
.kpi-card { min-height: 138px; padding: 1rem; display: flex; flex-direction: column; background: var(--white); border: 1px solid var(--slate-200); border-radius: 15px; box-shadow: 0 7px 22px rgba(8, 38, 63, 0.055); }
.kpi-card span { color: var(--slate-700); font-size: 0.8rem; font-weight: 760; }
.kpi-card strong { margin: 0.22rem 0 auto; color: var(--navy-900); font-size: clamp(1.65rem, 3vw, 2.3rem); line-height: 1.15; letter-spacing: -0.04em; }
.kpi-card small { color: var(--slate-500); font-size: 0.76rem; line-height: 1.35; }
.kpi-card.emphasis { border-color: #92d0d2; background: linear-gradient(145deg, #ffffff, #eaf9f9); }
.kpi-card.risk { grid-column: span 2; color: var(--white); background: linear-gradient(135deg, #7a3341, #a95043); border-color: transparent; }
.kpi-card.risk span, .kpi-card.risk strong, .kpi-card.risk small { color: var(--white); }
.kpi-card.risk strong { font-size: clamp(1.65rem, 3.4vw, 2.5rem); }

.analysis-note { margin-top: 0.85rem; padding: 0.75rem 0.9rem; display: flex; align-items: center; gap: 0.7rem; color: var(--amber-700); background: var(--amber-100); border: 1px solid #f3d98e; border-radius: 12px; }
.analysis-note strong, .analysis-note span { display: block; }
.analysis-note span { margin-top: 0.08rem; font-size: 0.84rem; }
.note-icon { width: 30px; height: 30px; flex: 0 0 auto; display: grid; place-items: center; color: var(--white); background: var(--amber-700); border-radius: 50%; font-weight: 900; }

.chart-grid { margin-top: 0.85rem; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.85rem; }
.panel { padding: 1rem; box-shadow: 0 7px 22px rgba(8, 38, 63, 0.05); }
.panel-heading { align-items: baseline; }
.panel-heading h3 { margin: 0; color: var(--navy-900); font-size: 1rem; }
.panel-heading > span { color: var(--slate-500); font-size: 0.72rem; white-space: nowrap; }
.bar-list { margin-top: 1rem; display: grid; gap: 0.82rem; }
.bar-meta { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.7rem; font-size: 0.79rem; }
.bar-meta span { max-width: 72%; color: var(--slate-700); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-meta strong { color: var(--navy-900); white-space: nowrap; }
.bar-track { height: 8px; overflow: hidden; background: var(--slate-100); border-radius: 99px; }
.bar-track span { display: block; height: 100%; background: linear-gradient(90deg, var(--teal-700), #20a5a4); border-radius: inherit; }
.money-bars .bar-track span { background: linear-gradient(90deg, #a95043, #dd8659); }
.staff-bars .bar-track span { background: linear-gradient(90deg, var(--navy-800), #498ab1); }
.empty-small { color: var(--slate-500); font-size: 0.84rem; }

.table-panel { margin-top: 0.85rem; padding: 0; overflow: hidden; }
.table-panel .panel-heading { padding: 1rem; border-bottom: 1px solid var(--slate-200); }
.table-panel .data-table { min-width: 850px; }
.detail-heading { align-items: center; }
.privacy-toggle { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--slate-700); font-size: 0.82rem; font-weight: 650; cursor: pointer; }
.privacy-toggle input { width: 19px; height: 19px; accent-color: var(--teal-600); }

.history-card { margin-top: 1.2rem; }
.history-card .table-frame { margin-top: 1rem; }

.app-footer {
  padding: 1.15rem max(1rem, env(safe-area-inset-left)) calc(1.15rem + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  gap: 0.6rem 1.2rem;
  flex-wrap: wrap;
  color: #c5d9e4;
  background: var(--navy-950);
  font-size: 0.78rem;
}

.busy-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.8rem;
  color: var(--navy-900);
  background: rgba(242, 248, 251, 0.86);
  backdrop-filter: blur(5px);
  font-weight: 760;
}
.spinner { width: 42px; height: 42px; border: 4px solid #c9e6e8; border-top-color: var(--teal-700); border-radius: 50%; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  z-index: 110;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  max-width: min(420px, calc(100% - 2rem));
  padding: 0.78rem 0.95rem;
  color: var(--white);
  background: var(--navy-900);
  border-radius: 11px;
  box-shadow: 0 14px 34px rgba(8, 38, 63, 0.25);
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--green-700); }
.toast.warning { background: var(--amber-700); }
.toast.error { background: var(--red-700); }

.print-report { display: none; }

@media (max-width: 1050px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-card.risk { grid-column: span 2; }
  .chart-grid { grid-template-columns: 1fr 1fr; }
  .chart-grid .panel:last-child { grid-column: 1 / -1; }
  .week-controls { grid-template-columns: 1fr auto 1fr; }
  .week-note { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .header-inner, .page-shell { width: min(100% - 1rem, 1440px); }
  .header-inner { min-height: 76px; padding: 0.55rem 0; align-items: flex-start; }
  .brand img { width: 40px; height: 40px; }
  .eyebrow { font-size: 0.65rem; }
  .brand-title { font-size: 1.08rem; }
  .header-badges { display: none; }
  .page-shell { margin-top: 0.6rem; }
  .workspace-card { border-radius: 14px; }
  .section-heading, .dashboard-toolbar, .detail-heading { display: grid; }
  .catalog-actions { justify-content: flex-start; }
  .catalog-chip { width: max-content; }
  .week-controls { grid-template-columns: 1fr; align-items: stretch; }
  .date-arrow { display: none; }
  .dropzone { min-height: 116px; justify-content: flex-start; padding: 1rem; }
  .upload-symbol { width: 44px; height: 44px; }
  .file-table { min-width: 720px; }
  .file-table-frame { overflow-x: auto; }
  .primary-actions, .export-actions, .history-actions { display: grid; grid-template-columns: 1fr; width: 100%; }
  .button { width: 100%; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-card { min-height: 124px; }
  .kpi-card.risk { grid-column: 1 / -1; }
  .chart-grid { grid-template-columns: 1fr; }
  .chart-grid .panel:last-child { grid-column: auto; }
  .panel-heading > span { white-space: normal; }
  .privacy-toggle { align-items: flex-start; }
}

@media (max-width: 430px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-card.risk { grid-column: auto; }
  .dropzone { align-items: flex-start; }
  .section-heading h1, .section-heading h2, .dashboard-toolbar h2 { display: block; margin: 0.2rem 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media print {
  @page { size: A4 portrait; margin: 13mm 12mm; }
  body { color: #111; background: #fff; font-family: "Times New Roman", serif; font-size: 11pt; }
  body > *:not(.print-report) { display: none !important; }
  .print-report { display: block !important; }
  .print-header { padding-bottom: 8mm; display: flex; justify-content: space-between; align-items: flex-start; gap: 8mm; border-bottom: 2px solid #0b3558; }
  .print-org { font-size: 9pt; font-weight: 700; }
  .print-report h1 { margin: 2mm 0 0; font-size: 16pt; color: #0b3558; }
  .print-week { white-space: nowrap; font-weight: 700; }
  .print-kpis { margin: 6mm 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 3mm; }
  .print-kpis div { padding: 3mm; border: 1px solid #b8c5cc; }
  .print-kpis span { display: block; font-size: 8pt; color: #444; }
  .print-kpis strong { display: block; margin-top: 1mm; font-size: 13pt; color: #0b3558; }
  .print-report h2 { margin: 6mm 0 2mm; font-size: 12pt; color: #0b3558; }
  .print-report p { margin: 0 0 3mm; text-align: justify; }
  .print-note { padding: 2.5mm; background: #fff4d6; border-left: 3px solid #9a5b00; }
  .print-report table { width: 100%; border-collapse: collapse; page-break-inside: avoid; }
  .print-report th, .print-report td { padding: 1.8mm; border: 1px solid #8d9aa1; font-size: 8.5pt; vertical-align: top; }
  .print-report th { color: #fff; background: #0b6477 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-footer { margin-top: 8mm; padding-top: 2mm; border-top: 1px solid #bbb; text-align: right; color: #555; font-size: 8pt; }
}
