:root {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #0c1727;
  --surface-2: #111f33;
  --line: rgba(255, 255, 255, .09);
  --text: #eef5ff;
  --muted: #8ea2bb;
  --brand: #2f7df6;
  --brand-2: #28d6a3;
  --danger: #ff5c75;
  --warning: #ffbd4a;
  --shadow: 0 24px 70px rgba(0, 0, 0, .34);
}

body.light {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #edf3fb;
  --line: rgba(17, 31, 51, .1);
  --text: #102033;
  --muted: #66758a;
  --shadow: 0 20px 55px rgba(28, 43, 68, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(47, 125, 246, .22), transparent 34rem),
    linear-gradient(135deg, var(--bg), #050a12 72%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body.light {
  background:
    radial-gradient(circle at top left, rgba(47, 125, 246, .13), transparent 34rem),
    linear-gradient(135deg, #f6f9ff, #eef3f9);
}

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

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 22px;
  background:
    radial-gradient(circle at 20% 10%, rgba(47, 125, 246, .28), transparent 30rem),
    radial-gradient(circle at 80% 90%, rgba(40, 214, 163, .18), transparent 26rem),
    var(--bg);
}

.login-gate.active { display: grid; }

.login-panel {
  width: min(520px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .06), transparent), var(--surface);
  box-shadow: var(--shadow);
}

.login-brand { margin-bottom: 24px; }
.login-panel h1 { margin-bottom: 12px; }
.login-panel p, .login-panel small {
  color: var(--muted);
  line-height: 1.6;
}

.login-form {
  display: grid;
  gap: 14px;
  margin: 22px 0 14px;
}

.login-status {
  display: none;
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid rgba(255, 189, 74, .3);
  border-radius: 8px;
  background: rgba(255, 189, 74, .1);
  color: var(--text);
  line-height: 1.5;
}

.login-status.show { display: block; }
.login-status.error {
  border-color: rgba(255, 92, 117, .35);
  background: rgba(255, 92, 117, .12);
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.mobile-menu-button,
.mobile-overlay {
  display: none;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(7, 17, 31, .72);
  backdrop-filter: blur(18px);
}

body.light .sidebar { background: rgba(255, 255, 255, .76); }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #0dd8a1);
  color: white;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(47, 125, 246, .34);
}

.brand strong, .brand span { display: block; }
.brand span { color: var(--muted); font-size: 12px; margin-top: 3px; }

.sidebar-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 30px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .035);
}

.sidebar-avatar {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
}

.sidebar-profile-fields {
  min-width: 0;
}

.sidebar-profile-fields input {
  width: 100%;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 11px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  transition: .2s ease;
}

.nav-item:hover, .nav-item.active {
  background: rgba(47, 125, 246, .13);
  border-color: rgba(47, 125, 246, .24);
  color: var(--text);
}

.icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: var(--brand-2);
}

.sidebar-card {
  position: absolute;
  left: 22px;
  right: 22px;
  bottom: 22px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sidebar-card h3 { margin: 14px 0 4px; font-size: 15px; }
.sidebar-card p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-2);
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
}

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

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--brand-2);
  font-size: 13px;
  font-weight: 700;
}

h1, h2, h3, p { letter-spacing: 0; }
h1 { margin: 0; font-size: clamp(28px, 4vw, 42px); line-height: 1.05; }
h2 { margin: 0; font-size: 18px; }

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

.top-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.top-avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  overflow: hidden;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: white;
  font-size: 13px;
  font-weight: 800;
}

.top-avatar input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.top-avatar img, .avatar img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.top-avatar.has-photo img, .avatar.has-photo img { display: block; }
.top-avatar.has-photo span, .avatar.has-photo span { display: none; }

.top-profile-fields {
  display: grid;
  min-width: 150px;
}

.top-profile-fields input {
  min-height: 24px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-weight: 800;
}

.top-profile-fields small {
  color: var(--muted);
  font-size: 11px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(340px, 32vw);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.search input {
  width: 100%;
  height: 42px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.icon-button, .primary-action, .secondary-action {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--text);
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.icon-button {
  width: 42px;
  background: var(--surface);
}

.primary-action {
  padding: 0 16px;
  border-color: rgba(47, 125, 246, .4);
  background: linear-gradient(135deg, var(--brand), #10b981);
  color: white;
  font-weight: 800;
}

.secondary-action {
  padding: 0 14px;
  background: var(--surface-2);
}

.icon-button:hover, .primary-action:hover, .secondary-action:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 125, 246, .42);
}

.screen { display: none; animation: rise .28s ease both; }
.screen.active { display: block; }

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

.filters, .table-filters, .button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filters { margin-bottom: 16px; }
.filters { position: relative; }

.custom-period {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 8;
  display: none;
  grid-template-columns: minmax(160px, 220px) auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.custom-period.show { display: grid; }
.custom-period .primary-action { min-height: 42px; }

.chip, .pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
}

.chip {
  padding: 9px 13px;
  transition: .18s ease;
}

.chip.active, .chip:hover {
  background: rgba(47, 125, 246, .16);
  border-color: rgba(47, 125, 246, .35);
  color: var(--text);
}

.pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.pill.success { color: var(--brand-2); background: rgba(40, 214, 163, .1); }

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

.metric-card, .panel, .form-panel, .calculator-card, .plan-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .045), transparent), var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 138px;
  padding: 18px;
}

.metric-card span, .metric-card small {
  display: block;
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 12px 0 8px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1;
}

.hero-metric {
  background: linear-gradient(135deg, rgba(47, 125, 246, .28), rgba(40, 214, 163, .12)), var(--surface);
}

.positive { color: var(--brand-2) !important; }
.negative { color: var(--danger) !important; }

.dashboard-grid, .report-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.panel, .form-panel, .calculator-card, .plan-card {
  padding: 18px;
}

.span-2 { grid-column: span 2; }

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-header p, .plan-card p, .profile-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.bar-chart {
  display: flex;
  align-items: end;
  gap: 10px;
  height: 260px;
  padding-top: 14px;
}

.empty-state {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.bar {
  flex: 1;
  min-width: 22px;
  position: relative;
  border-radius: 7px 7px 4px 4px;
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  transition: .2s ease;
}

.bar:hover { filter: brightness(1.12); transform: translateY(-2px); }
.bar span {
  position: absolute;
  left: 50%;
  bottom: -24px;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 11px;
}

.donut-wrap {
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: center;
  gap: 18px;
}

.donut {
  width: 140px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--brand) 0 45%, var(--danger) 45% 72%, var(--warning) 72% 88%, var(--brand-2) 88% 100%);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 22px;
  border-radius: inherit;
  background: var(--surface);
}

.legend, .ranking, .insights, .report-list, .maintenance-list, .calc-list {
  display: grid;
  gap: 12px;
}

.legend div, .ranking div, .insights div, .report-list div, .maintenance-list div, .calc-list div, .strategy-grid div, .stack-grid div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .03);
}

.insights div, .strategy-grid div, .stack-grid div {
  display: grid;
}

.legend span, .ranking span, .insights span, .report-list span, .maintenance-list span, .calc-list span, .strategy-grid span, .stack-grid span {
  color: var(--muted);
  font-size: 13px;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  outline: 0;
  padding: 10px 12px;
}

textarea { min-height: 92px; resize: vertical; }
.full { grid-column: 1 / -1; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.calculator-card {
  position: sticky;
  top: 24px;
}

.calculator-card h2 { margin: 14px 0 16px; }

.alert-card {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(40, 214, 163, .22);
  border-radius: 8px;
  background: rgba(40, 214, 163, .1);
}

.alert-card span { color: var(--muted); font-size: 13px; }

.history-header { align-items: center; }
.table-filters { margin-bottom: 14px; }
.table-filters input, .table-filters select { max-width: 280px; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td { font-size: 14px; }

.row-actions {
  display: flex;
  gap: 6px;
}

.mini-button {
  min-width: 34px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}

.line-chart {
  height: 260px;
  border-radius: 8px;
  background:
    linear-gradient(to top, var(--line) 1px, transparent 1px) 0 0 / 100% 25%,
    linear-gradient(135deg, rgba(47, 125, 246, .18), rgba(40, 214, 163, .1));
  clip-path: polygon(0 78%, 12% 62%, 25% 65%, 38% 44%, 52% 50%, 65% 27%, 78% 34%, 100% 12%, 100% 100%, 0 100%);
}

.strategy-grid, .stack-grid, .profile-grid, .pricing-grid {
  display: grid;
  gap: 16px;
}

.strategy-grid, .stack-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.profile-grid { grid-template-columns: 380px 1fr; }
.pricing-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.avatar {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  overflow: hidden;
  margin-bottom: 18px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: white;
  font-size: 28px;
  font-weight: 800;
}

.profile-stats {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.profile-stats div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.profile-stats span { color: var(--muted); font-size: 13px; }

.maintenance-alerts {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.maintenance-alerts:empty { display: none; }

.maintenance-alert {
  padding: 12px;
  border: 1px solid rgba(255, 92, 117, .28);
  border-radius: 8px;
  background: rgba(255, 92, 117, .1);
}

.maintenance-alert strong,
.maintenance-alert span {
  display: block;
}

.maintenance-alert span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.plan-card {
  display: grid;
  align-content: start;
  gap: 16px;
}

.plan-card.featured {
  border-color: rgba(40, 214, 163, .34);
  background: linear-gradient(135deg, rgba(47, 125, 246, .22), rgba(40, 214, 163, .12)), var(--surface);
  transform: translateY(-8px);
}

.plan-card h2 { font-size: 34px; }
.plan-card ul { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.8; }
.stack-section { margin-top: 16px; }
.download-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.download-panel p {
  margin: 8px 0 0;
  color: var(--muted);
}

.download-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}
.sync-note {
  margin-top: 16px;
}

.sync-note p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}
.report-settings-form { margin-top: 18px; }

.visibility-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .03);
}

.visibility-options strong {
  grid-column: 1 / -1;
}

.visibility-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 600;
}

.visibility-options input {
  width: 18px;
  min-height: 18px;
}

.is-hidden-by-user { display: none !important; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 14px 16px;
  border: 1px solid rgba(40, 214, 163, .28);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  transition: .22s ease;
}

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

.install-banner {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  display: none;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  width: min(760px, calc(100% - 32px));
  padding: 14px;
  border: 1px solid rgba(47, 125, 246, .32);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(47, 125, 246, .2), rgba(40, 214, 163, .1)), var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.install-banner.show { display: grid; }
.install-banner strong, .install-banner span { display: block; }
.install-banner span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 88px 1fr; }
  .sidebar-profile-fields, .nav-item:not(.active) { font-size: 0; }
  .nav-item { justify-content: center; }
  .sidebar-card { display: none; }
  .metric-grid, .dashboard-grid, .report-grid, .pricing-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2 { grid-column: span 2; }
  .split-layout, .profile-grid { grid-template-columns: 1fr; }
  .calculator-card { position: static; }
  .strategy-grid, .stack-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  body { padding-top: 0; }
  .mobile-menu-button {
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 31;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-overlay {
    position: fixed;
    inset: 0;
    z-index: 28;
    display: none;
    background: rgba(0, 0, 0, .48);
  }
  body.mobile-menu-open .mobile-overlay { display: block; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    right: auto;
    z-index: 30;
    width: min(82vw, 292px);
    height: 100vh;
    padding: 16px;
    border-right: 1px solid var(--line);
    border-top: 0;
    transform: translateX(-104%);
    transition: transform .22s ease;
    will-change: transform;
  }
  body.mobile-menu-open .sidebar { transform: translateX(0); }
  .brand { display: none; }
  .sidebar-profile {
    display: flex;
    position: static;
    margin: 0 0 26px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }
  .sidebar-profile-fields {
    display: grid;
    font-size: initial;
  }
  .nav { grid-template-columns: 1fr; gap: 10px; }
  .nav-item {
    min-height: 46px;
    padding: 11px 14px;
    font-size: 16px;
    justify-content: flex-start;
    flex-direction: row;
    gap: 10px;
  }
  .nav-item:not(.active) { font-size: 16px; }
  .main { padding: 74px 14px 28px; }
  .topbar { display: grid; }
  .topbar-actions { width: 100%; display: grid; grid-template-columns: 1fr 42px 42px; }
  .search { width: 100%; }
  .topbar-actions .primary-action { grid-column: 1 / -1; }
  .metric-grid, .dashboard-grid, .report-grid, .pricing-grid, .strategy-grid, .stack-grid { grid-template-columns: 1fr; }
  .download-panel { display: grid; }
  .span-2 { grid-column: span 1; }
  .form-grid { grid-template-columns: 1fr; }
  .donut-wrap { grid-template-columns: 1fr; }
  .bar-chart { height: 210px; overflow-x: auto; }
  .bar { min-width: 34px; }
  .history-header { display: grid; }
  .table-filters input, .table-filters select { max-width: none; }
  .table-wrap { overflow: visible; }
  table, thead, tbody, tr, td { display: block; min-width: 0; width: 100%; }
  thead { display: none; }
  tr {
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .03);
  }
  td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
    white-space: normal;
  }
  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }
  td:last-child { border-bottom: 0; display: block; }
  td:last-child::before { display: none; }
  .row-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .mini-button {
    width: 100%;
    height: 42px;
    font-size: 18px;
  }
  .plan-card.featured { transform: none; }
  .custom-period {
    position: static;
    grid-template-columns: 1fr;
    width: 100%;
  }
  .visibility-options { grid-template-columns: 1fr; }
  .install-banner {
    bottom: 74px;
    grid-template-columns: 1fr;
  }
}
