:root {
  color-scheme: dark;
  --bg: #11151d;
  --panel: #151b25;
  --panel-soft: #192231;
  --text: #eef4ff;
  --muted: #99a7c4;
  --cyan: #2ed3b7;
  --blue: #7ea7ff;
  --yellow: #ffcf57;
  --red: #ff667a;
  --line: rgba(255, 255, 255, 0.08);
  --shadow-dark: rgba(3, 6, 12, 0.8);
  --shadow-light: rgba(255, 255, 255, 0.06);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 22% 10%, rgba(46, 211, 183, 0.10), transparent 32rem),
    radial-gradient(circle at 82% 0%, rgba(255, 207, 87, 0.08), transparent 28rem),
    var(--bg);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 236px 1fr; }
.content { min-width: 0; padding: 30px; max-width: 1440px; width: 100%; }
.content.centered { display: grid; place-items: center; max-width: none; }

.sidebar {
  min-width: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: rgba(16, 21, 31, 0.82);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 800; margin-bottom: 30px; }
.brand-mark, .login-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(145deg, #202a3a, #111722);
  box-shadow: 9px 9px 18px var(--shadow-dark), -7px -7px 16px var(--shadow-light);
}
.nav { display: grid; gap: 8px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
}
.nav a:hover { color: var(--text); background: var(--panel-soft); }
.nav svg, button svg { width: 18px; height: 18px; }
.logout-form { position: absolute; left: 18px; bottom: 24px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.eyebrow { margin: 0 0 5px; color: var(--cyan); text-transform: uppercase; font-size: 12px; font-weight: 700; letter-spacing: 0; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: clamp(30px, 4vw, 48px); }
h2 { font-size: 18px; }

.metric-grid, .comparison-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.comparison-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.metric, .panel, .chart-panel, .table-panel, .login-panel {
  background: linear-gradient(145deg, #182131, #111721);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 14px 14px 30px var(--shadow-dark), -10px -10px 24px var(--shadow-light);
}
.metric { min-height: 132px; padding: 18px; display: grid; align-content: space-between; }
.metric span, .metric small, .muted { color: var(--muted); }
.metric strong { font-size: 28px; white-space: nowrap; }
.metric.hot strong { color: var(--yellow); }
.metric.good strong { color: var(--cyan); }
.winner-card { border-color: rgba(46, 211, 183, 0.6); }

.chart-panel { height: 380px; padding: 20px; margin-bottom: 18px; }
.chart-panel canvas { width: 100%; height: 300px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-head span { color: var(--muted); }

.cycle-overview, .month-panel { margin-bottom: 18px; }
.cycle-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 20px;
}
.cycle-head > span {
  flex: 0 0 auto;
  color: var(--cyan);
  font-weight: 700;
}
.cycle-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  gap: 22px;
  align-items: stretch;
}
.cycle-primary, .cycle-compare {
  min-width: 0;
  display: grid;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.cycle-primary span, .cycle-primary small,
.cycle-compare span, .cycle-compare small,
.cycle-kpis span, .cycle-kpis small {
  color: var(--muted);
}
.cycle-primary strong {
  color: var(--yellow);
  font-size: clamp(34px, 5vw, 56px);
  line-height: 1;
}
.cycle-compare strong {
  color: var(--text);
  font-size: 28px;
}
.cycle-compare.good strong { color: var(--cyan); }
.cycle-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 22px;
}
.cycle-kpis > div {
  min-width: 0;
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
}
.cycle-kpis strong {
  font-size: 22px;
  white-space: nowrap;
}
.balance-strip {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.balance-strip span {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
}
.balance-strip strong { color: var(--text); }
.schedule-details {
  margin-top: 14px;
  color: var(--muted);
}
.schedule-details summary {
  cursor: pointer;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  color: var(--text);
  font-weight: 700;
}
.compact-metrics {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 0;
}

.contract-summary, .tariff-active, .settings-advanced {
  margin-bottom: 18px;
}
.contract-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.contract-grid > div {
  min-width: 0;
  display: grid;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.contract-grid span, .contract-grid small,
.tariff-card span, .tariff-card small {
  color: var(--muted);
}
.contract-grid strong {
  font-size: 24px;
}
.tariff-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.tariff-card {
  min-width: 0;
  display: grid;
  gap: 14px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid transparent;
}
.tariff-card.current {
  border-color: rgba(46, 211, 183, 0.42);
  background: rgba(46, 211, 183, 0.08);
}
.tariff-card strong {
  display: block;
  margin: 4px 0;
  font-size: 18px;
}
.tariff-values {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.tariff-values span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: 30px;
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
}
.tariff-values strong {
  display: inline;
  margin: 0;
  color: var(--text);
  font-size: 14px;
}
.settings-advanced {
  display: grid;
  gap: 14px;
}
.settings-advanced summary {
  cursor: pointer;
  min-height: 34px;
  font-weight: 700;
}
.compact-form {
  margin-top: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.flat-table {
  padding: 0;
  margin-top: 12px;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.balance-panel { margin-bottom: 18px; }
.balance-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}
.balance-item {
  min-width: 0;
  display: grid;
  gap: 7px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.balance-item span, .balance-item small, .balance-note { color: var(--muted); }
.balance-item strong {
  font-size: 24px;
  color: var(--text);
  white-space: nowrap;
}
.balance-note { margin: 16px 0 0; line-height: 1.5; }
.schedule-table {
  max-height: 310px;
  margin-top: 14px;
  overflow: auto;
  border-top: 1px solid var(--line);
}
.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.status-chip.paid { color: #b8fff0; background: rgba(46, 211, 183, 0.12); }
.status-chip.planned { color: #ffe4a0; background: rgba(255, 207, 87, 0.12); }

.split, .actions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.actions-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.panel, .table-panel { padding: 20px; }
.formula-list { display: grid; gap: 10px; }
.formula-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px; border-radius: 8px; background: rgba(255,255,255,0.04); }
.formula-row.winner { color: var(--cyan); }

.ratio { height: 20px; display: flex; overflow: hidden; border-radius: 8px; background: #0d121b; box-shadow: inset 6px 6px 12px rgba(0,0,0,.45); }
.ratio span:first-child { background: var(--cyan); }
.ratio span:last-child { background: var(--yellow); }
.legend { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 15px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 999px; margin-right: 6px; }
.dot.hc { background: var(--cyan); }
.dot.hp { background: var(--yellow); }

.toolbar, .inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.form-grid { display: grid; gap: 12px; }
.button-stack { display: grid; gap: 12px; align-content: start; }
label { display: grid; gap: 6px; color: var(--muted); }
input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  background: #101722;
  outline: none;
}
input:focus, select:focus { border-color: rgba(126, 167, 255, 0.75); }

button, .primary, .secondary, .icon-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.primary { padding: 0 16px; background: linear-gradient(135deg, #1fa98f, #5b83ff); }
.secondary { padding: 0 16px; background: #202b3d; }
.icon-button { width: 42px; background: #202b3d; }
.danger { color: var(--red); }

.notice, .flash-stack { display: grid; gap: 8px; margin-bottom: 16px; }
.notice span, .flash {
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(255, 207, 87, 0.12);
  border: 1px solid rgba(255, 207, 87, 0.24);
  color: #ffe4a0;
}
.flash.success { background: rgba(46, 211, 183, 0.12); border-color: rgba(46, 211, 183, 0.28); color: #b8fff0; }
.flash.error { background: rgba(255, 102, 122, 0.12); border-color: rgba(255, 102, 122, 0.28); color: #ffc8d0; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
td { color: #e7edfa; }
.large-line { font-size: 24px; margin: 0; }

.login-panel { width: min(420px, calc(100vw - 32px)); padding: 30px; }
.login-mark { margin-bottom: 18px; font-size: 24px; }
.login-panel h1 { margin-bottom: 18px; }

@media (max-width: 1000px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    z-index: 10;
    height: auto;
    width: 100%;
    max-width: 100vw;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand { margin: 0; font-size: 18px; }
  .brand-mark { width: 36px; height: 36px; }
  .nav { display: flex; }
  .nav a span { display: none; }
  .logout-form { position: static; margin-left: auto; }
  .content { padding: 18px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cycle-layout { grid-template-columns: 1fr; }
  .cycle-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .contract-grid, .tariff-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compact-form { grid-template-columns: 1fr; }
  .balance-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .actions-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .page-head { align-items: stretch; flex-direction: column; }
  .cycle-head { flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric { min-height: 112px; }
  .metric strong { font-size: 24px; }
  .cycle-kpis { grid-template-columns: 1fr; }
  .contract-grid, .tariff-card-grid { grid-template-columns: 1fr; }
  .balance-grid { grid-template-columns: 1fr; }
  .toolbar, .inline-form { display: grid; grid-template-columns: 1fr; }
  .icon-button { width: 100%; }
  .chart-panel { height: 340px; }
  .chart-panel canvas { height: 260px; }
  .table-panel, .schedule-table { overflow-x: auto; }
}
