/* ==========================================================================
   BanksRd — "Smart-home dark" design (handoff option 2a)
   Rounded tiles, native-app feel. Dark is the default scheme; the light
   scheme is applied via .theme-light on the app shell.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Theme tokens
   Dark is the base. `.theme-system` (the default) follows the device's
   prefers-color-scheme; `.theme-dark` / `.theme-light` force a scheme.
   -------------------------------------------------------------------------- */
:root,
.theme-dark,
.theme-system {
    --bg: #0a0a0c;
    --text: #f2f2f4;
    --sub: #98989f;
    --faint: #5a5a60;
    --card: #1c1c1e;
    --card2: #141416;
    --card-hover: #26262a;
    --chip: #2c2c30;
    --chip-text: #c8c8cc;
    --avatar-tile: linear-gradient(145deg, #3a3a40, #232327);
    --accent: #30d158;
    --accent-hover: #4ade70;
    --accent-ink: #04140c;
    --accent-soft: rgba(48, 209, 88, 0.14);
    --accent-chip: rgba(48, 209, 88, 0.16);

    --ok: #30d158;
    --neutral: #98989f;
    --pending: #ffd60a;
    --offline: #5a5a60;
    --error: #ff453a;
}

.theme-light {
    --bg: #f2f2f7;
    --text: #1c1c1e;
    --sub: #7c7c82;
    --faint: #a3a3ab;
    --card: #ffffff;
    --card2: #f7f7fa;
    --card-hover: #ececf1;
    --chip: #e9e9ee;
    --chip-text: #4b4b52;
    --avatar-tile: linear-gradient(145deg, #ffffff, #e2e2e8);

    --ok: #248a3d;
    --neutral: #6d6d72;
    --pending: #b25000;
    --offline: #8e8e93;
    --error: #d70015;
}

/* System mode on a light device (same values as .theme-light) */
@media (prefers-color-scheme: light) {
    :root,
    .theme-system {
        --bg: #f2f2f7;
        --text: #1c1c1e;
        --sub: #7c7c82;
        --faint: #a3a3ab;
        --card: #ffffff;
        --card2: #f7f7fa;
        --card-hover: #ececf1;
        --chip: #e9e9ee;
        --chip-text: #4b4b52;
        --avatar-tile: linear-gradient(145deg, #ffffff, #e2e2e8);

        --ok: #248a3d;
        --neutral: #6d6d72;
        --pending: #b25000;
        --offline: #8e8e93;
        --error: #d70015;
    }

    .theme-system .inset-field__input {
        color-scheme: light;
    }
}

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

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: "Hanken Grotesk", "Segoe UI", system-ui, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6, p {
    margin: 0;
}

h1:focus, h2:focus, h3:focus {
    outline: none;
}

button {
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.text-danger {
    color: var(--error);
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 12px 16px;
    background: var(--pending, #ffd60a);
    color: #1c1c1e;
}

/* --------------------------------------------------------------------------
   App shell
   -------------------------------------------------------------------------- */
.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background-color: var(--bg);
    color: var(--text);
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* --------------------------------------------------------------------------
   Page scaffolding
   -------------------------------------------------------------------------- */
.page {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: calc(20px + env(safe-area-inset-top, 0px)) 22px calc(20px + env(safe-area-inset-bottom, 0px));
}

.page-header {
    padding-bottom: 4px;
}

.page-header--row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-header--brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

/* Small version of the login app tile, used beside the home page title */
.brand-tile {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: var(--avatar-tile);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
}

.brand-tile__icon {
    width: 22px;
    height: 22px;
    color: var(--accent);
}

.page-eyebrow {
    font-size: 13px;
    font-weight: 600;
    color: var(--sub);
    letter-spacing: 0.06em;
}

.page-title {
    font-size: 26px;
    font-weight: 700;
    line-height: 1.15;
}

.section-heading {
    margin-top: 14px;
}

.section-heading-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 14px;
    font-size: 11px;
    font-weight: 700;
}

.audit-card--full {
    max-height: none;
}

.card-stack,
.row-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Footer */
.page-footer {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 2px 2px;
    font-size: 11px;
    font-weight: 700;
    color: var(--faint);
}

.page-footer__link {
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
}

.page-footer__signout {
    background: none;
    border: none;
    padding: 0;
    font-size: 11px;
    font-weight: 700;
    color: var(--faint);
    cursor: pointer;
}

/* --------------------------------------------------------------------------
   Shared bits: icons, circles, dots, text roles, chips, avatars
   -------------------------------------------------------------------------- */
.md-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
}

.icon-circle {
    width: 38px;
    height: 38px;
    border-radius: 99px;
    background: var(--chip);
    color: var(--sub);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.icon-circle--accent {
    background: var(--accent-soft);
}

.icon-circle .md-icon {
    width: 20px;
    height: 20px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 99px;
    transition: background-color 0.25s;
}

.card-title {
    font-size: 14px;
    font-weight: 700;
}

.status-line {
    font-size: 12px;
    font-weight: 600;
    transition: color 0.25s;
}

.meta-line {
    font-size: 11px;
    color: var(--sub);
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.chip {
    background: var(--chip);
    color: var(--chip-text);
    border-radius: 99px;
    padding: 4px 11px;
    font-size: 11px;
    font-weight: 600;
}

.chip--admin {
    background: var(--accent-chip);
    color: var(--ok);
    font-weight: 700;
}

/* Toggleable filter pills (audit log) */
.chip-toggle {
    border: none;
    cursor: pointer;
    opacity: 0.45;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.chip-toggle--on {
    opacity: 1;
    background: var(--accent-chip);
    color: var(--ok);
    font-weight: 700;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 99px;
    background: var(--avatar-tile);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex: none;
}

@keyframes busy-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.3; }
}

.pulse {
    animation: busy-pulse 1.1s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Home: garage tiles
   -------------------------------------------------------------------------- */
.garage-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.garage-tile {
    background: var(--card);
    border: none;
    border-radius: 20px;
    padding: 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 22px;
    text-align: left;
    color: var(--text);
    transition: background 0.15s, opacity 0.2s;
    min-height: 44px;
}

.garage-tile:hover {
    background: var(--card-hover);
}

.garage-tile:disabled,
button.row-card:disabled {
    cursor: default;
}

.garage-tile:disabled:hover,
button.row-card:disabled:hover {
    background: var(--card);
}

.garage-tile.is-busy {
    opacity: 0.62;
    pointer-events: none;
}

.garage-tile__top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.garage-tile__body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* --------------------------------------------------------------------------
   Home: row cards (gate, keep-open, bins)
   -------------------------------------------------------------------------- */
.row-card {
    background: var(--card);
    border: none;
    border-radius: 20px;
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    color: var(--text);
    width: 100%;
    min-height: 44px;
    transition: background 0.15s, opacity 0.2s;
}

button.row-card {
    cursor: pointer;
}

button.row-card:hover {
    background: var(--card-hover);
}

.row-card.is-busy {
    opacity: 0.62;
    pointer-events: none;
}

.row-card__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.row-card__right {
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Keep-open switch: 46x26 track, 20px knob (x: 2 off, 12 pending, 21 on) */
.ho-switch {
    width: 46px;
    height: 26px;
    border-radius: 99px;
    background: var(--chip);
    border: none;
    position: relative;
    cursor: pointer;
    flex: none;
    padding: 0;
    transition: background 0.25s ease;
}

.ho-switch:disabled {
    cursor: default;
}

.ho-switch__knob {
    position: absolute;
    top: 3px;
    left: 0;
    width: 20px;
    height: 20px;
    border-radius: 99px;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
    transition: transform 0.25s ease;
}

/* --------------------------------------------------------------------------
   Login
   -------------------------------------------------------------------------- */
.login-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: calc(20px + env(safe-area-inset-top, 0px)) 28px calc(20px + env(safe-area-inset-bottom, 0px));
}

.login-column {
    width: 100%;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-tile {
    width: 70px;
    height: 70px;
    border-radius: 22px;
    background: var(--avatar-tile);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
}

.login-tile__icon {
    width: 32px;
    height: 32px;
    color: var(--accent);
}

.login-heading {
    text-align: center;
}

.login-title {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.login-subtitle {
    font-size: 14px;
    color: var(--sub);
    margin-top: 4px;
}

.login-submit {
    margin-top: 6px;
    width: 100%;
}

/* --------------------------------------------------------------------------
   Text fields (filled card, tiny label above value)
   -------------------------------------------------------------------------- */
.md-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.md-field__card {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--card);
    border-radius: 14px;
    padding: 12px 16px;
    cursor: text;
}

.md-field__label {
    font-size: 11px;
    color: var(--sub);
}

.md-field__input {
    background: transparent;
    border: none;
    outline: none;
    padding: 0;
    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    width: 100%;
}

.md-field__input[type="password"] {
    letter-spacing: 5px;
}

.md-field--error .md-field__card {
    box-shadow: inset 0 0 0 1px var(--error);
}

.md-field__error {
    font-size: 11px;
    color: var(--error);
    padding: 0 16px;
}

/* Dialogs place fields on the elevated card surface */
.md-dialog .md-field__card,
.dialog-permissions {
    background: var(--card2);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.md-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 14px;
    padding: 15px 22px;
    font-size: 15px;
    font-weight: 700;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
    min-height: 44px;
}

.md-button--filled {
    background: var(--accent);
    color: var(--accent-ink);
}

.md-button--filled:hover {
    background: var(--accent-hover);
}

.md-button--tonal {
    background: var(--chip);
    color: var(--chip-text);
}

.md-button--tonal:hover {
    background: var(--card-hover);
}

.md-button--outlined {
    box-shadow: inset 0 0 0 1px var(--chip);
}

.md-button:disabled {
    opacity: 0.45;
    cursor: default;
    pointer-events: none;
}

.md-button__icon {
    width: 18px;
    height: 18px;
}

/* Round accent add button (admin header) */
.add-fab {
    width: 40px;
    height: 40px;
    border-radius: 99px;
    border: none;
    background: var(--accent);
    color: var(--accent-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
}

.add-fab:hover {
    background: var(--accent-hover);
}

.add-fab .md-icon {
    width: 20px;
    height: 20px;
}

/* Quiet inline icon buttons (edit / delete) */
.ghost-icon-button {
    background: none;
    border: none;
    padding: 6px;
    color: var(--sub);
    cursor: pointer;
    display: inline-flex;
    border-radius: 99px;
    transition: color 0.15s, background 0.15s;
}

.ghost-icon-button:hover {
    background: var(--chip);
}

.ghost-icon-button .md-icon {
    width: 18px;
    height: 18px;
}

.ghost-icon-button--danger {
    color: var(--error);
}

.ghost-icon-button--ok {
    color: var(--ok);
}

/* Legacy icon-button class used by shared hosts */
.md-icon-button {
    background: none;
    border: none;
    padding: 8px;
    color: var(--sub);
    cursor: pointer;
    display: inline-flex;
    border-radius: 99px;
}

.md-icon-button:hover {
    background: var(--chip);
}

/* --------------------------------------------------------------------------
   Switch (used in the user dialog permission list)
   -------------------------------------------------------------------------- */
.md-switch {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.md-switch__input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.md-switch__track {
    position: relative;
    width: 46px;
    height: 26px;
    flex-shrink: 0;
    border-radius: 99px;
    background-color: var(--chip);
    transition: background-color 0.25s ease;
}

.md-switch__handle {
    position: absolute;
    top: 3px;
    left: 0;
    width: 20px;
    height: 20px;
    border-radius: 99px;
    background-color: #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
    transform: translateX(2px);
    transition: transform 0.25s ease;
}

.md-switch__input:checked + .md-switch__track {
    background-color: var(--accent);
}

.md-switch__input:checked + .md-switch__track .md-switch__handle {
    transform: translateX(21px);
}

.md-switch__input:disabled ~ * {
    opacity: 0.45;
}

.md-switch__label {
    font-size: 13px;
    font-weight: 600;
    color: var(--chip-text);
}

/* --------------------------------------------------------------------------
   User cards (admin)
   -------------------------------------------------------------------------- */
.user-card {
    background: var(--card);
    border-radius: 20px;
    padding: 16px;
}

.user-card__row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-card__names {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.user-card__name {
    font-size: 15px;
    font-weight: 700;
}

/* Audit log */
.audit-card {
    max-height: 420px;
    overflow-y: auto;
    padding: 6px 16px;
}

.audit-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--chip);
}

.audit-card .audit-row:last-child {
    border-bottom: none;
}

.audit-row__main {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.audit-row__action {
    font-size: 13px;
    font-weight: 600;
}

.audit-row__time {
    flex: none;
    text-align: right;
}

/* Inset sub-fields (bin schedule) */
.inset-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.inset-field {
    flex: 1;
    background: var(--chip);
    border-radius: 12px;
    padding: 9px 12px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.inset-field__label {
    font-size: 10px;
    color: var(--sub);
}

.inset-field__value {
    font-size: 13px;
    font-weight: 700;
}

.inset-field__input {
    background: transparent;
    border: none;
    outline: none;
    padding: 0;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    width: 100%;
    color-scheme: dark;
}

.theme-light .inset-field__input {
    color-scheme: light;
}

/* --------------------------------------------------------------------------
   Linear progress
   -------------------------------------------------------------------------- */
.md-linear-progress {
    position: relative;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    overflow: hidden;
    background-color: var(--chip);
}

.md-linear-progress__bar {
    position: absolute;
    top: 0;
    bottom: 0;
    border-radius: 2px;
    background-color: var(--accent);
}

.md-linear-progress--indeterminate .md-linear-progress__bar--1 {
    animation: md-linear-progress-1 2s infinite linear;
}

.md-linear-progress--indeterminate .md-linear-progress__bar--2 {
    animation: md-linear-progress-2 2s infinite linear;
}

@keyframes md-linear-progress-1 {
    0%   { left: -35%; right: 100%; }
    60%  { left: 100%; right: -90%; }
    100% { left: 100%; right: -90%; }
}

@keyframes md-linear-progress-2 {
    0%   { left: -200%; right: 100%; }
    60%  { left: 107%; right: -8%; }
    100% { left: 107%; right: -8%; }
}

/* --------------------------------------------------------------------------
   Dialog
   -------------------------------------------------------------------------- */
.md-dialog-scrim {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.55);
    animation: fade-in 0.15s;
}

.md-dialog {
    width: 100%;
    min-width: 280px;
    max-width: 420px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 22px;
    border-radius: 20px;
    background-color: var(--card);
    color: var(--text);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
    animation: dialog-in 0.2s ease;
}

.md-dialog__headline {
    display: flex;
    align-items: center;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
}

.md-dialog__headline .md-icon {
    width: 20px;
    height: 20px;
    color: var(--sub);
}

.dialog-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dialog-permissions {
    border-radius: 14px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes dialog-in {
    from { opacity: 0; transform: scale(0.96) translateY(6px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* --------------------------------------------------------------------------
   Snackbar
   -------------------------------------------------------------------------- */
.md-snackbar-host {
    position: fixed;
    left: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: calc(100vw - 32px);
}

.md-snackbar {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    min-width: 280px;
    max-width: 420px;
    padding: 6px 8px 6px 16px;
    border-radius: 14px;
    background-color: var(--card-hover);
    color: var(--text);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
    animation: snackbar-in 0.25s ease;
}

.md-snackbar--error {
    background-color: var(--error);
    color: #fff;
}

.md-snackbar--success {
    background-color: var(--accent);
    color: var(--accent-ink);
}

.md-snackbar--warning {
    background-color: var(--pending);
    color: #1c1c1e;
}

.md-snackbar__text {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    line-height: 20px;
}

.md-snackbar__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border: none;
    border-radius: 99px;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.md-snackbar__close .md-icon {
    width: 18px;
    height: 18px;
}

@keyframes snackbar-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --------------------------------------------------------------------------
   Circular progress (also the pre-Blazor boot loader — this file is a plain
   static asset, so it is available before the runtime starts)
   -------------------------------------------------------------------------- */
.md-boot-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    height: 100dvh;
}

.md-circular-progress {
    width: 48px;
    height: 48px;
    animation: circular-rotate 1.6s linear infinite;
}

.md-circular-progress circle {
    stroke: var(--accent, #30d158);
    stroke-linecap: round;
    stroke-dasharray: 125.66;
    animation: circular-arc 1.2s ease-in-out infinite;
}

@keyframes circular-rotate {
    to { transform: rotate(360deg); }
}

@keyframes circular-arc {
    0%   { stroke-dashoffset: 119; }
    50%  { stroke-dashoffset: 34; }
    100% { stroke-dashoffset: 119; }
}

/* --------------------------------------------------------------------------
   Misc utilities
   -------------------------------------------------------------------------- */
.md-spacer {
    flex: 1 1 auto;
}

.mr-3 {
    margin-right: 12px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
