:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef7f6;
  --text: #13201f;
  --muted: #667371;
  --border: #dce5e3;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-text: #ffffff;
  --danger: #b42318;
  --shadow: 0 12px 32px rgba(17, 42, 39, 0.08);
  --radius: 18px;
  --container: 1160px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1514;
  --surface: #131f1d;
  --surface-soft: #172b28;
  --text: #edf7f5;
  --muted: #a7b7b4;
  --border: #2b3d3a;
  --accent: #39b9aa;
  --accent-strong: #54cbbc;
  --accent-text: #07110f;
  --danger: #ff8a80;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}
button, input, select { font: inherit; }
button, label.file-button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, .file-button:focus-within {
  outline: 3px solid color-mix(in srgb, var(--accent) 32%, transparent);
  outline-offset: 2px;
}

.container { width: min(calc(100% - 32px), var(--container)); margin-inline: auto; }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 100; background: var(--surface); color: var(--text); padding: 10px 14px; border-radius: 10px; }
.skip-link:focus { top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.site-header { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); }
.header-inner, .footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 72px; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand span:last-child { display: grid; }
.brand strong { font-size: 1.05rem; letter-spacing: .01em; }
.brand small { color: var(--muted); }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; background: var(--surface-soft); color: var(--accent); }
.brand-mark svg { width: 27px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.header-actions, .button-group { display: flex; flex-wrap: wrap; gap: 8px; }

.main-layout { padding-block: 42px 64px; display: grid; gap: 28px; }
.hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 32px; }
.hero h1 { margin: 8px 0 12px; max-width: 790px; font-size: clamp(2rem, 5vw, 4.6rem); line-height: 1.02; letter-spacing: -.055em; }
.hero p { max-width: 750px; margin: 0; color: var(--muted); font-size: clamp(1rem, 1.7vw, 1.2rem); }
.eyebrow { display: block; color: var(--accent); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.hero-formula { min-width: 240px; padding: 18px 20px; border-left: 4px solid var(--accent); background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; box-shadow: var(--shadow); }
.hero-formula span { display: block; color: var(--muted); font-size: .82rem; }
.hero-formula strong { display: block; margin-top: 4px; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card { min-width: 0; padding: 19px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.metric-card span { display: block; color: var(--muted); font-size: .85rem; }
.metric-card strong { display: block; margin-top: 6px; font-size: clamp(1.35rem, 3vw, 2rem); letter-spacing: -.035em; overflow-wrap: anywhere; }
.panel, .room-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 24px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.section-heading h2 { margin: 4px 0 0; font-size: clamp(1.35rem, 2vw, 1.8rem); letter-spacing: -.02em; }

.form-grid { display: grid; gap: 16px; }
.four-columns { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: block; min-width: 0; }
.field > span { display: block; margin-bottom: 7px; font-size: .87rem; font-weight: 700; }
.field small { display: block; margin-top: 6px; color: var(--muted); font-size: .76rem; line-height: 1.35; }
input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
}
.input-unit { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); overflow: hidden; }
.input-unit input { min-width: 0; border: 0; border-radius: 0; background: transparent; }
.input-unit span { display: grid; place-items: center; min-width: 58px; padding-inline: 10px; color: var(--muted); border-left: 1px solid var(--border); font-size: .82rem; }
.calculated-field { padding: 12px 14px; border-radius: 12px; background: var(--surface-soft); }
.calculated-field strong { display: block; font-size: 1.45rem; }

.button, .icon-button { border: 1px solid transparent; cursor: pointer; transition: .18s ease; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 9px 14px; border-radius: 12px; font-weight: 750; text-decoration: none; }
.button:hover, .icon-button:hover { transform: translateY(-1px); }
.button-primary { background: var(--accent); color: var(--accent-text); }
.button-primary:hover { background: var(--accent-strong); }
.button-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.button-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.file-button { position: relative; cursor: pointer; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.rooms-list { display: grid; gap: 16px; }
.room-card { padding: 20px; }
.room-card-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.room-title-wrap { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.room-index { display: grid; place-items: center; flex: 0 0 34px; width: 34px; height: 34px; border-radius: 10px; background: var(--surface-soft); color: var(--accent); font-weight: 800; }
.room-name-field { flex: 1; }
.room-name-field input { font-weight: 800; background: transparent; border-color: transparent; font-size: 1.08rem; }
.room-name-field input:hover, .room-name-field input:focus { border-color: var(--border); background: var(--bg); }
.room-actions { display: flex; gap: 8px; }
.icon-button { display: grid; place-items: center; width: 38px; height: 38px; border-color: var(--border); border-radius: 10px; background: var(--bg); color: var(--text); font-size: 1.25rem; }
.icon-button.danger { color: var(--danger); }
.room-grid { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 14px; }
.room-output { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.room-output div { padding: 12px; border-radius: 12px; background: var(--surface-soft); min-width: 0; }
.room-output span { display: block; color: var(--muted); font-size: .76rem; }
.room-output strong { display: block; margin-top: 3px; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 13px 11px; border-bottom: 1px solid var(--border); text-align: right; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; }
tfoot td { font-weight: 800; border-bottom: 0; }
.empty-state { padding: 28px; text-align: center; border: 1px dashed var(--border); border-radius: 14px; color: var(--muted); }
.notice { padding: 18px 20px; border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 12px; background: var(--surface-soft); }
.site-footer { border-top: 1px solid var(--border); color: var(--muted); }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 50; max-width: min(380px, calc(100vw - 36px)); padding: 13px 16px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); transform: translateY(20px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.visible { transform: translateY(0); opacity: 1; }

@media (max-width: 980px) {
  .four-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .room-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { grid-template-columns: 1fr; align-items: start; }
  .hero-formula { width: fit-content; }
}

@media (max-width: 720px) {
  .container { width: min(calc(100% - 22px), var(--container)); }
  .header-inner { min-height: 64px; }
  .brand small { display: none; }
  .header-actions .button { padding-inline: 10px; }
  .main-layout { padding-block: 28px 42px; gap: 22px; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel, .room-card { padding: 17px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading .button-group { width: 100%; }
  .section-heading .button-group .button { flex: 1; }
  .room-output { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .footer-inner { align-items: flex-start; flex-direction: column; justify-content: center; gap: 2px; padding-block: 18px; }
}

@media (max-width: 480px) {
  .four-columns, .room-grid { grid-template-columns: 1fr; }
  .room-card-header { align-items: flex-start; }
  .room-title-wrap { align-items: flex-start; }
  .summary-grid { gap: 10px; }
  .metric-card { padding: 14px; }
  .metric-card strong { font-size: 1.3rem; }
}

@media print {
  :root { --bg: #fff; --surface: #fff; --text: #000; --muted: #444; --border: #bbb; --surface-soft: #f5f5f5; --shadow: none; }
  .site-header, .header-actions, .button, .room-actions, .notice, .site-footer, .file-button { display: none !important; }
  .container { width: 100%; }
  .main-layout { padding: 0; gap: 16px; }
  .hero h1 { font-size: 2.4rem; }
  .panel, .room-card, .metric-card { break-inside: avoid; box-shadow: none; }
  .rooms-list { display: block; }
  .room-card { margin-bottom: 12px; }
  input, select { appearance: none; border: 0; padding: 0; min-height: auto; background: transparent; }
  .input-unit { border: 0; background: transparent; }
  .input-unit span { border: 0; min-width: auto; padding-left: 3px; }
  .results-panel { break-before: page; }
}
