:root {
  --ink: #251b15;
  --ink-soft: #46382e;
  --muted: #7d7066;
  --paper: #f4f0e9;
  --surface: #fffdfa;
  --surface-soft: #f8f4ed;
  --line: #ded4c6;
  --line-strong: #c7b8a2;
  --gold: #bd8420;
  --gold-dark: #90600f;
  --gold-soft: #f2e2bd;
  --green: #2f7353;
  --green-soft: #dcece3;
  --red: #a44132;
  --red-soft: #f4ddd8;
  --shadow: 0 16px 40px rgba(58, 43, 31, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px max(24px, calc((100vw - 1440px) / 2));
  color: #fff8ec;
  background: var(--ink);
  border-bottom: 2px solid var(--gold);
}

.brand-lockup { display: flex; align-items: center; gap: 12px; letter-spacing: .12em; }
.brand-lockup strong, .brand-lockup small { display: block; }
.brand-lockup strong { font-family: Georgia, "Times New Roman", serif; font-size: 15px; }
.brand-lockup small { margin-top: 3px; color: #d7c7af; font-size: 9px; }
.brand-mark {
  display: grid; place-items: center; width: 40px; height: 40px;
  color: var(--ink); background: var(--gold); font-family: Georgia, serif; font-size: 21px;
  border: 1px solid #d8a647;
}
.topbar-actions { display: flex; align-items: center; gap: 18px; font-size: 12px; }

.app-shell { width: min(1440px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 70px; }
.page-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin-bottom: 28px; }
.eyebrow, .section-kicker {
  margin: 0 0 10px; color: var(--gold-dark); font-size: 10px; font-weight: 800;
  letter-spacing: .22em;
}
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
h1 { max-width: 820px; margin: 0; font-size: clamp(34px, 4.2vw, 60px); line-height: 1.02; letter-spacing: -.025em; }
h2 { margin: 0; font-size: 27px; line-height: 1.1; }
.intro-copy { max-width: 680px; margin: 14px 0 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.muted { color: var(--muted); }

.control-state {
  min-width: 210px; display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-left: 3px solid var(--line-strong); background: rgba(255,255,255,.45);
}
.control-state small, .control-state strong { display: block; }
.control-state small { color: var(--muted); font-size: 9px; letter-spacing: .18em; }
.control-state strong { margin-top: 4px; font-size: 14px; }
.status-dot, .service-dot { display: block; width: 10px; height: 10px; border-radius: 50%; background: #a99e93; }
.control-state[data-state="active"] { border-color: var(--gold); }
.control-state[data-state="active"] .status-dot { background: var(--green); box-shadow: 0 0 0 5px var(--green-soft); }

.status-rail {
  display: grid; grid-template-columns: repeat(4, 1fr); background: var(--ink); color: #fff;
  border: 1px solid var(--ink); box-shadow: var(--shadow);
}
.status-item { display: flex; align-items: center; gap: 12px; min-height: 76px; padding: 16px 20px; border-right: 1px solid rgba(255,255,255,.12); }
.status-item:last-child { border-right: 0; }
.status-item small, .status-item strong { display: block; }
.status-item small { color: #b9aa99; font-size: 9px; letter-spacing: .17em; }
.status-item strong { margin-top: 5px; font-size: 14px; }
.service-dot.online { background: #62b58b; box-shadow: 0 0 0 5px rgba(98,181,139,.14); }
.service-dot.warning { background: #b18d74; }

.global-message { margin-top: 20px; padding: 13px 16px; color: #7c2f23; background: var(--red-soft); border-left: 3px solid var(--red); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, .72fr); gap: 22px; margin-top: 22px; }
.panel { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 24px 26px; border-bottom: 1px solid var(--line); }
.panel-header .section-kicker { margin-bottom: 7px; }
.data-age { padding: 6px 10px; color: var(--muted); background: var(--surface-soft); border: 1px solid var(--line); font-size: 11px; }

.energy-map {
  position: relative; display: grid;
  grid-template-columns: repeat(5, 1fr); grid-template-rows: 118px 118px;
  gap: 18px; padding: 34px 30px 26px; overflow: hidden;
}
.energy-node {
  position: relative; z-index: 2; display: flex; flex-direction: column; justify-content: center;
  min-width: 0; padding: 16px; background: var(--surface-soft); border: 1px solid var(--line);
}
.energy-node strong { margin: 8px 0 3px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(21px, 2vw, 30px); font-weight: 500; white-space: nowrap; }
.energy-node small { color: var(--muted); font-size: 11px; }
.node-label { color: var(--gold-dark); font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.featured-node { color: #fff; background: var(--ink); border-color: var(--ink); }
.featured-node .node-label { color: #e7b95f; }
.featured-node small { color: #c8baaa; }
.pv-node { grid-column: 1 / 2; grid-row: 1; }
.house-node { grid-column: 3 / 4; grid-row: 1; }
.grid-node { grid-column: 5 / 6; grid-row: 1; }
.battery-node { grid-column: 2 / 3; grid-row: 2; }
.charger-node { grid-column: 4 / 5; grid-row: 2; border-color: #d4ad64; }
.flow-line { position: relative; align-self: center; height: 1px; background: var(--line-strong); z-index: 1; }
.flow-line i { position: absolute; right: 0; top: -3px; width: 7px; height: 7px; border-top: 1px solid var(--gold-dark); border-right: 1px solid var(--gold-dark); transform: rotate(45deg); }
.flow-a { grid-column: 2 / 3; grid-row: 1; }
.flow-b { grid-column: 4 / 5; grid-row: 1; }
.flow-c { grid-column: 3 / 4; grid-row: 2; }

.decision-strip { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 20px 26px; background: var(--gold-soft); border-top: 1px solid #ddbd7c; }
.decision-strip small { display: block; color: var(--gold-dark); font-size: 9px; letter-spacing: .16em; }
.decision-strip strong { display: block; margin-top: 5px; font-size: 14px; }
.decision-values { display: flex; gap: 34px; text-align: right; }
.decision-values strong { font-family: Georgia, serif; font-size: 21px; font-weight: 500; }

.badge { padding: 6px 9px; font-size: 9px; font-weight: 800; letter-spacing: .13em; border: 1px solid var(--line); }
.badge.success { color: var(--green); background: var(--green-soft); border-color: #b3d5c0; }
.badge.neutral { color: var(--muted); background: var(--surface-soft); }
.detail-list { margin: 0; padding: 8px 26px 18px; }
.detail-list div { display: flex; justify-content: space-between; gap: 18px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.detail-list dt { color: var(--muted); font-size: 12px; }
.detail-list dd { margin: 0; font-size: 12px; font-weight: 700; text-align: right; }
.panel-note { margin: 0; padding: 18px 26px; color: var(--muted); background: var(--surface-soft); border-top: 1px solid var(--line); font-size: 11px; line-height: 1.6; }

.settings-panel, .events-panel { margin-top: 22px; }
.settings-heading { align-items: center; }
.settings-heading .muted { margin: 8px 0 0; font-size: 12px; }
.settings-form { display: grid; grid-template-columns: repeat(4, 1fr); }
fieldset { min-width: 0; margin: 0; padding: 24px; border: 0; border-right: 1px solid var(--line); }
fieldset:last-child { border-right: 0; }
legend { padding: 0; font-family: Georgia, serif; font-size: 17px; font-weight: 600; }
label { display: block; color: var(--ink-soft); font-size: 11px; font-weight: 700; }
label > span { color: var(--muted); font-weight: 500; }
input, select {
  width: 100%; min-height: 42px; margin-top: 7px; padding: 9px 11px; color: var(--ink);
  background: #fff; border: 1px solid var(--line-strong); border-radius: 0; outline: none;
}
input:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(189,132,32,.12); }
input:disabled { color: #a39a92; background: #eee9e2; }
.field-grid { display: grid; grid-template-columns: 1fr; gap: 15px; margin-top: 17px; }
.switch-row { display: flex; justify-content: space-between; gap: 15px; margin: 17px 0; }
.switch-row strong, .switch-row small { display: block; }
.switch-row small { margin-top: 4px; color: var(--muted); font-weight: 400; line-height: 1.4; }
.switch-row input { width: 42px; min-height: 22px; margin: 0; accent-color: var(--gold); }
.segmented-control { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 17px; border: 1px solid var(--line-strong); }
.segmented-control label { position: relative; margin: 0; }
.segmented-control input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-control span { display: grid; place-items: center; min-height: 38px; padding: 7px; color: var(--muted); font-size: 10px; text-align: center; border-right: 1px solid var(--line); }
.segmented-control label:last-child span { border-right: 0; }
.segmented-control input:checked + span { color: #fff; background: var(--ink); }

.primary-button, .quiet-button {
  min-height: 44px; padding: 10px 18px; border: 1px solid transparent; font-size: 11px;
  font-weight: 800; letter-spacing: .09em;
}
.primary-button { color: #fff; background: var(--ink); border-color: var(--ink); }
.primary-button:hover { background: #3b2b21; }
.quiet-button { color: inherit; background: transparent; border-color: var(--line-strong); }
.topbar .quiet-button { color: #fff8ec; border-color: rgba(255,255,255,.25); }
.compact-button { min-width: 170px; }
.form-message { margin: 0; padding: 14px 24px; border-top: 1px solid var(--line); font-size: 12px; }
.success-message { color: var(--green); background: var(--green-soft); }
.error-message { color: var(--red); background: var(--red-soft); }

.event-table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 13px 18px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); background: var(--surface-soft); font-size: 9px; letter-spacing: .14em; }
tbody tr:last-child td { border-bottom: 0; }
.event-badge { padding: 4px 7px; color: var(--ink-soft); background: var(--surface-soft); border-left: 2px solid var(--line-strong); font-size: 9px; font-weight: 800; letter-spacing: .08em; }
.event-badge.warning { color: #815b1a; background: #f5ead2; border-color: var(--gold); }
.event-badge.error { color: var(--red); background: var(--red-soft); border-color: var(--red); }
.empty-cell { padding: 30px; color: var(--muted); text-align: center; }

.login-body { display: grid; place-items: center; padding: 34px; background: var(--ink); }
.login-shell { width: min(980px, 100%); display: grid; grid-template-columns: 1.1fr .9fr; min-height: 560px; border: 1px solid #4a382c; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.login-brand { display: flex; flex-direction: column; justify-content: center; padding: 68px; color: #fff8ec; background: #2f221a; border-right: 1px solid #4a382c; }
.login-brand .eyebrow { color: #e1ad4d; }
.login-brand h1 { font-size: clamp(38px, 4.4vw, 58px); }
.login-brand > p:not(.eyebrow) { max-width: 470px; color: #cbbcab; line-height: 1.7; }
.login-system-line { display: flex; align-items: center; gap: 14px; margin-top: 60px; color: #e1ad4d; font-size: 9px; letter-spacing: .18em; }
.login-system-line i { width: 52px; height: 1px; background: #765c33; }
.login-panel { display: flex; flex-direction: column; justify-content: center; gap: 34px; padding: 54px; background: var(--surface); }
.login-panel h2 { font-size: 34px; }
.login-panel .muted { font-size: 12px; line-height: 1.6; }
.login-panel form { display: grid; gap: 14px; }
.login-panel input { min-height: 48px; margin-top: -5px; }
.login-panel .primary-button { margin-top: 8px; min-height: 50px; }
.login-panel .form-message { margin: 0; padding: 11px; border: 0; }

@media (max-width: 1100px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .settings-form { grid-template-columns: repeat(2, 1fr); }
  fieldset:nth-child(2) { border-right: 0; }
  fieldset:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .topbar { min-height: 64px; padding: 10px 16px; }
  .topbar-actions .muted { display: none; }
  .app-shell { width: min(100% - 24px, 1440px); padding: 28px 0 50px; }
  .page-intro { align-items: stretch; flex-direction: column; }
  .control-state { min-width: 0; width: 100%; }
  .status-rail { grid-template-columns: repeat(2, 1fr); }
  .status-item:nth-child(2) { border-right: 0; }
  .status-item:nth-child(-n+2) { border-bottom: 1px solid rgba(255,255,255,.12); }
  .dashboard-grid { gap: 14px; margin-top: 14px; }
  .panel-header { padding: 20px; }
  .energy-map { grid-template-columns: 1fr 36px 1fr; grid-template-rows: repeat(3, 104px); gap: 12px; padding: 22px 18px; }
  .pv-node { grid-column: 1; grid-row: 1; }
  .flow-a { grid-column: 2; grid-row: 1; }
  .house-node { grid-column: 3; grid-row: 1; }
  .battery-node { grid-column: 1; grid-row: 2; }
  .flow-c { grid-column: 2; grid-row: 2; }
  .charger-node { grid-column: 3; grid-row: 2; }
  .grid-node { grid-column: 3; grid-row: 3; }
  .flow-b { display: none; }
  .energy-node { padding: 12px; }
  .energy-node strong { font-size: 21px; }
  .decision-strip { align-items: flex-start; flex-direction: column; padding: 18px 20px; }
  .decision-values { width: 100%; justify-content: space-between; text-align: left; }
  .settings-heading { align-items: stretch; flex-direction: column; }
  .compact-button { width: 100%; }
  .settings-form { grid-template-columns: 1fr; }
  fieldset, fieldset:nth-child(2) { border-right: 0; border-bottom: 1px solid var(--line); }
  fieldset:last-child { border-bottom: 0; }
  .login-body { padding: 16px; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: 280px; padding: 38px; border-right: 0; border-bottom: 1px solid #4a382c; }
  .login-system-line { margin-top: 26px; }
  .login-panel { padding: 36px; }
}

@media (prefers-reduced-motion: no-preference) {
  .service-dot.online, .control-state[data-state="active"] .status-dot {
    animation: pulse 2.4s ease-in-out infinite;
  }
  @keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(98,181,139,.11); }
    50% { box-shadow: 0 0 0 8px rgba(98,181,139,.04); }
  }
}

