:root {
  --bg: #f4f7fb;
  --bg-strong: #eaf0fb;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-strong: #ffffff;
  --card: #ffffff;
  --card-alt: #f8fafc;
  --line: rgba(15, 23, 42, 0.08);
  --text: #111827;
  --muted: #5b6475;
  --muted-soft: #7a869a;
  --primary: #0f766e;
  --primary-deep: #0d5f59;
  --primary-soft: rgba(15, 118, 110, 0.12);
  --accent: #f59e0b;
  --green: #16a34a;
  --red: #dc2626;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

body.dark {
  --bg: #07111f;
  --bg-strong: #0d1727;
  --panel: rgba(15, 23, 42, 0.68);
  --panel-strong: #121f2d;
  --card: #132238;
  --card-alt: #182c42;
  --line: rgba(148, 163, 184, 0.16);
  --text: #edf6ff;
  --muted: #c6d4ea;
  --muted-soft: #9fb2cc;
  --primary: #2dd4bf;
  --primary-deep: #6ee7d8;
  --primary-soft: rgba(45, 212, 191, 0.12);
  --accent: #fbbf24;
  --green: #34d399;
  --red: #f87171;
  --shadow: 0 22px 48px rgba(2, 6, 23, 0.45);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(45, 212, 191, 0.14), transparent 28%),
    radial-gradient(circle at bottom right, rgba(251, 191, 36, 0.12), transparent 22%),
    var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  max-width: 1300px;
  margin: 0 auto;
  padding: 28px 18px 40px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  margin-bottom: 22px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

body.dark .topbar {
  background: rgba(15, 23, 42, 0.72);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: white;
  box-shadow: 0 10px 18px rgba(15, 118, 110, 0.3);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 14px;
  background: var(--card-alt);
  border: 1px solid var(--line);
}

.nav-link {
  padding: 10px 16px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  transition: 180ms ease;
}

.nav-link:hover,
.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary-deep);
}

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

.icon-button,
.theme-toggle,
.calculate,
.download,
.save-history,
.segment {
  border: 0;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--card-alt);
  border: 1px solid var(--line);
  color: var(--text);
}

.icon-button:hover,
.theme-toggle:hover,
.calculate:hover,
.download:hover,
.save-history:hover,
.segment:hover {
  transform: translateY(-1px);
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--card-alt), var(--panel));
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 800;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 0 18px;
}

.hero-copy {
  flex: 1;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.12em;
  font-weight: 800;
  color: var(--primary);
}

.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.3rem);
  line-height: 1.06;
}

.subhead {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 380px) minmax(0, 1.5fr);
  gap: 20px;
  margin-top: 10px;
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 20px;
  box-shadow: var(--shadow);
}

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

.card h2,
.card h3 {
  margin: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chip.status-online {
  background: rgba(52, 211, 153, 0.12);
  color: var(--green);
}

.chip.accent {
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent);
}

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

.form-group:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--muted);
}

input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1.5px solid rgba(148, 163, 184, 0.32);
  border-radius: 14px;
  background: var(--card-alt);
  color: var(--text);
  outline: none;
}

input:focus {
  border-color: rgba(15, 118, 110, 0.7);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

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

.segment {
  min-height: 46px;
  border-radius: 12px;
  background: var(--card-alt);
  color: var(--muted);
  font-weight: 800;
  border: 1px solid var(--line);
}

.segment.selected {
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: white;
  box-shadow: 0 12px 22px rgba(15, 118, 110, 0.18);
}

.free-note {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.18);
}

.free-note > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: rgba(34, 197, 94, 0.12);
  font-size: 1.1rem;
}

.free-note strong,
.free-note small {
  display: block;
}

.free-note strong {
  color: var(--green);
}

.free-note small {
  color: var(--muted);
  margin-top: 2px;
}

.calculate,
.download,
.save-history {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  width: 100%;
  border-radius: 14px;
  font-weight: 800;
  margin-top: 14px;
}

.calculate {
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: white;
  box-shadow: 0 14px 28px rgba(15, 118, 110, 0.22);
}

.error {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--red);
  font-weight: 700;
  font-size: 0.85rem;
}

.breakdown-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.cycle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-alt);
}

th,
td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th {
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(148, 163, 184, 0.04);
}

tbody tr:last-child td {
  border-bottom: none;
}

.totals {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 0 4px;
}

.totals > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--card-alt);
  color: var(--muted);
}

.totals strong {
  color: var(--text);
  font-size: 1.02rem;
}

.grand {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(45, 212, 191, 0.08));
  border: 1px solid rgba(15, 118, 110, 0.18);
}

.grand span,
.grand strong {
  color: var(--primary-deep);
}

.action-row {
  display: flex;
  gap: 12px;
}

.download {
  margin-top: 0;
  background: rgba(245, 158, 11, 0.1);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.save-history {
  margin-top: 0;
  background: linear-gradient(135deg, #0f172a, #1f2937);
  color: white;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-top: 24px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.stat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-size: 1.35rem;
}

.stat small {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
}

.stat strong {
  font-size: 1.1rem;
}

.green {
  color: var(--green) !important;
}

.slabs-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-top: 8px;
}

.slab-card {
  min-height: 100%;
}

.slab-card h3 {
  margin-bottom: 16px;
  color: var(--text);
}

.slab-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.slab-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.75fr) minmax(0, 0.9fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card-alt);
}

.slab-range,
.slab-note {
  font-size: 0.82rem;
  color: var(--muted);
}

.slab-rate {
  font-weight: 800;
  color: var(--text);
}

.info-box {
  margin-top: 22px;
  padding: 20px 22px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.09), rgba(251, 191, 36, 0.08));
  border: 1px solid rgba(15, 118, 110, 0.12);
}

.info-box h3 {
  margin: 0 0 14px;
}

.info-box ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.7;
}

.history-container {
  margin-top: 10px;
}

.history-list {
  display: grid;
  gap: 14px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
}

.history-item strong,
.history-item small {
  display: block;
}

.history-item small {
  margin-top: 4px;
  color: var(--muted);
}

.history-load {
  min-width: 128px;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card-alt);
  color: var(--text);
  font-weight: 700;
}

.empty-state {
  margin: 0;
  padding: 18px 16px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
}

footer {
  margin-top: 28px;
  padding: 18px 10px 6px;
  text-align: center;
  color: var(--muted-soft);
  font-size: 0.9rem;
}

@media (max-width: 980px) {
  .dashboard-grid,
  .slabs-grid,
  .stats {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-wrap: wrap;
    justify-content: center;
  }

  .nav-links {
    order: 3;
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 18px 12px 26px;
  }

  .hero,
  .card-title-row,
  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .slab-row {
    grid-template-columns: 1fr;
  }

  .nav-links {
    overflow-x: auto;
    justify-content: flex-start;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
