:root {
  --navy: #087bcf;
  --navy-dark: #17191b;
  --blue: #0788dc;
  --orange: #09aeeb;
  --ink: #202326;
  --muted: #65717a;
  --line: #dce4e9;
  --soft: #f2f7fa;
  --white: #fff;
  --green: #2f7d57;
  --red: #b94343;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: #eef4f7;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  min-height: 76px;
  padding: 0 5vw;
  background: #17191b;
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 3px 16px #071b2b33;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 55px; height: 55px; object-fit: contain; border-radius: 8px; background: white; }
.brand div { display: grid; }
.brand strong { font-size: 15px; letter-spacing: .02em; }
.brand span:last-child { color: #a9becb; font-size: 12px; margin-top: 2px; }
nav { align-self: stretch; display: flex; gap: 8px; }
.nav-button {
  border: 0; color: #b8cad5; background: transparent; padding: 0 18px;
  border-bottom: 3px solid transparent; font-weight: 700;
}
.nav-button:hover, .nav-button.active { color: white; border-bottom-color: var(--orange); }
.count { background: #ffffff1c; padding: 2px 7px; border-radius: 999px; font-size: 11px; }
.cloud-button { display: flex; align-items: center; gap: 7px; }
.cloud-dot { width: 8px; height: 8px; border-radius: 50%; background: #78909d; }
.cloud-button.connected .cloud-dot { background: #65d69a; box-shadow: 0 0 0 3px #65d69a22; }

main { width: min(1180px, 92vw); margin: 0 auto; padding: 42px 0 56px; }
.view { display: none; }
.view.active { display: block; }
.auth-home-view { min-height: calc(100vh - 174px); place-items: center; }
.auth-home-view.active { display: grid; }
.auth-home-card {
  width: min(520px, 100%); padding: clamp(34px, 7vw, 58px); text-align: center;
  background: var(--white); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 18px 55px #087bcf1c;
}
.auth-home-logo { display: block; width: min(300px, 82%); margin: -35px auto -24px; }
.auth-home-card h1 {
  margin: 8px 0 15px; color: var(--navy-dark); font-size: clamp(34px, 7vw, 52px);
  line-height: 1; letter-spacing: -.045em;
}
.auth-home-card > p:not(.eyebrow) { margin: 0 auto 27px; max-width: 420px; color: var(--muted); line-height: 1.6; }
.auth-home-card .primary-button { width: auto; min-width: 180px; }
.hero { display: flex; justify-content: space-between; align-items: end; gap: 28px; margin-bottom: 28px; }
.hero.compact { align-items: center; }
.hero h1 { font-size: clamp(32px, 5vw, 54px); letter-spacing: -.045em; line-height: 1; margin: 4px 0 12px; color: var(--navy-dark); }
.hero p:not(.eyebrow) { max-width: 670px; color: var(--muted); margin: 0; line-height: 1.55; }
.eyebrow, .step { margin: 0; text-transform: uppercase; color: var(--blue); font-size: 11px; font-weight: 900; letter-spacing: .15em; }
.status { background: #deeee5; color: var(--green); border-radius: 999px; padding: 10px 15px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.status span { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-right: 7px; }

.calculator-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 22px; }
.panel, .reference-card, .table-panel {
  background: var(--white); border: 1px solid var(--line); border-radius: 15px;
  box-shadow: 0 10px 30px #087bcf0d;
}
.panel { padding: clamp(24px, 4vw, 38px); }
.panel-heading { display: flex; justify-content: space-between; align-items: start; }
h2 { margin: 5px 0 26px; color: var(--navy-dark); font-size: 23px; }
.text-button { border: 0; background: transparent; color: var(--blue); font-size: 13px; font-weight: 800; padding: 5px; }
.input-panel > label, fieldset { display: block; margin-top: 23px; }
label > span, legend { display: block; font-size: 13px; font-weight: 800; margin-bottom: 8px; color: #30434e; }
label small { display: block; color: var(--muted); font-size: 11px; margin-top: 7px; }
.input-with-unit { display: flex; border: 1px solid #b9c7ce; border-radius: 8px; overflow: hidden; background: white; }
.input-with-unit:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px #176b9c18; }
.input-with-unit input { flex: 1; min-width: 0; border: 0; outline: 0; padding: 13px 14px; font-weight: 750; font-size: 17px; }
.input-with-unit > span { min-width: 52px; display: grid; place-items: center; color: var(--muted); background: var(--soft); border-left: 1px solid var(--line); font-size: 12px; font-weight: 800; }
fieldset { padding: 0; border: 0; }
.orientation-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.orientation-card input { position: absolute; opacity: 0; }
.orientation-card > span { display: grid; grid-template-columns: 42px 1fr; column-gap: 10px; padding: 14px; border: 1px solid #b9c7ce; border-radius: 9px; cursor: pointer; }
.orientation-card b { grid-row: 1 / 3; width: 40px; height: 40px; display: grid; place-items: center; background: var(--soft); border-radius: 7px; color: var(--navy); font-size: 20px; }
.orientation-card strong { font-size: 13px; align-self: end; }
.orientation-card small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.orientation-card input:checked + span { border-color: var(--blue); background: #edf8fe; box-shadow: 0 0 0 2px #0788dc1a; }
.orientation-card input:checked + span b { background: var(--blue); color: white; }

.result-panel { background: linear-gradient(145deg, #17191b 0%, #063f69 100%); color: white; border-color: #073b61; }
.result-panel .step { color: #8bc4e4; }
.result-panel h2 { color: white; margin-bottom: 18px; }
.result-value { padding: 26px 0 22px; border-top: 1px solid #ffffff22; border-bottom: 1px solid #ffffff22; }
.result-value span { display: block; color: var(--orange); font-weight: 900; font-size: clamp(64px, 9vw, 90px); line-height: .95; letter-spacing: -.065em; }
.result-value small { display: block; color: #c0d1dc; margin-top: 8px; font-weight: 700; }
.notice { margin: 20px 0; border-radius: 8px; padding: 13px 15px; display: grid; gap: 3px; background: #ffffff12; border-left: 4px solid var(--orange); }
.notice strong { font-size: 12px; }
.notice span { color: #c8d7df; font-size: 11px; line-height: 1.4; }
.notice.low { border-color: #ff7777; }
.notice.dead-zone { border-color: #ff7777; background: #7c24243d; }
.result-details { margin: 0 0 24px; }
.result-details div { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid #ffffff17; }
.result-details dt { color: #b7cad5; font-size: 12px; }
.result-details dd { margin: 0; font-size: 12px; font-weight: 800; text-align: right; }
.primary-button, .secondary-button, .danger-button {
  border-radius: 8px; padding: 12px 17px; font-weight: 850; border: 1px solid transparent;
}
.primary-button { width: 100%; color: white; background: linear-gradient(135deg, #09aeeb, #087bcf); }
.primary-button:hover { background: linear-gradient(135deg, #20baf0, #0788dc); }
.secondary-button { color: var(--navy); border-color: #b9c7ce; background: white; }
.danger-button { color: var(--red); border-color: #e1b4b4; background: white; }
.result-help { margin: 11px 3px 0; color: #b7cad5; font-size: 10px; line-height: 1.45; text-align: center; }

.reference-card { margin-top: 22px; padding: 28px 34px; display: grid; grid-template-columns: .85fr 1.15fr; align-items: center; gap: 30px; }
.reference-card h2 { margin-bottom: 10px; }
.reference-card p:last-child { color: var(--muted); line-height: 1.55; font-size: 13px; }
.diagram svg { width: 100%; height: auto; }
.diagram .rail { fill: none; stroke: #202326; stroke-width: 10; stroke-linecap: round; }
.diagram .chord { stroke: var(--orange); stroke-width: 3; stroke-dasharray: 8 5; }
.diagram .measure { stroke: var(--blue); stroke-width: 3; }
.diagram circle { fill: var(--orange); }
.diagram text { font-size: 14px; fill: var(--muted); font-weight: 700; }
.actions { display: flex; gap: 10px; }
.sync-status { align-self: center; color: var(--muted); font-size: 11px; font-weight: 700; margin-right: 4px; }
.sync-status.error { color: var(--red); }
.sync-status.synced { color: var(--green); }
.table-panel { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1100px; }
th { padding: 13px 11px; text-align: left; background: var(--navy); color: white; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
td { padding: 12px 11px; font-size: 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:hover { background: #f7fafb; }
.empty-state { padding: 55px 20px; text-align: center; display: grid; gap: 7px; color: var(--muted); }
.empty-state strong { color: var(--navy); }
.delete-row { border: 0; background: transparent; color: var(--red); font-weight: 800; }

dialog { width: min(690px, 92vw); border: 0; border-radius: 15px; padding: 0; box-shadow: 0 20px 80px #061a2870; }
dialog::backdrop { background: #081d2bc4; }
#log-form, #auth-form { padding: 30px; }
.dialog-heading { display: flex; justify-content: space-between; }
.dialog-heading h2 { margin-bottom: 20px; }
.icon-button { border: 0; background: var(--soft); border-radius: 50%; width: 35px; height: 35px; font-size: 25px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.form-grid input, textarea { width: 100%; border: 1px solid #b9c7ce; border-radius: 8px; padding: 12px; outline: 0; }
.form-grid input:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #176b9c18; }
.wide { grid-column: 1 / -1; }
.dialog-summary { margin-top: 18px; background: var(--soft); border-radius: 8px; padding: 13px; font-size: 12px; color: var(--muted); }
.raw-data-option {
  display: flex; gap: 12px; align-items: flex-start; margin-top: 18px;
  padding: 14px; border: 1px solid #b7d5c3; border-radius: 9px; background: #eff8f2;
}
.raw-data-option input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--green); }
.raw-data-option > span { margin: 0; }
.raw-data-option strong { display: block; color: #235f42; font-size: 13px; }
.raw-data-option small { display: block; margin-top: 5px; color: #4e6c5b; line-height: 1.4; font-weight: 500; }
.source-local { color: #ffd079; }
.dialog-actions { margin-top: 20px; display: flex; justify-content: end; gap: 10px; }
.dialog-actions .primary-button { width: auto; }
.auth-copy { margin: -10px 0 22px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.single-column { grid-template-columns: 1fr; }
.form-error { padding: 10px 12px; border-radius: 7px; color: var(--red); background: #fff0f0; font-size: 12px; }
.account-card { padding: 18px; border-radius: 9px; background: #eff8f2; display: grid; gap: 5px; }
.account-card strong { color: #235f42; }
.account-card span { color: #4e6c5b; font-size: 12px; }

@media (max-width: 760px) {
  .topbar { padding: 0 16px; align-items: stretch; }
  .brand div { display: none; }
  .nav-button { padding: 0 10px; font-size: 12px; }
  .cloud-button { padding: 0 8px; }
  #cloud-label { display: none; }
  main { padding-top: 28px; }
  .hero { display: block; }
  .status { display: inline-block; margin-top: 18px; }
  .calculator-grid, .reference-card { grid-template-columns: 1fr; }
  .result-panel { grid-row: 1; }
  .orientation-options, .form-grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .hero.compact .actions { margin-top: 20px; }
}
