:root[data-theme="dark"] {
    --bg: #0f1420;
    --bg-elevated: #171d2c;
    --bg-input: #10182a;
    --border: #262e42;
    --text: #e8ecf4;
    --text-muted: #8b93a7;
    --accent: #4f8cff;
    --accent-text: #ffffff;
    --danger: #e5484d;
    --success: #2fbf71;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
    --bg: #f4f6fb;
    --bg-elevated: #ffffff;
    --bg-input: #ffffff;
    --border: #dde3ee;
    --text: #1b2333;
    --text-muted: #626d82;
    --accent: #2f6fed;
    --accent-text: #ffffff;
    --danger: #d33;
    --success: #1f9d55;
    --shadow: 0 2px 10px rgba(20, 30, 60, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

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

.topbar {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}

.brand {
    font-weight: 700;
    flex: 1;
}

.nav-toggle, .theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 16px;
}

.nav-toggle { display: none; }

.theme-toggle .icon-light { display: none; }
:root[data-theme="light"] .theme-toggle .icon-dark { display: none; }
:root[data-theme="light"] .theme-toggle .icon-light { display: inline; }

.layout {
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
}

.sidebar {
    width: 220px;
    flex-shrink: 0;
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-right: 1px solid var(--border);
    min-height: calc(100vh - 57px);
}

.sidebar a {
    display: block;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
}

.sidebar a:hover { background: var(--bg-elevated); color: var(--text); }
.sidebar a.active { background: var(--accent); color: var(--accent-text); }
.sidebar a.logout { margin-top: auto; color: var(--danger); }

.content {
    flex: 1;
    padding: 24px 20px 60px;
    min-width: 0;
}

.page-title {
    margin: 0 0 18px;
    font-size: 22px;
}

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card h2 {
    margin-top: 0;
    font-size: 16px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin: 12px 0 6px;
}

input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="url"], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    font-size: 14px;
}

input[type="checkbox"] { width: 16px; height: 16px; vertical-align: middle; }

input[type="file"] {
    color: var(--text-muted);
    font-size: 13px;
}

button, .btn {
    display: inline-block;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    margin-top: 16px;
}

button.secondary, .btn.secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

button.danger, .btn.danger {
    background: var(--danger);
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-success { background: rgba(47, 191, 113, 0.15); color: var(--success); border: 1px solid var(--success); }
.alert-error { background: rgba(229, 72, 77, 0.15); color: var(--danger); border: 1px solid var(--danger); }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

th { color: var(--text-muted); font-weight: 600; }

.table-wrap { overflow-x: auto; }

.thumb {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-input);
}

.thumb-wide {
    width: 120px;
    height: 56px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-input);
}

.preview-current {
    max-width: 220px;
    max-height: 120px;
    border-radius: 8px;
    border: 1px solid var(--border);
    display: block;
    margin-top: 8px;
}

.hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
}

.badge.on { background: rgba(47, 191, 113, 0.15); color: var(--success); }
.badge.off { background: rgba(229, 72, 77, 0.15); color: var(--danger); }

.row-actions { white-space: nowrap; }
.row-actions a { margin-right: 10px; font-size: 13px; }

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

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    font-size: 20px;
    margin: 0 0 20px;
    text-align: center;
}

.code-box {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    font-family: Consolas, Menlo, monospace;
    font-size: 13px;
    word-break: break-all;
    color: var(--text-muted);
}

@media (max-width: 860px) {
    .nav-toggle { display: inline-block; }

    .sidebar {
        position: fixed;
        top: 57px;
        left: 0;
        bottom: 0;
        background: var(--bg-elevated);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 15;
        width: 240px;
    }

    .sidebar.open { transform: translateX(0); }

    .content { padding: 18px 14px 50px; }
}
