/* GIMRemoteControl (interim) — dark theme for the week planner and
 * status views.
 *
 * Design tokens in :root; status chips per state; the two views (week
 * planner, status) share the same card/surface language. Mobile-first;
 * comfortable touch targets (>= 44px). */

:root {
    --bg: #0e1014;
    --surface: #15181e;
    --surface-2: #1a1e26;
    --line: #262b36;
    --text: #e8eaf0;
    --muted: #9aa3b5;
    --accent: #1e90ff;
    --accent-2: #63b3ff;
    --on: #2fd48f;        /* running / on */
    --off: #f0b429;       /* off / idle */
    --unknown: #8a93a6;   /* unknown */
    --error: #ff5f56;     /* error / offline */
    --radius: 10px;
    --radius-s: 7px;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

/* Ambient top-right glow. It MUST be a fixed-position pseudo-element:
 * a body background would propagate to the canvas with the tile sized
 * by html's box (the VIEWPORT), so on any page taller than one window
 * the default background-repeat re-drew the glow once per viewport
 * height down the whole document. Fixed + inset 0 anchors it to the
 * window exactly once, at any scroll position. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(1200px 500px at 85% -10%,
                                rgba(30, 144, 255, .08), transparent 60%);
}

/* ---- top bar ---- */
#topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    background: rgba(14, 16, 20, .92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(6px);
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-weight: 650;
    font-size: 16px;
    letter-spacing: .2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.brandDot {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 10px rgba(30, 144, 255, .7);
    flex: none;
}
.connchip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    font-size: 12.5px;
    color: var(--muted);
    transition: opacity .2s;
}
.connchip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--unknown); }
.connchip[data-state="ok"] .dot { background: var(--on); box-shadow: 0 0 8px rgba(47, 212, 143, .8); }
.connchip[data-state="down"] .dot { background: var(--error); }
.connchip[data-state="down"] { color: var(--error); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .45; } }
.userchip {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 13.5px;
    min-width: 0;
}
.userchip > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userchip .logout {
    color: var(--accent-2);
    text-decoration: none;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    background: var(--surface);
    white-space: nowrap;
}
.userchip .logout:hover { border-color: var(--accent); }

/* ---- layout ---- */
main { max-width: 940px; margin: 0 auto; padding: 14px 16px 60px; }

.tabs {
    display: flex;
    gap: 6px;
    margin: 10px 0 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 5px;
}
.tab {
    flex: 1;
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    padding: 11px 8px;
    min-height: 44px;
    border-radius: var(--radius-s);
    cursor: pointer;
    transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
    background: var(--surface-2);
    color: var(--text);
    box-shadow: inset 0 0 0 1px var(--line);
}

.hint { color: var(--muted); margin: 0 0 16px; max-width: 60ch; }
.hidden { display: none !important; }

/* ---- surfaces ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.card h2 {
    margin: 0 0 12px;
    font-size: 16px;
    letter-spacing: .3px;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 650;
}
.card.offline { opacity: .75; }
.card.offline h2 { color: var(--error); }

.app-loading {
    padding: 22px 6px;
    color: var(--muted);
    text-align: center;
}

/* ---- chips ---- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--muted);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.on { color: var(--on); border-color: rgba(47, 212, 143, .4); }
.chip.off { color: var(--off); border-color: rgba(240, 180, 41, .4); }
.chip.auto { color: var(--accent-2); border-color: rgba(99, 179, 255, .4); }
.chip.unknown { color: var(--unknown); }
.chip.error { color: var(--error); border-color: rgba(255, 95, 86, .4); }

/* ---- week planner ---- */
.modegrid { display: flex; flex-wrap: wrap; gap: 10px; }
.modebox {
    flex: 1 1 150px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    background: var(--surface-2);
    padding: 13px 14px;
    cursor: pointer;
    min-height: 52px;
    transition: border-color .15s, background .15s;
    position: relative;
}
.modebox:hover { border-color: var(--accent); }
.modebox.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
    background: #152f4a;
}
/* The radio stays in the DOM and keyboard-focusable (visually hidden),
 * but the ICON + card highlight now carry the selection state. */
.modebox input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}
.modebox:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.modebox .mlabel { display: flex; flex-direction: column; }
.modebox .mlabel b { font-size: 15px; }
.modebox .mlabel span { color: var(--muted); font-size: 12.5px; }
.modebox .icon {
    width: 22px; height: 22px; flex: none;
    color: var(--muted);
    transition: color .15s;
}
.modebox:hover .icon { color: var(--text); }
.modebox.selected .icon { color: var(--accent); }

#timerCard .note { color: var(--muted); font-size: 13px; margin: -6px 0 12px; }

.periods { display: flex; flex-direction: column; gap: 10px; }
.prow {
    display: grid;
    grid-template-columns: minmax(110px, 1.3fr) auto auto auto 44px;
    gap: 8px;
    align-items: center;
}
/* 24-hour time selects — locale-independent display */
.timepair { display: inline-flex; align-items: center; gap: 3px; }
.timepair select {
    width: 64px;
    padding-left: 6px;
    padding-right: 6px;
    text-align: center;
}
.tsep { color: var(--muted); }
.tdash { color: var(--muted); padding: 0 2px; }
select {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    padding: 10px 9px;
    font: inherit;
    min-height: 44px;
    width: 100%;
    color-scheme: dark;
}
.prow .rm {
    appearance: none;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--muted);
    font-size: 18px;
    border-radius: var(--radius-s);
    min-height: 44px;
    cursor: pointer;
}
.prow .rm:hover { color: var(--error); border-color: var(--error); }

.btnrow { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
/* the save action sits at the right edge of the planner */
.btnrow.actions { justify-content: flex-end; }
button.primary, button.ghost {
    appearance: none;
    font: inherit;
    font-weight: 650;
    border-radius: var(--radius-s);
    min-height: 46px;
    padding: 10px 22px;
    cursor: pointer;
    transition: filter .15s, opacity .15s;
}
button.primary {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: #fff;
}
button.primary:hover { filter: brightness(1.12); }
button.primary:disabled {
    background: var(--surface-2);
    color: var(--muted);
    border-color: var(--line);
    cursor: default;
}

/* the save button: disabled while the plan on screen matches the
 * equipment; highlighted as soon as there are unsaved changes. */
#savePlan { display: inline-flex; align-items: center; gap: 8px; }
#savePlan .icon { width: 17px; height: 17px; flex: none; }
#savePlan.dirty { box-shadow: 0 0 1em #225582; }
button.ghost {
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--text);
}
button.ghost:hover { border-color: var(--accent); }

/* ---- status ---- */
.statebox {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    background: var(--surface-2);
    margin-bottom: 14px;
}
.statebox .slabel { color: var(--muted); font-size: 13px; }

.devlist { display: flex; flex-direction: column; gap: 8px; }
.devrow {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    background: var(--surface-2);
}
.devrow .dname { font-weight: 600; overflow-wrap: anywhere; }
.devrow .dtype { color: var(--muted); font-size: 12.5px; }
.devrow .dmeta { min-width: 0; flex: 1; }
.devrow .dstate { margin-left: auto; }

/* ---- notices / toasts ---- */
.page-notice {
    max-width: 620px;
    margin: 48px auto;
    padding: 26px 30px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.page-notice h1 { margin-top: 0; font-size: 22px; }
.page-notice code { background: var(--surface-2); padding: 2px 7px; border-radius: 5px; }
a.button {
    display: inline-block;
    margin-top: 10px;
    padding: 10px 20px;
    min-height: 44px;
    line-height: 24px;
    background: var(--accent);
    border-radius: var(--radius-s);
    color: #fff;
    text-decoration: none;
    font-weight: 650;
}

#toasts {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 18px;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(420px, calc(100vw - 32px));
}
.toast {
    padding: 12px 16px;
    border-radius: var(--radius-s);
    background: var(--surface-2);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    font-size: 14px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-color: rgba(47, 212, 143, .5); }
.toast.err { border-color: rgba(255, 95, 86, .6); }

.foot {
    margin-top: 28px;
    color: var(--muted);
    font-size: 12.5px;
    text-align: center;
}

/* ---- login screen ---- */
.loginwrap { max-width: 400px; margin: 48px auto 0; padding: 0 16px; }
.logincard {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 26px 28px 28px;
    box-shadow: var(--shadow);
}
.logincard h1 { margin: 0 0 2px; font-size: 22px; }
.logincard .hint { margin: 0 0 12px; }
.logincard .formerr {
    border: 1px solid rgba(255, 95, 86, .5);
    background: rgba(255, 95, 86, .08);
    color: var(--error);
    border-radius: var(--radius-s);
    padding: 10px 12px;
    font-size: 13.5px;
    margin: 0 0 6px;
}
.logincard label {
    color: var(--muted);
    font-size: 13px;
    margin-top: 12px;
}
.logincard input {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    padding: 11px 12px;
    font: inherit;
    min-height: 46px;
    color-scheme: dark;
}
.logincard input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}
.logincard button.primary { margin-top: 22px; }

/* the sign-on button (shown only when the deployment configured the
 * OAuth2 flow — see public/login.php); the local form above it stays
 * for museum operator accounts. */
.logincard .ordiv {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 12.5px;
    margin: 18px 0 14px;
}
.logincard .ordiv::before,
.logincard .ordiv::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--line);
}
.logincard a.ssobtn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 46px;
    padding: 10px 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    background: var(--surface-2);
    color: var(--text);
    font-weight: 650;
    text-decoration: none;
    transition: border-color .15s;
}
.logincard a.ssobtn:hover { border-color: var(--accent); }
/* the configured logo (OAUTH_LOGIN_LOGO) sits on a light pill so a
 * dark-mode sign-on mark stays visible on the dark card. */
.logincard a.ssobtn img.ssologo {
    height: 40px;
    width: auto;
    max-width: 110px;
    flex: none;
    border-radius: 4px;
    padding: 2px 7px;
}

@media (max-width: 640px) {
    .prow {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "day rm"
            "start end";
    }
    .prow > select.dayselect { grid-area: day; }
    .prow .rm { grid-area: rm; }
    .prow .tdash { display: none; }
    .prow .tstart { grid-area: start; }
    .prow .tend { grid-area: end; }
}
