:root {
    --bg: #0f1117;
    --bg2: #1a1d2e;
    --bg3: #242840;
    --accent: #4a7cff;
    --accent-hover: #6090ff;
    --text: #e0e4f0;
    --text2: #8890aa;
    --green: #3daa5c;
    --red: #d44;
    --orange: #d8862a;
    --blue: #3a78cc;
    --border: #2a2e44;
    --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
}

/* ── Auth ──────────────────────────────────────────────────── */
[hidden] { display: none !important; }

#auth-view {
    display: flex; align-items: center; justify-content: center;
    min-height: 100dvh; padding: 20px;
}

.auth-card {
    background: var(--bg2); border-radius: var(--radius);
    padding: 40px 32px; width: 100%; max-width: 380px;
    text-align: center;
}

.auth-logo { font-size: 56px; margin-bottom: 8px; }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-subtitle { color: var(--text2); margin-bottom: 28px; font-size: 14px; }

.auth-card input {
    display: block; width: 100%; padding: 12px 14px;
    margin-bottom: 12px; border: 1px solid var(--border);
    border-radius: 8px; background: var(--bg3);
    color: var(--text); font-size: 15px; outline: none;
}
.auth-card input:focus { border-color: var(--accent); }

.auth-switch { margin-top: 16px; font-size: 13px; color: var(--text2); }
.auth-switch a { color: var(--accent); text-decoration: none; }

.error-msg {
    margin-top: 14px; padding: 10px; border-radius: 8px;
    background: rgba(220,60,60,.15); color: #f88; font-size: 13px;
}

/* ── Header ────────────────────────────────────────────────── */
header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px; background: var(--bg2);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 28px; }
header h2 { font-size: 17px; font-weight: 600; }
#user-name { font-size: 13px; color: var(--text2); }

.btn-back {
    background: none; border: none; color: var(--accent);
    font-size: 22px; cursor: pointer; padding: 4px 8px;
}

/* ── Main ──────────────────────────────────────────────────── */
main { padding: 16px 20px; max-width: 640px; margin: 0 auto; }

.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px;
}
.section-header h3 { font-size: 18px; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--bg2); border-radius: var(--radius);
    padding: 18px; margin-bottom: 14px;
}
.card h3 { font-size: 15px; margin-bottom: 12px; color: var(--text2); font-weight: 600; }
.card-muted { opacity: .7; }

/* ── Device List ───────────────────────────────────────────── */
.device-card {
    background: var(--bg2); border-radius: var(--radius);
    padding: 16px 18px; margin-bottom: 10px; cursor: pointer;
    border: 1px solid var(--border); transition: border-color .15s;
}
.device-card:hover { border-color: var(--accent); }
.device-card .name { font-size: 16px; font-weight: 600; }
.device-card .meta { font-size: 12px; color: var(--text2); margin-top: 4px; }
.device-card .status-badge {
    display: inline-block; padding: 2px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600; margin-top: 6px;
}
.badge-online { background: rgba(61,170,92,.2); color: #5dda7c; }
.badge-locked { background: rgba(220,60,60,.2); color: #f88; }
.badge-offline { background: rgba(100,100,120,.2); color: #888; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn-primary {
    display: block; width: 100%; padding: 12px;
    background: var(--accent); color: #fff; border: none;
    border-radius: 8px; font-size: 15px; font-weight: 600;
    cursor: pointer; transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-full { margin-top: 8px; margin-bottom: 14px; }

.btn-small {
    padding: 6px 14px; border-radius: 6px; font-size: 13px;
    border: none; cursor: pointer; font-weight: 500;
}
.btn-small.btn-primary { background: var(--accent); color: #fff; width: auto; display: inline-block; }
.btn-small.btn-outline {
    background: transparent; color: var(--text2);
    border: 1px solid var(--border);
}
.btn-small.btn-red { background: rgba(220,60,60,.2); color: #f88; }

.action-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.btn-action {
    padding: 12px 8px; border: none; border-radius: 8px;
    font-size: 13px; font-weight: 600; cursor: pointer;
    color: #fff; transition: opacity .15s;
}
.btn-action:hover { opacity: .85; }
.btn-blue { background: var(--blue); }
.btn-green { background: var(--green); }
.btn-orange { background: var(--orange); }
.btn-red { background: var(--red); }

/* ── Tabs ──────────────────────────────────────────────────── */
.tab-bar {
    display: flex; gap: 4px; margin-bottom: 16px;
    border-bottom: 1px solid var(--border); padding-bottom: 8px;
}
.tab {
    padding: 8px 16px; background: none; border: none;
    color: var(--text2); font-size: 13px; cursor: pointer;
    border-radius: 6px; font-weight: 500;
}
.tab.active { background: var(--bg3); color: var(--text); }

/* ── Forms ─────────────────────────────────────────────────── */
.inline-form {
    display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap;
}
.inline-form input {
    flex: 1; min-width: 120px; padding: 8px 12px;
    background: var(--bg3); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); font-size: 13px; outline: none;
}
.inline-form input:focus { border-color: var(--accent); }

/* ── Schedule Editor ───────────────────────────────────────── */
.day-row {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 0; border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.day-row:last-child { border-bottom: none; }
.day-row label { width: 32px; }
.day-name { width: 80px; font-size: 13px; font-weight: 500; }
.day-row input[type="time"] {
    width: 90px; padding: 6px; background: var(--bg3);
    border: 1px solid var(--border); border-radius: 6px;
    color: var(--text); font-size: 13px;
}
.day-row input[type="number"] {
    width: 65px; padding: 6px; background: var(--bg3);
    border: 1px solid var(--border); border-radius: 6px;
    color: var(--text); font-size: 13px; text-align: center;
}
.day-row .unit { font-size: 12px; color: var(--text2); }

/* ── List Items ────────────────────────────────────────────── */
.list-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px; background: var(--bg3); border-radius: 6px;
    margin-bottom: 6px; font-size: 13px;
}
.list-item .item-name { flex: 1; }
.list-item .item-desc { color: var(--text2); margin-left: 8px; }
.list-item button {
    background: none; border: none; color: var(--red);
    cursor: pointer; font-size: 16px; padding: 2px 6px;
}

/* ── Status Grid ───────────────────────────────────────────── */
.status-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.stat {
    background: var(--bg3); border-radius: 8px; padding: 12px;
}
.stat .label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 4px; }
.stat .value.locked { color: #f88; }
.stat .value.active { color: #5dda7c; }

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    padding: 10px 24px; border-radius: 8px; font-size: 14px;
    background: var(--bg3); border: 1px solid var(--border);
    z-index: 100; animation: fadeIn .2s;
}
.toast.success { border-color: var(--green); color: #5dda7c; }
.toast.error { border-color: var(--red); color: #f88; }

@keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

/* ── Code ──────────────────────────────────────────────────── */
code {
    background: var(--bg3); padding: 2px 8px; border-radius: 4px;
    font-size: 12px; word-break: break-all;
}

/* ── Mobile ────────────────────────────────────────────────── */
@media (max-width: 480px) {
    main { padding: 12px 14px; }
    .action-grid { grid-template-columns: repeat(2, 1fr); }
    .status-grid { grid-template-columns: 1fr; }
    .day-row { gap: 4px; }
    .day-name { width: 60px; font-size: 12px; }
    .day-row input[type="time"] { width: 80px; }
}
