:root {
  --navy: #11103f;
  --navy-2: #1a1957;
  --pink: #f51f4a;
  --pink-soft: #fff0f3;
  --cream: #f7f2ec;
  --paper: #ffffff;
  --ink: #18172a;
  --muted: #736f7d;
  --line: #e8e4eb;
  --success: #0a8f62;
  --warning: #bb6b00;
  --danger: #c92945;
  --shadow: 0 18px 45px rgba(25, 17, 52, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #f6f5f8;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.loading-screen {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  color: var(--navy);
}
.loading-mark, .brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 18px 4px 18px 18px;
  background: var(--pink);
  color: white;
  font-size: 27px;
  font-weight: 900;
}

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: 260px;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  color: white;
  background:
    radial-gradient(circle at 0 100%, rgba(245, 31, 74, 0.18), transparent 34%),
    var(--navy);
}
.brand { display: flex; align-items: center; gap: 13px; margin-bottom: 36px; }
.brand strong { display: block; font-size: 22px; line-height: 1; }
.brand span { display: block; margin-top: 5px; color: #d6d4e8; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.brand-mark { width: 44px; height: 44px; border-radius: 14px 4px 14px 14px; font-size: 23px; }

nav { display: grid; gap: 6px; }
.nav-item {
  width: 100%;
  padding: 13px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  border-radius: 12px;
  color: #d8d7e9;
  background: transparent;
  text-align: left;
  transition: 160ms ease;
}
.nav-item:hover, .nav-item.active { color: white; background: rgba(255,255,255,0.1); }
.nav-icon { width: 24px; text-align: center; }
.sidebar-footer { margin-top: auto; display: grid; gap: 8px; }
.sidebar-footer span { padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.1); font-weight: 700; }
.sidebar-footer small { color: #aaa8c6; }

.workspace { margin-left: 260px; min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 82px;
  padding: 18px 34px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.93);
  backdrop-filter: blur(14px);
}
.topbar small, .topbar strong { display: block; }
.topbar small { color: var(--muted); }
.topbar strong { margin-top: 3px; }
.topbar select { min-width: 220px; min-height: 36px; margin-top: 3px; padding: 6px 34px 6px 9px; border: 0; background-color: transparent; color: var(--navy); font-weight: 800; }
.topbar-actions { display: flex; gap: 10px; }
.file-button input { display: none; }

main { padding: 32px 34px 54px; }
.page-header { margin-bottom: 28px; display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.page-header h1 { margin: 0; color: var(--navy); font-size: clamp(28px, 4vw, 40px); letter-spacing: -0.04em; }
.page-header p { margin: 8px 0 0; color: var(--muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.button {
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 750;
  text-decoration: none;
}
.button.primary { background: var(--pink); color: white; }
.button.primary:hover { background: #dd123d; }
.button.secondary { border-color: var(--line); background: white; color: var(--navy); }
.button.danger { background: #fff0f2; color: var(--danger); }
.button.small { min-height: 34px; padding: 7px 11px; font-size: 13px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--navy); }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 24px; }
.metric-card, .panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.metric-card { padding: 22px; }
.metric-card span { color: var(--muted); font-size: 13px; }
.metric-card strong { display: block; margin-top: 9px; color: var(--navy); font-size: 28px; }
.metric-card em { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; font-style: normal; }
.metric-card.accent { color: white; background: var(--navy); border-color: var(--navy); }
.metric-card.accent span, .metric-card.accent em { color: #c9c7dc; }
.metric-card.accent strong { color: white; }

.dashboard-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.panel { padding: 24px; }
.panel-header { margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.panel h2 { margin: 0; color: var(--navy); font-size: 20px; }
.panel-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.alert-list { display: grid; gap: 11px; }
.alert {
  padding: 14px 15px;
  display: flex;
  gap: 11px;
  border-radius: 12px;
  background: #fff8e9;
  color: #72500c;
}
.alert.danger { background: #fff0f2; color: #8a2438; }
.alert.success { background: #eaf8f2; color: #096944; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.quick-action { padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #faf9fb; text-align: left; }
.quick-action strong { display: block; color: var(--navy); }
.quick-action span { display: block; margin-top: 6px; color: var(--muted); font-size: 13px; }

.table-toolbar { margin-bottom: 16px; display: flex; justify-content: space-between; gap: 12px; }
.search { position: relative; width: min(460px, 100%); }
.search input { width: 100%; padding-left: 40px; }
.search::before { content: "⌕"; position: absolute; left: 14px; top: 10px; color: var(--muted); }
input, select {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid #dcd8e1;
  border-radius: 10px;
  background: white;
  color: var(--ink);
}
input:focus, select:focus { outline: 3px solid rgba(245,31,74,.12); border-color: var(--pink); }
input[readonly] { color: var(--navy); background: #f5f3f7; font-weight: 750; cursor: not-allowed; }
.money-input { font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 15px; background: white; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); background: #faf9fb; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
td { font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fffafb; }
.cell-main { font-weight: 750; color: var(--navy); }
.cell-actions { display: flex; gap: 6px; justify-content: end; }
.status { display: inline-flex; padding: 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.status.ok { color: #08704b; background: #e9f8f2; }
.status.warn { color: #97620b; background: #fff4d8; }
.status.bad { color: #9c2740; background: #ffedf1; }
.empty { padding: 42px; color: var(--muted); text-align: center; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.field { display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field label { color: var(--navy); font-size: 13px; font-weight: 750; }
.field small { color: var(--muted); line-height: 1.35; }
.switch-row { padding: 17px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border: 1px solid var(--line); border-radius: 12px; }
.switch-row input { width: 21px; min-height: 21px; accent-color: var(--pink); }
.form-actions { margin-top: 22px; display: flex; gap: 10px; justify-content: end; }

.simulator-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.results { position: sticky; top: 105px; color: white; background: var(--navy); border-color: var(--navy); }
.result-price { padding: 20px 0 24px; border-bottom: 1px solid rgba(255,255,255,.14); }
.result-price span { color: #c7c5da; }
.result-price strong { display: block; margin-top: 7px; color: white; font-size: clamp(38px,5vw,58px); letter-spacing: -.05em; }
.result-grid { padding-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.result-item span { display: block; color: #aaa8c6; font-size: 12px; }
.result-item strong { display: block; margin-top: 5px; font-size: 18px; }
.formula-bar { margin-top: 20px; padding: 14px; border-radius: 11px; color: #d5d4e5; background: rgba(255,255,255,.08); font-size: 12px; line-height: 1.5; }
.save-hint { display: block; margin-top: 12px; color: #aaa8c6; line-height: 1.45; }

dialog { width: min(680px, calc(100% - 28px)); max-height: 90vh; padding: 0; border: 0; border-radius: 18px; box-shadow: 0 25px 80px rgba(18,10,45,.28); }
dialog::backdrop { background: rgba(10,8,31,.58); backdrop-filter: blur(3px); }
.modal-header { padding: 22px 24px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; color: var(--navy); }
.modal-body { padding: 24px; max-height: 68vh; overflow: auto; }
.modal-footer { padding: 16px 24px; display: flex; justify-content: end; gap: 10px; border-top: 1px solid var(--line); background: #faf9fb; }
.form-feedback { flex: 1 1 100%; align-self: center; margin-right: auto; font-size: .86rem; font-weight: 700; }
.form-feedback.error { color: #b42318; }
.composition-list { display: grid; gap: 10px; }
.composition-row { display: grid; grid-template-columns: 1fr 130px 44px; gap: 8px; align-items: center; }
.history-grid { display: grid; gap: 8px; }
.history-row { display: grid; grid-template-columns: 130px 1fr 1fr; gap: 10px; align-items: center; }
.history-row strong { color: var(--navy); font-size: 13px; text-transform: capitalize; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 100; max-width: 360px; padding: 14px 17px; border-radius: 12px; color: white; background: var(--navy); box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: 180ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.mobile-only { display: none; }

@media (max-width: 1100px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .dashboard-grid, .simulator-layout { grid-template-columns: 1fr; }
  .results { position: static; }
}

@media (max-width: 760px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .sidebar { transform: translateX(-100%); transition: 180ms ease; }
  .sidebar.open { transform: translateX(0); }
  .workspace { margin-left: 0; }
  .topbar { padding: 14px 18px; }
  .topbar-actions { display: none; }
  main { padding: 24px 17px 42px; }
  .page-header { align-items: stretch; flex-direction: column; }
  .metrics, .form-grid, .quick-actions { grid-template-columns: 1fr; }
  .panel { padding: 19px; }
  .table-toolbar { flex-direction: column; }
  .composition-row { grid-template-columns: 1fr 90px 42px; }
}
