:root {
    color-scheme: light dark;
    --bg: #eef0f5;
    --bg-gradient: radial-gradient(circle at 15% -10%, #eef1ff 0%, #eef0f5 45%);
    --card-bg: #ffffff;
    --card-border: rgba(15, 23, 42, 0.07);
    --text: #14161f;
    --muted: #6b7280;
    --border: #e4e6ed;
    --primary: #6366f1;
    --primary-2: #8b5cf6;
    --primary-hover: #4f46e5;
    --primary-soft: rgba(99, 102, 241, 0.10);
    --danger: #ef4444;
    --danger-soft: rgba(239, 68, 68, 0.10);
    --ok-bg: #e7f8ee;
    --ok-text: #15803d;
    --error-bg: #fdecec;
    --error-text: #c62828;
    --warn-bg: #fff3cd;
    --warn-text: #8a6416;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.06);
    --radius: 14px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #101116;
        --bg-gradient: radial-gradient(circle at 15% -10%, #1a1c2e 0%, #101116 45%);
        --card-bg: #191b22;
        --card-border: rgba(255, 255, 255, 0.06);
        --text: #f2f2f5;
        --muted: #9aa0aa;
        --border: #2a2d38;
        --primary-soft: rgba(129, 140, 248, 0.16);
        --danger-soft: rgba(248, 113, 113, 0.14);
        --ok-bg: #123321;
        --ok-text: #6fd396;
        --error-bg: #3a1d1d;
        --error-text: #f28b8b;
        --warn-bg: #453714;
        --warn-text: #f0cd7a;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
        --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
    }
}

/* Ghi de theo lua chon thu cong cua nguoi dung (assets/theme.js), bat ke he thong dang o che do nao */
:root[data-theme="light"] {
    --bg: #eef0f5;
    --bg-gradient: radial-gradient(circle at 15% -10%, #eef1ff 0%, #eef0f5 45%);
    --card-bg: #ffffff;
    --card-border: rgba(15, 23, 42, 0.07);
    --text: #14161f;
    --muted: #6b7280;
    --border: #e4e6ed;
    --primary-soft: rgba(99, 102, 241, 0.10);
    --danger-soft: rgba(239, 68, 68, 0.10);
    --ok-bg: #e7f8ee;
    --ok-text: #15803d;
    --error-bg: #fdecec;
    --error-text: #c62828;
    --warn-bg: #fff3cd;
    --warn-text: #8a6416;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.06);
}

:root[data-theme="dark"] {
    --bg: #101116;
    --bg-gradient: radial-gradient(circle at 15% -10%, #1a1c2e 0%, #101116 45%);
    --card-bg: #191b22;
    --card-border: rgba(255, 255, 255, 0.06);
    --text: #f2f2f5;
    --muted: #9aa0aa;
    --border: #2a2d38;
    --primary-soft: rgba(129, 140, 248, 0.16);
    --danger-soft: rgba(248, 113, 113, 0.14);
    --ok-bg: #123321;
    --ok-text: #6fd396;
    --error-bg: #3a1d1d;
    --error-text: #f28b8b;
    --warn-bg: #453714;
    --warn-text: #f0cd7a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-gradient), var(--bg);
    background-attachment: fixed;
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    transition: background-color .25s ease, color .25s ease;
}

/* ---------- Topbar ---------- */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 32px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar h1 {
    font-size: 17px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.site-logo {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.topbar-right { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13px; }

.topbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px 5px 6px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
}

.user-chip .avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    flex-shrink: 0;
}

.theme-controls { display: flex; align-items: center; gap: 8px; }
.theme-controls select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .15s ease;
}
.theme-controls select:hover { border-color: var(--primary); }
.theme-controls input[type="color"] {
    width: 30px;
    height: 30px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    cursor: pointer;
}
.btn-reset-bg {
    color: var(--muted);
    font-size: 13px;
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 8px;
    transition: background-color .15s ease, color .15s ease;
    white-space: nowrap;
}
.btn-reset-bg:hover { color: var(--text); background: var(--bg); }

/* ---------- Layout ---------- */

.layout {
    max-width: 920px;
    margin: 36px auto;
    padding: 0 20px 60px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow-md);
    animation: fadeInUp .35s ease both;
}

.card + .card { animation-delay: .06s; }

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

.card h2 {
    margin: 0 0 20px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

/* ---------- Forms ---------- */

form label {
    display: block;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
}

input[type="text"], input[type="email"], input[type="password"], input[type="datetime-local"], textarea {
    display: block;
    width: 100%;
    margin-top: 7px;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

input[type="text"]:hover, input[type="email"]:hover, input[type="password"]:hover,
input[type="datetime-local"]:hover, textarea:hover {
    border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
}

input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus,
input[type="datetime-local"]:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

textarea { resize: vertical; line-height: 1.5; }

.form-actions { display: flex; gap: 10px; margin-top: 4px; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: transform .12s ease, box-shadow .15s ease, background-color .15s ease, border-color .15s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    border-color: transparent;
    color: #fff;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
}
.btn-primary:hover { box-shadow: 0 6px 18px rgba(99, 102, 241, 0.45); filter: brightness(1.04); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg); }

.btn-small { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }

.btn-danger {
    color: var(--danger);
    border-color: transparent;
    background: var(--danger-soft);
}
.btn-danger:hover { background: var(--danger); color: #fff; box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35); }

.icon { width: 14px; height: 14px; flex-shrink: 0; }

/* ---------- Schedule toggle ---------- */

.schedule-toggle {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: -2px 0 18px;
    padding: 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.radio-pill {
    display: inline-flex !important;
    align-items: center;
    gap: 7px;
    margin: 0 !important;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    width: auto !important;
    background: var(--card-bg);
    color: var(--muted);
    transition: background-color .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.radio-pill input { margin: 0; accent-color: var(--primary); }

.radio-pill:has(input:checked) {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary) inset;
}

.radio-pill:hover { border-color: var(--primary); }

.schedule-toggle input[type="datetime-local"] {
    margin-top: 0;
    max-width: 240px;
    background: var(--card-bg);
}
.schedule-toggle input[type="datetime-local"]:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Alerts ---------- */

.alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 18px;
    font-size: 13.5px;
    font-weight: 500;
    border-left: 3px solid currentColor;
}
.alert-ok { background: var(--ok-bg); color: var(--ok-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }

/* ---------- Table ---------- */

.list-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.list-table th, .list-table td {
    text-align: left;
    padding: 13px 10px;
    border-bottom: 1px solid var(--border);
}
.list-table th {
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.list-table tbody tr { transition: background-color .12s ease; }
.list-table tbody tr:hover { background: var(--bg); }
.list-table tbody tr:last-child td { border-bottom: none; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-form { display: inline; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.badge-on { background: var(--ok-bg); color: var(--ok-text); }
.badge-off { background: var(--border); color: var(--muted); }
.badge-scheduled { background: var(--warn-bg); color: var(--warn-text); }

/* ---------- Auth page ---------- */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp .4s ease both;
}

.auth-card .logo-badge {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    object-fit: cover;
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.4), 0 0 0 3px var(--primary-soft);
    margin-bottom: 16px;
}

.auth-card h1 { font-size: 18px; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.01em; }
.auth-card .subtitle { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.auth-card button { width: 100%; margin-top: 10px; justify-content: center; }

/* ---------- Table scroll wrapper (mobile safety net) ---------- */

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
    .topbar {
        flex-wrap: wrap;
        row-gap: 10px;
        padding: 12px 16px;
    }
    .topbar h1 { font-size: 15px; }
    .topbar-right {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        row-gap: 8px;
        gap: 10px;
    }
    .topbar-divider { display: none; }
    .user-chip span:last-child {
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .layout { margin: 20px auto; padding: 0 14px 40px; gap: 16px; }
    .card { padding: 18px; border-radius: 12px; }
    .card h2 { font-size: 14px; margin-bottom: 16px; }

    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; justify-content: center; }

    .schedule-toggle { flex-direction: column; align-items: stretch; padding: 12px; }
    .radio-pill { justify-content: center; }
    .schedule-toggle input[type="datetime-local"] { max-width: none; width: 100%; }

    .list-table { min-width: 620px; }

    .auth-card { padding: 28px 22px; }
}

@media (max-width: 420px) {
    .theme-controls select { font-size: 12px; padding: 5px 6px; }
    .theme-controls { gap: 6px; }
    .btn-reset-bg { padding: 6px 4px; font-size: 12px; }
}
