/* site.css — base styles, themed via CSS custom properties (ported from the ESP32 web UI) */
*, *::before, *::after { box-sizing: border-box; }

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --card-radius: 12px;
    --radius: .375rem;
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.18);
    --transition: all 0.2s ease-in-out;
    --warning-bg: #fef9c3;
    --warning-text: #854d0e;
    --warning-border: #fde047;
    --info-bg: #dbeafe;
    --info-text: #1e40af;
    --info-border: #93c5fd;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --success-border: #86efac;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    --error-border: #fca5a5;
    --switch-track-off-bg: #e2e8f0;
    --switch-track-off-border: #64748b;
    --switch-knob-bg: #ffffff;
    --switch-knob-border: #475569;
    --switch-track-on-bg: var(--primary);
    --switch-track-on-border: var(--primary-hover);
    --switch-knob-on-border: var(--primary-hover);
    --btn-primary-bg: var(--primary);
    --btn-primary-hover-bg: var(--primary-hover);
    --btn-danger-bg: #dc2626;
    --btn-danger-hover-bg: #b91c1c;
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --bg-body: #0f172a;
    --bg-surface: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
    --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.28);
    --warning-bg: #3b2504;
    --warning-text: #fde047;
    --warning-border: #ca8a04;
    --info-bg: #1e3a5f;
    --info-text: #93c5fd;
    --info-border: #2563eb;
    --success-bg: #14532d;
    --success-text: #86efac;
    --success-border: #16a34a;
    --error-bg: #450a0a;
    --error-text: #fca5a5;
    --error-border: #ef4444;
    --switch-track-off-bg: #253144;
    --switch-track-off-border: #cbd5e1;
    --switch-knob-bg: #f8fafc;
    --switch-knob-border: #475569;
    --switch-track-on-bg: var(--primary);
    --switch-track-on-border: #93c5fd;
    --switch-knob-on-border: #93c5fd;
    --btn-primary-bg: #2563eb;
    --btn-primary-hover-bg: #3b82f6;
    --btn-danger-bg: #dc2626;
    --btn-danger-hover-bg: #ef4444;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    margin: 0;
    color: var(--text-main);
    background: var(--bg-body);
    transition: background-color 0.3s ease, color 0.3s ease;
}

a { color: var(--primary); }
a:hover { color: var(--primary-hover); }

header { background: var(--bg-surface); color: var(--text-main); padding: .75rem 1.5rem; border-bottom: 1px solid var(--border); }
header a { color: var(--text-muted); text-decoration: none; transition: var(--transition); }
header a:hover { color: var(--primary); }

.navbar { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; }
.navbar .brand { font-weight: 700; font-size: 1.1rem; color: var(--text-main); }
.nav-right { display: flex; align-items: center; gap: 1.25rem; }

.user-menu { position: relative; }
.user-menu summary {
    cursor: pointer;
    list-style: none;
    color: var(--text-main);
    font-weight: 600;
    padding: .3rem .6rem;
    border-radius: var(--radius);
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary::after { content: "\25BE"; margin-left: .4rem; font-size: .7em; opacity: .8; }
.user-menu summary:hover,
.user-menu[open] summary { background: var(--bg-body); }

.user-menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: .4rem;
    min-width: 140px;
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    z-index: 20;
}
.user-menu-dropdown a {
    display: block;
    padding: .55rem .9rem;
    color: var(--text-main);
}
.user-menu-dropdown a:hover { background: var(--bg-body); }

main { max-width: 960px; margin: 2rem auto; padding: 0 1rem; }
footer { text-align: center; padding: 2rem; color: var(--text-muted); font-size: .85rem; }

.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-success { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success-border); }
.alert-error   { background: var(--error-bg); color: var(--error-text); border: 1px solid var(--error-border); }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border); }
.alert-info    { background: var(--info-bg); color: var(--info-text); border: 1px solid var(--info-border); }

.oauth-login-box {
    max-width: 400px;
    margin: 4rem auto;
    padding: 2rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    box-shadow: var(--shadow);
}

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: .25rem; font-weight: 600; color: var(--text-main); }
.form-group input {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    background: var(--bg-surface);
    color: var(--text-main);
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .5rem .75rem; border: 1px solid var(--border); text-align: left; }
th { background: var(--bg-body); color: var(--text-muted); }

.muted { color: var(--text-muted); }

.status-dot { display: inline-block; width: .65rem; height: .65rem; border-radius: 50%; }
.status-dot.connected { background: var(--success-text); box-shadow: 0 0 0 2px var(--success-bg); }
.status-dot.disconnected { background: var(--border); }

/* Buttons (ported from the ESP32 web UI). Each variant is self-contained so it
   renders correctly whether used alone (e.g. <button class="btn-primary">) or
   combined with .btn (e.g. <button class="btn btn-primary">). */
.btn,
.btn-primary,
.btn-secondary,
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .375rem;
    padding: .5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    background: var(--bg-surface);
    color: var(--text-main);
    font-weight: 500;
    font-size: .875rem;
    line-height: 1.25;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: var(--transition);
}
.btn:hover, .btn-secondary:hover { background: var(--bg-body); }
.btn:disabled, .btn-primary:disabled, .btn-secondary:disabled, .btn-danger:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--btn-primary-bg); color: #fff; border-color: var(--btn-primary-bg); }
.btn-primary:hover { background: var(--btn-primary-hover-bg); border-color: var(--btn-primary-hover-bg); }

.btn-secondary { background: var(--bg-surface); color: var(--text-main); border-color: var(--border); }

.btn-sm { padding: .35rem .75rem; font-size: .8rem; }

.btn-danger { background: var(--btn-danger-bg); color: #fff; border-color: var(--btn-danger-bg); }
.btn-danger:hover { background: var(--btn-danger-hover-bg); border-color: var(--btn-danger-hover-bg); }

.badge { display: inline-block; padding: .15rem .5rem; border-radius: .25rem; font-size: .75rem; font-weight: 600; margin-left: .5rem; }
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-warn { background: var(--warning-bg); color: var(--warning-text); }
.badge-danger { background: var(--error-bg); color: var(--error-text); }

.pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; font-size: .875rem; color: var(--text-muted); }
.pagination .pager-links { display: flex; gap: .75rem; align-items: center; }
.pagination .disabled { color: var(--border); }

/* Form fields — selects, labelled inputs and checkboxes (ported look from the ESP32 web UI) */
select,
.field input,
.field select {
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    background: var(--bg-surface);
    color: var(--text-main);
    font-size: .9rem;
    font-family: inherit;
    width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
select:focus,
.field input:focus,
.field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.field label { font-size: .85rem; font-weight: 600; color: var(--text-main); }

/* Toggle switches (ported from the ESP32 web UI's .ui-switch component) */
.ui-switch {
    --ui-switch-size: 42px;
    position: relative;
    display: inline-block;
    width: var(--ui-switch-size);
    height: calc(var(--ui-switch-size) / 2);
    flex-shrink: 0;
}
.ui-switch-input {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    opacity: 0;
    pointer-events: none;
}
.ui-switch-track {
    display: block;
    width: 100%;
    height: 100%;
    border: 2px solid var(--switch-track-off-border);
    border-radius: 999px;
    background: var(--switch-track-off-bg);
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}
.ui-switch-track::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc((var(--ui-switch-size) / 2) - 8px);
    height: calc((var(--ui-switch-size) / 2) - 8px);
    border-radius: 999px;
    background: var(--switch-knob-bg);
    border: 2px solid var(--switch-knob-border);
    box-sizing: border-box;
    transition: transform 0.2s ease, border-color 0.2s ease;
}
.ui-switch-input:checked + .ui-switch-track {
    background: var(--switch-track-on-bg);
    border-color: var(--switch-track-on-border);
    box-shadow: 0 0 0 1px var(--switch-track-on-border);
}
.ui-switch-input:checked + .ui-switch-track::before {
    transform: translateX(calc(var(--ui-switch-size) / 2));
    border-color: var(--switch-knob-on-border);
}
.ui-switch-input:focus-visible + .ui-switch-track {
    box-shadow: var(--focus-ring);
}

/* A labelled row pairing descriptive text with a .ui-switch toggle, replacing
   plain checkboxes for boolean options. */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .9rem;
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
}
.toggle-row:last-child { margin-bottom: 0; }

/* Theme toggle button */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    font-size: 1rem;
    line-height: 1;
    transition: background-color 0.2s;
}
.theme-toggle:hover { background-color: var(--bg-body); }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
