:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef3ff;
  --text: #162033;
  --muted: #64748b;
  --line: #dce4f2;
  --primary: #2457d6;
  --primary-dark: #153a9f;
  --primary-soft: #e9efff;
  --success: #0f9f6e;
  --warning: #b7791f;
  --danger: #c2410c;
  --shadow: 0 18px 45px rgba(15, 23, 42, .08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --sidebar: #111827;
  --sidebar-soft: #1f2937;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(36, 87, 214, .12), transparent 32rem),
    radial-gradient(circle at bottom left, rgba(15, 159, 110, .10), transparent 34rem),
    var(--bg);
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px;
  background: linear-gradient(180deg, var(--sidebar), #0b1120);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}

.brand-block {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-radius: 22px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .12);
}

.brand-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: #fff;
  color: var(--primary);
  font-size: 24px;
}

.brand-block strong,
.brand-block small {
  display: block;
}

.brand-block strong {
  font-size: 16px;
}

.brand-block small {
  margin-top: 4px;
  color: #cbd5e1;
  font-size: 12px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  border: 0;
  border-radius: 16px;
  padding: 13px 14px;
  text-align: left;
  background: transparent;
  color: #cbd5e1;
  transition: .2s ease;
}

.nav-tab:hover,
.nav-tab.active {
  background: rgba(255, 255, 255, .11);
  color: #fff;
  transform: translateX(2px);
}

.sidebar-card {
  margin-top: auto;
  padding: 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .12);
}

.sidebar-card p {
  margin: 8px 0 0;
  color: #dbeafe;
  line-height: 1.55;
  font-size: 13px;
}

.main-content {
  padding: 32px;
  min-width: 0;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 30px;
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, .88);
  border: 1px solid rgba(255, 255, 255, .7);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  margin-bottom: 24px;
}

.hero h1 {
  margin: 8px 0 12px;
  font-size: clamp(30px, 4vw, 52px);
  line-height: 1;
  letter-spacing: -.05em;
}

.hero p {
  max-width: 850px;
  color: var(--muted);
  line-height: 1.7;
  margin: 0;
}

.hero-actions,
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--primary);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 11px;
}

.eyebrow::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: currentColor;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: fadeIn .2s ease;
}

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

.grid,
.dashboard-grid,
.form-grid,
.info-grid,
.quote-grid {
  display: grid;
  gap: 18px;
}

.kpi-grid {
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  margin-bottom: 18px;
}

.dashboard-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .85fr);
  margin-bottom: 18px;
}

.info-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}

.quote-grid {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  margin-bottom: 18px;
}

.card,
.input-card,
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 34px rgba(15, 23, 42, .05);
}

.card {
  padding: 22px;
}

.card + .card {
  margin-top: 18px;
}

.card h2,
.card h3,
.section-head h2 {
  margin: 8px 0 10px;
  letter-spacing: -.035em;
}

.card h2 {
  font-size: 24px;
}

.card h3 {
  font-size: 20px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 16px;
}

.kpi-card {
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: "";
  position: absolute;
  right: -18px;
  top: -18px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary-soft);
}

.kpi-card small,
.metric-card small {
  display: block;
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 8px;
}

.kpi-card strong,
.metric-card strong {
  display: block;
  font-size: 26px;
  letter-spacing: -.045em;
  line-height: 1.05;
}

.kpi-card span,
.metric-card span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.section-head {
  padding: 24px;
  margin-bottom: 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
}

.section-head p {
  color: var(--muted);
  line-height: 1.7;
  margin: 0;
  max-width: 900px;
}

.input-card {
  padding: 16px;
}

.input-card label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  font-weight: 750;
  font-size: 14px;
  margin-bottom: 9px;
}

.input-card label span:last-child {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.input-card input,
.input-card select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: #f8fafc;
  color: var(--text);
  outline: none;
  transition: .2s ease;
}

.input-card input:focus,
.input-card select:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(36, 87, 214, .1);
}

.help-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 16px;
  border: 1px solid var(--line);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  background: #fff;
}

.data-table th,
.data-table td {
  padding: 13px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.data-table th {
  background: #f8fafc;
  color: #334155;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.data-table td:nth-child(2),
.data-table td:nth-child(3),
.data-table td:nth-child(4) {
  white-space: nowrap;
}

.bar-cell {
  min-width: 160px;
}

.bar-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  margin-top: 6px;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
}

.chart-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 24px;
  align-items: center;
}

.donut-wrap {
  position: relative;
  width: 240px;
  height: 240px;
}

.donut {
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: conic-gradient(var(--primary) 0deg, var(--primary) 360deg);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.04);
}

.donut::after {
  content: "";
  position: absolute;
  inset: 46px;
  background: #fff;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--line);
}

.donut-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  pointer-events: none;
  z-index: 1;
}

.donut-center span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.donut-center strong {
  font-size: 22px;
  letter-spacing: -.04em;
  margin-top: 4px;
}

.legend {
  display: grid;
  gap: 10px;
}

.legend-item {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 5px;
  background: var(--primary);
}

.warnings {
  display: grid;
  gap: 10px;
}

.notice {
  padding: 13px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  line-height: 1.55;
  font-size: 14px;
}

.notice.ok {
  background: #ecfdf5;
  border-color: #bbf7d0;
  color: #065f46;
}

.notice.warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.notice.danger {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #9a3412;
}

.metric-card {
  padding: 18px;
  border-radius: 18px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.result-card {
  margin-top: 18px;
}

.check-list {
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 10px;
  margin: 0;
}

.check-list li {
  position: relative;
  padding-left: 28px;
  color: var(--muted);
  line-height: 1.6;
}

.check-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--success);
  font-weight: 900;
}

.formula-list {
  display: grid;
  gap: 10px;
}

.formula-list p {
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.6;
}

.muted {
  color: var(--muted);
  line-height: 1.7;
}

.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  padding: 10px 17px;
  border: 1px solid transparent;
  font-weight: 850;
  white-space: nowrap;
  transition: .2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 14px 26px rgba(36, 87, 214, .25);
}

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

.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

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

.file-btn {
  cursor: pointer;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 340px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: .22s ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .main-content {
    padding: 20px;
  }

  .kpi-grid,
  .dashboard-grid,
  .form-grid,
  .info-grid,
  .quote-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .main-content,
  .sidebar {
    padding: 16px;
  }

  .hero {
    flex-direction: column;
    padding: 22px;
  }

  .hero-actions,
  .export-actions {
    width: 100%;
    justify-content: stretch;
  }

  .btn {
    width: 100%;
  }

  .nav-tabs,
  .kpi-grid,
  .dashboard-grid,
  .form-grid,
  .info-grid,
  .quote-grid,
  .chart-layout {
    grid-template-columns: 1fr;
  }

  .donut-wrap,
  .donut {
    width: 220px;
    height: 220px;
    margin: 0 auto;
  }
}

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .hero-actions,
  .export-actions,
  .toast {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .main-content {
    padding: 0;
  }

  .panel {
    display: block !important;
    page-break-before: auto;
  }

  .card,
  .input-card,
  .kpi-card,
  .hero,
  .section-head {
    box-shadow: none;
    border-color: #ddd;
  }
}
