/* Huize Nauta: mobile first, design tokens per theme. boot.js sets data-theme on <html>. */

:root,
:root[data-theme="light"] {
    --bg: #f4f6f5;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --border: #dfe5e2;
    --text: #16201d;
    --text-muted: #5b6b66;
    --accent: #2f6f5e;
    --accent-hover: #285f50;
    --accent-contrast: #ffffff;
    --accent-soft: #e3f0ec;
    --danger: #b3261e;
    --danger-soft: #fbe9e7;
    --focus: #1a73e8;
    --shadow: 0 1px 2px rgb(16 32 28 / 8%), 0 2px 8px rgb(16 32 28 / 6%);
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #101315;
    --surface: #181c1f;
    --surface-raised: #1f2427;
    --border: #2b3236;
    --text: #e8eeec;
    --text-muted: #9aa9a4;
    --accent: #5fb89f;
    --accent-hover: #74c8b0;
    --accent-contrast: #0b1512;
    --accent-soft: #1d2d28;
    --danger: #f2877f;
    --danger-soft: #3a1f1d;
    --focus: #8ab4f8;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
}

h1, h2, h3 {
    line-height: 1.25;
    margin: 0 0 .5rem;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }

p { margin: 0 0 1rem; }

a { color: var(--accent); }

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/* --- Boot splash and error bar ------------------------------------------------------------ */

.boot-splash {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--accent);
    font-weight: 600;
    font-size: 1.1rem;
}

.boot-splash-icon {
    width: 56px;
    height: 56px;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
    background: var(--danger-soft);
    color: var(--danger);
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 1rem;
    top: .75rem;
}

/* --- Shell -------------------------------------------------------------------------------- */

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.app-top {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
}

.app-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .6rem max(1rem, env(safe-area-inset-left)) .2rem max(1rem, env(safe-area-inset-right));
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
}

.brand svg {
    width: 26px;
    height: 26px;
    color: var(--accent);
}

.user-chip {
    color: var(--text-muted);
    font-size: .875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 50vw;
}

.tabs,
.subtabs {
    display: flex;
    gap: .25rem;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 0 max(.5rem, env(safe-area-inset-left));
}

.tabs::-webkit-scrollbar,
.subtabs::-webkit-scrollbar {
    display: none;
}

.tab {
    flex: 0 0 auto;
    padding: .65rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 3px solid transparent;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

/* Icons only: share the width so the tabs are easy to hit with a thumb. */
.tab {
    flex: 1 1 0;
    justify-content: center;
}

.tab svg {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tab:hover { color: var(--text); }

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.subtabs {
    padding-top: .5rem;
    padding-bottom: .6rem;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.subtab {
    flex: 0 0 auto;
    padding: .4rem .9rem;
    border-radius: 999px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: .925rem;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
}

.subtab:hover { background: var(--accent-soft); }

.subtab.active {
    background: var(--accent);
    color: var(--accent-contrast);
}

.content {
    flex: 1;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 1.25rem max(1rem, env(safe-area-inset-left)) calc(2rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-right));
}

/* --- Cards, forms, buttons ---------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    margin-bottom: 1rem;
}

.field label {
    font-weight: 600;
    font-size: .925rem;
}

.field input,
.field select {
    font: inherit;
    /* 16px stops iOS from zooming in on focus. */
    font-size: 16px;
    padding: .7rem .8rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-raised);
    color: var(--text);
    min-height: 48px;
}

.hint {
    color: var(--text-muted);
    font-size: .875rem;
}

.btn {
    font: inherit;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .7rem 1.1rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-raised);
    color: var(--text);
    cursor: pointer;
    min-height: 48px;
    text-decoration: none;
}

.btn:hover { border-color: var(--accent); }

.btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-danger {
    color: var(--danger);
    border-color: var(--danger);
    background: transparent;
}

.btn-small {
    min-height: 36px;
    padding: .3rem .75rem;
    font-size: .875rem;
}

.btn-block { width: 100%; }

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.alert {
    padding: .75rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    background: var(--accent-soft);
}

.alert-error {
    background: var(--danger-soft);
    color: var(--danger);
}

/* --- Login -------------------------------------------------------------------------------- */

.login-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
}

.login-card {
    width: 100%;
    max-width: 420px;
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    margin-bottom: 1.25rem;
    color: var(--accent);
}

.login-brand svg { width: 56px; height: 56px; }
.login-brand h1 { color: var(--text); margin: 0; }

.divider {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: var(--text-muted);
    font-size: .875rem;
    margin: 1rem 0;
}

.divider::before,
.divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* --- Lists -------------------------------------------------------------------------------- */

.list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
}

.list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .75rem 0;
    border-bottom: 1px solid var(--border);
}

.list li:last-child { border-bottom: 0; }

.segmented {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.segmented button {
    font: inherit;
    padding: .6rem 1rem;
    min-height: 44px;
    border: 0;
    background: var(--surface-raised);
    color: var(--text);
    cursor: pointer;
}

.segmented button + button { border-left: 1px solid var(--border); }

.segmented button[aria-pressed="true"] {
    background: var(--accent);
    color: var(--accent-contrast);
}

/* Welcome steps */
.steps {
    list-style: none;
    margin: 0 0 1.25rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.steps li {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: var(--text-muted);
}

.steps .mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    border: 2px solid var(--border);
    font-size: .875rem;
    font-weight: 700;
}

.steps .done { color: var(--text); }

.steps .done .mark {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

.steps .current { color: var(--text); font-weight: 600; }
.steps .current .mark { border-color: var(--accent); color: var(--accent); }

.install-card h2 { margin-bottom: .25rem; }

.hint-list {
    margin: 0;
    padding-left: 1.25rem;
}

/* --- Lighting ----------------------------------------------------------------------------- */

.room { padding: 1rem 1.25rem; }

.room-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.room-title h2 { margin: 0; }
.room-title .hint { display: block; }

.room-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.icon-btn:hover,
.icon-btn[aria-expanded="true"] {
    background: var(--accent-soft);
    color: var(--accent);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.switch {
    position: relative;
    flex: 0 0 auto;
    width: 56px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--border);
    cursor: pointer;
    transition: background .15s;
}

.switch[aria-checked="true"] { background: var(--accent); }

.switch:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.switch-knob {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
    transition: transform .15s;
}

.switch[aria-checked="true"] .switch-knob { transform: translateX(24px); }

.switch-small {
    width: 46px;
    height: 26px;
}

.switch-small .switch-knob {
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
}

.switch-small[aria-checked="true"] .switch-knob { transform: translateX(20px); }

.lights {
    list-style: none;
    margin: 1rem 0 0;
    padding: .25rem 0 0;
    border-top: 1px solid var(--border);
}

.lights li { padding: .6rem 0; }

.light-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.dim-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-top: .4rem;
}

.dim-row input[type="range"] {
    flex: 1;
    min-height: 32px;
    accent-color: var(--accent);
}

.dim-value {
    min-width: 3rem;
    text-align: right;
}

.placeholder {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem 1rem;
}

@media (min-width: 720px) {
    .content { padding-top: 1.75rem; }
}
