:root {
    color-scheme: dark;
    --bg: #101216;
    --panel: #171a20;
    --panel-2: #1e222a;
    --text: #e8ebf0;
    --muted: #9aa3b2;
    --accent: #36a0fa;
    --danger: #e5484d;
    --ok: #30a46c;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

a { color: var(--accent); text-decoration: none; }

.muted { color: var(--muted); }
.mono { font-family: Consolas, "Courier New", monospace; }

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(1200px 600px at 20% -10%, #1c2a3a, var(--bg));
}

.login-card {
    width: min(400px, 100%);
    background: var(--panel);
    border: 1px solid #262b34;
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}

.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card p { margin: 0 0 18px; }

label { display: block; margin-bottom: 14px; color: var(--muted); }

input[type="text"], input[type="password"] {
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #2c323d;
    background: #0e1014;
    color: var(--text);
    outline: none;
}

input:focus { border-color: var(--accent); }

button, .button {
    display: inline-block;
    border: 0;
    border-radius: 10px;
    padding: 9px 14px;
    background: #262c36;
    color: var(--text);
    cursor: pointer;
    font: inherit;
}

button:hover, .button:hover { background: #303744; }

.primary { background: var(--accent); color: #04121f; font-weight: 600; }
.primary:hover { background: #4fb0ff; }
.danger { background: var(--danger); color: #fff; }
.danger:hover { background: #f1575c; }
.ghost { background: transparent; border: 1px solid #2c323d; }

.alert {
    background: rgba(229, 72, 77, .14);
    border: 1px solid rgba(229, 72, 77, .4);
    color: #ffd2d3;
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 16px;
}

.notice {
    background: rgba(48, 164, 108, .14);
    border: 1px solid rgba(48, 164, 108, .4);
    color: #c8f0d9;
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 16px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
    border-bottom: 1px solid #22262e;
    background: rgba(16, 18, 22, .9);
    position: sticky;
    top: 0;
    backdrop-filter: blur(8px);
}

.brand { font-weight: 700; letter-spacing: .4px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }

.wrap { padding: 24px; max-width: 1280px; margin: 0 auto; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }

.stat {
    background: var(--panel);
    border: 1px solid #22262e;
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat span { color: var(--muted); }
.stat strong { font-size: 24px; }

.panel {
    background: var(--panel);
    border: 1px solid #22262e;
    border-radius: 16px;
    padding: 16px;
    overflow-x: auto;
}

.toolbar-panel {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.search, .add-device { display: flex; align-items: end; gap: 10px; margin: 0; }
.search { flex: 1; }
.search input { flex: 1; margin: 0; }
.add-device label { margin: 0; min-width: 108px; }
.add-device input { width: 150px; margin: 0; }

table { width: 100%; border-collapse: collapse; min-width: 820px; }
th, td { padding: 12px 10px; text-align: left; border-bottom: 1px solid #232831; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
tr:last-child td { border-bottom: 0; }

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge.online { background: rgba(48, 164, 108, .18); color: #62d39a; }
.badge.offline { background: rgba(154, 163, 178, .14); color: var(--muted); }
.badge.locked { background: rgba(229, 72, 77, .18); color: #ff8d90; }

.inline { display: inline; margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 32px; }

.device-card { margin-bottom: 16px; overflow: visible; }
.device-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid #232831;
}

.device-id { font-size: 22px; font-weight: 700; letter-spacing: .8px; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.device-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 24px;
    padding: 14px 0;
    color: var(--muted);
}
.device-meta strong { color: var(--text); font-weight: 500; }
.device-actions { padding-bottom: 14px; }

.iptv-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 16px;
    padding-top: 14px;
    border-top: 1px solid #232831;
}
.iptv-form .wide, .iptv-form .check, .iptv-form > button { grid-column: 1 / -1; }
.iptv-form label { margin-bottom: 12px; }
.iptv-form .check {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--text);
}
.iptv-form .check input { width: auto; margin: 0; }
.iptv-form > button { justify-self: start; }
.clear-binding { margin-top: 12px; }

@media (max-width: 900px) {
    .toolbar-panel { align-items: stretch; flex-direction: column; }
    .add-device { flex-wrap: wrap; }
    .add-device input { flex: 1; }
}

@media (max-width: 720px) {
    .wrap { padding: 14px; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .topbar { padding: 12px 14px; }
    .device-heading { flex-direction: column; }
    .badges { justify-content: flex-start; }
    .iptv-form { grid-template-columns: 1fr; }
    .iptv-form > * { grid-column: 1; }
}
