:root {
  --bg: #07080b;
  --panel: rgba(21, 23, 29, 0.84);
  --panel-strong: #15171d;
  --panel-soft: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.11);
  --line-strong: rgba(255, 255, 255, 0.2);
  --text: #f7f7f8;
  --muted: #a5a7af;
  --red: #ee2536;
  --red-dark: #a90f1d;
  --red-soft: rgba(238, 37, 54, 0.14);
  --green: #36d486;
  --amber: #ffbd4a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
  --radius: 24px;
  --radius-sm: 15px;
}

* { box-sizing: border-box; }

html { color-scheme: dark; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 80% -10%, rgba(238, 37, 54, 0.17), transparent 34rem),
    radial-gradient(circle at 15% 10%, rgba(255, 255, 255, 0.055), transparent 26rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button { color: inherit; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 20px;
  border-right: 1px solid var(--line);
  background: rgba(7, 8, 11, 0.8);
  backdrop-filter: blur(22px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 6px 34px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  font-weight: 900;
  letter-spacing: -0.08em;
  background: linear-gradient(145deg, #ff5360, #bd0b1a);
  box-shadow: 0 10px 30px rgba(238, 37, 54, 0.35);
}

.brand-copy strong { display: block; letter-spacing: 0.02em; }
.brand-copy span { display: block; margin-top: 2px; color: var(--muted); font-size: 0.77rem; }

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

.nav-button {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 13px 14px;
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: 160ms ease;
}

.nav-button:hover { color: var(--text); background: var(--panel-soft); }
.nav-button.active { color: #fff; border-color: rgba(238, 37, 54, 0.24); background: var(--red-soft); }
.nav-icon { width: 22px; text-align: center; }

.sidebar-footer {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 25px;
}

.connection-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.035);
}

.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 16px currentColor; }
.connected .connection-dot { background: var(--green); }
.offline .connection-dot { background: var(--red); }

.main { min-width: 0; padding: 32px clamp(22px, 4vw, 62px) 70px; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #ff7c87;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(1.8rem, 4vw, 3.05rem); line-height: 1.03; letter-spacing: -0.045em; }
h2 { margin-bottom: 8px; font-size: 1.18rem; letter-spacing: -0.02em; }
h3 { margin-bottom: 6px; font-size: 0.96rem; }
.subtitle { margin: 0; color: var(--muted); max-width: 720px; line-height: 1.55; }

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  font-weight: 700;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.button:hover { transform: translateY(-1px); border-color: var(--line-strong); background: rgba(255, 255, 255, 0.08); }
.button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.button.primary { border-color: #f14856; background: linear-gradient(145deg, #f23b4b, #c31120); box-shadow: 0 12px 32px rgba(238, 37, 54, 0.23); }
.button.ghost { background: transparent; }
.button.danger { color: #ff9ca4; }
.button.small { min-height: 36px; padding: 0 12px; font-size: 0.82rem; }
.icon-button { width: 38px; min-height: 38px; padding: 0; }

.view { display: none; }
.view.active { display: block; animation: fade 190ms ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.065), rgba(255, 255, 255, 0.025));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.kpi-card { padding: 20px; min-height: 132px; }
.kpi-label { color: var(--muted); font-size: 0.79rem; font-weight: 700; }
.kpi-value { margin: 18px 0 4px; font-size: clamp(1.45rem, 2.8vw, 2.2rem); font-weight: 850; letter-spacing: -0.045em; }
.kpi-note { color: var(--muted); font-size: 0.76rem; }
.kpi-card.accent { border-color: rgba(238, 37, 54, 0.33); background: linear-gradient(145deg, rgba(238, 37, 54, 0.2), rgba(238, 37, 54, 0.055)); }

.panel { padding: clamp(18px, 2.4vw, 28px); margin-bottom: 18px; }
.panel-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 22px; }
.panel-header p { margin: 0; color: var(--muted); font-size: 0.86rem; line-height: 1.45; }

.empty-state {
  padding: 52px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 18px;
}
.empty-state strong { display: block; margin-bottom: 7px; color: var(--text); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 17px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 13px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 0.84rem; white-space: nowrap; }
th { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase; background: rgba(255, 255, 255, 0.035); }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 130ms ease; }
tbody tr:hover { background: rgba(255, 255, 255, 0.025); }

.status { display: inline-flex; padding: 6px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 800; background: rgba(255, 189, 74, 0.13); color: #ffd58d; }
.status.saved { color: #91efbb; background: rgba(54, 212, 134, 0.12); }

.calculator-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
.calculator-main { min-width: 0; }
.summary-rail { position: sticky; top: 24px; }

.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 15px; }
.field { grid-column: span 4; min-width: 0; }
.field.wide { grid-column: span 8; }
.field.full { grid-column: 1 / -1; }
.field.half { grid-column: span 6; }
.field.quarter { grid-column: span 3; }

label { display: block; margin: 0 0 7px; color: #d7d8dc; font-size: 0.78rem; font-weight: 750; }
.hint { display: block; margin-top: 6px; color: var(--muted); font-size: 0.69rem; line-height: 1.35; }

input, select, textarea {
  width: 100%;
  min-height: 45px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: 0;
  color: var(--text);
  background: rgba(0, 0, 0, 0.22);
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: rgba(238, 37, 54, 0.72); box-shadow: 0 0 0 3px rgba(238, 37, 54, 0.11); background: rgba(0, 0, 0, 0.32); }
input[readonly] { color: var(--muted); background: rgba(255, 255, 255, 0.025); }

.segmented { display: inline-grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 15px; background: rgba(0, 0, 0, 0.2); }
.segmented button { min-height: 38px; padding: 0 14px; border: 0; border-radius: 11px; color: var(--muted); background: transparent; cursor: pointer; font-weight: 750; }
.segmented button.active { color: #fff; background: var(--red); box-shadow: 0 7px 18px rgba(238, 37, 54, 0.26); }

.section-rule { height: 1px; margin: 23px 0; background: var(--line); }

.shift-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr .9fr .8fr auto; gap: 9px; align-items: end; padding: 12px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255, 255, 255, 0.025); }
.shift-row + .shift-row { margin-top: 9px; }
.shift-row label { font-size: 0.68rem; }

.summary-card { padding: 23px; border-color: rgba(238, 37, 54, 0.3); }
.summary-card h2 { margin-bottom: 20px; }
.summary-primary { padding: 18px; margin-bottom: 17px; border-radius: 18px; background: linear-gradient(145deg, rgba(238, 37, 54, 0.24), rgba(238, 37, 54, 0.08)); }
.summary-primary span { color: #ffb0b7; font-size: 0.74rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.07em; }
.summary-primary strong { display: block; margin-top: 7px; font-size: 2rem; letter-spacing: -0.05em; }
.summary-list { display: grid; gap: 0; }
.summary-row { display: flex; justify-content: space-between; gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 0.82rem; }
.summary-row:last-child { border-bottom: 0; }
.summary-row span { color: var(--muted); }
.summary-row strong { text-align: right; }
.summary-actions { display: grid; gap: 9px; margin-top: 18px; }
.validity { margin-top: 14px; padding: 11px 12px; border-radius: 12px; color: #ffcf83; background: rgba(255, 189, 74, 0.1); font-size: 0.76rem; line-height: 1.4; }
.validity.ok { color: #90efbb; background: rgba(54, 212, 134, 0.1); }

.cost-breakdown { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cost-item { padding: 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.035); }
.cost-item span { display: block; color: var(--muted); font-size: 0.72rem; }
.cost-item strong { display: block; margin-top: 6px; font-size: 1rem; }

.settings-note { padding: 14px 16px; margin-bottom: 18px; border-left: 3px solid var(--red); border-radius: 0 12px 12px 0; color: var(--muted); background: var(--red-soft); font-size: 0.82rem; line-height: 1.5; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.74);
  backdrop-filter: blur(11px);
  z-index: 100;
}
.modal-backdrop.open { display: grid; }
.modal { width: min(560px, 100%); padding: 28px; }
.modal h2 { font-size: 1.42rem; }
.modal p { color: var(--muted); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 21px; }

.toast-stack { position: fixed; right: 22px; bottom: 22px; display: grid; gap: 10px; z-index: 200; }
.toast { width: min(380px, calc(100vw - 44px)); padding: 14px 16px; border: 1px solid var(--line-strong); border-radius: 14px; background: #1a1c22; box-shadow: var(--shadow); animation: toast-in 180ms ease; font-size: 0.84rem; }
.toast.error { border-color: rgba(238, 37, 54, 0.55); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.mobile-nav { display: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.text-red { color: #ff8b95; }
.text-green { color: var(--green); }
.numeric { font-variant-numeric: tabular-nums; }

@media (max-width: 1120px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calculator-layout { grid-template-columns: 1fr; }
  .summary-rail { position: static; }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main { padding: 22px 16px 92px; }
  .topbar { display: block; }
  .topbar .actions { justify-content: flex-start; margin-top: 18px; }
  .mobile-nav { position: fixed; display: grid; grid-template-columns: repeat(3, 1fr); left: 12px; right: 12px; bottom: 12px; z-index: 40; padding: 6px; border: 1px solid var(--line); border-radius: 18px; background: rgba(17, 18, 23, 0.9); backdrop-filter: blur(20px); box-shadow: var(--shadow); }
  .mobile-nav .nav-button { justify-content: center; padding: 10px 6px; font-size: 0.7rem; }
  .mobile-nav .nav-icon { display: none; }
  .field, .field.wide, .field.half, .field.quarter { grid-column: 1 / -1; }
  .shift-row { grid-template-columns: 1fr 1fr; }
  .shift-row .shift-date { grid-column: 1 / -1; }
  .shift-row .remove-shift { grid-column: 2; justify-self: end; }
}

@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .panel { padding: 18px; border-radius: 19px; }
  .panel-header { display: block; }
  .panel-header .button { margin-top: 12px; }
  .segmented { width: 100%; }
  .cost-breakdown { grid-template-columns: 1fr; }
  .actions .button { flex: 1 1 auto; }
}

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