:root {
    color-scheme: dark;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    --bg: #050914;
    --surface: rgba(13, 21, 35, .86);
    --surface-2: #101b2c;
    --surface-3: #162438;
    --line: rgba(255, 255, 255, .11);
    --text: #f7f9ff;
    --muted: #99a7bc;
    --accent: #ed3743;
    --accent-dark: #b81827;
    --success: #43d69b;
    --warning: #ffbc52;
    --danger: #ff6570;
    --shadow: 0 24px 65px rgba(0, 0, 0, .34);
}

*, *::before, *::after { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
    min-height: 100%;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 88% -8%, rgba(36, 93, 144, .25), transparent 36rem),
        radial-gradient(circle at 7% 13%, rgba(237, 55, 67, .12), transparent 30rem),
        linear-gradient(145deg, #050914, #07111e 50%, #050914);
}

button, input, select { font: inherit; }
a { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.login-view { display: grid; place-items: center; padding: 20px; }
.login-shell { width: 100%; display: grid; place-items: center; }

.login-card {
    width: min(100%, 430px);
    padding: 38px;
    border: 1px solid var(--line);
    border-radius: 30px;
    background: linear-gradient(145deg, rgba(17, 29, 47, .97), rgba(8, 14, 25, .97));
    box-shadow: var(--shadow);
    backdrop-filter: blur(22px);
}

.brand-mark {
    width: 68px;
    height: 68px;
    margin-bottom: 20px;
    border-radius: 22px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(145deg, #ff4853, #b90e20);
    box-shadow: 0 14px 30px rgba(237, 55, 67, .25), inset 0 1px rgba(255,255,255,.22);
    font-size: 2rem;
    font-weight: 900;
}

.brand-mark.small { width: 50px; height: 50px; margin: 0; border-radius: 16px; font-size: 1.45rem; }
.eyebrow { margin: 0 0 6px; color: #ff7580; font-size: .72rem; font-weight: 800; letter-spacing: .13em; direction: ltr; text-align: right; }
.login-card h1 { margin: 0; font-size: clamp(1.55rem, 5vw, 2rem); }
.login-copy { margin: 13px 0 24px; color: var(--muted); line-height: 1.8; }
.login-form { display: grid; gap: 13px; }

label > span { display: block; margin-bottom: 8px; color: #bdc7d6; font-size: .84rem; font-weight: 700; }
input, select {
    width: 100%;
    height: 48px;
    border: 1px solid rgba(255,255,255,.13);
    border-radius: 13px;
    outline: 0;
    padding: 0 14px;
    color: #fff;
    background: rgba(3, 8, 16, .54);
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

input::placeholder { color: #67758a; }
input:focus, select:focus { border-color: rgba(237, 55, 67, .85); box-shadow: 0 0 0 4px rgba(237, 55, 67, .14); background: rgba(4, 9, 18, .84); }

.primary-button, .secondary-button, .ghost-button, .danger-button {
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 13px;
    padding: 9px 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: #fff;
    cursor: pointer;
    font-weight: 800;
    transition: transform .14s ease, filter .14s ease, background .14s ease;
}

.primary-button { background: linear-gradient(180deg, #f2424d, #c9212e); box-shadow: 0 9px 22px rgba(214, 30, 44, .2); }
.secondary-button { border-color: rgba(255,255,255,.14); background: #19283c; }
.ghost-button { border-color: rgba(255,255,255,.12); background: rgba(255,255,255,.055); }
.danger-button { border-color: rgba(255, 101, 112, .32); color: #ffadb3; background: rgba(255, 67, 80, .09); }
.primary-button:hover, .secondary-button:hover, .ghost-button:hover, .danger-button:hover { filter: brightness(1.1); }
.primary-button:active, .secondary-button:active, .ghost-button:active, .danger-button:active { transform: scale(.98); }

.notice { margin-bottom: 18px; padding: 13px 16px; border: 1px solid; border-radius: 14px; line-height: 1.6; }
.notice.error { border-color: rgba(255,101,112,.3); color: #ffc2c6; background: rgba(255,65,78,.08); }
.notice.success { border-color: rgba(67,214,155,.28); color: #9cf4d0; background: rgba(67,214,155,.08); }

.admin-header {
    position: sticky;
    z-index: 50;
    top: 0;
    min-height: 78px;
    padding: 13px clamp(16px, 4vw, 54px);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    background: rgba(5, 10, 19, .82);
    backdrop-filter: blur(20px) saturate(130%);
}

.header-brand { display: flex; align-items: center; gap: 13px; }
.header-brand h1 { margin: 0; font-size: clamp(1rem, 2.5vw, 1.34rem); }
.header-brand .eyebrow { margin-bottom: 3px; }
.admin-main { width: min(1500px, 100%); margin: 0 auto; padding: 28px clamp(14px, 3.5vw, 48px) 70px; }

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

.stats-row article {
    min-height: 105px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: linear-gradient(145deg, rgba(17, 29, 47, .88), rgba(9, 16, 28, .88));
    box-shadow: 0 12px 30px rgba(0,0,0,.12);
}

.stats-row strong { font-size: clamp(1.5rem, 3vw, 2.1rem); font-variant-numeric: tabular-nums; }
.stats-row span { margin-top: 5px; color: var(--muted); font-size: .85rem; }

.editor-panel, .dashboard-tools {
    margin-bottom: 26px;
    border: 1px solid var(--line);
    border-radius: 25px;
    padding: clamp(16px, 2.8vw, 27px);
    background: linear-gradient(150deg, rgba(15, 25, 41, .94), rgba(8, 14, 25, .94));
    box-shadow: var(--shadow);
}

.section-heading, .group-heading, .server-list-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.section-heading h2, .editor-heading h2 { margin: 0; font-size: clamp(1.25rem, 3vw, 1.7rem); }
.editor-heading code { display: inline-block; margin-top: 8px; color: #8ea0b7; }
.heading-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.form-box {
    margin-top: 18px;
    border: 1px solid var(--line);
    border-radius: 18px;
    overflow: hidden;
    background: rgba(4, 9, 17, .36);
}

.form-box > summary, .server-editor > summary {
    min-height: 58px;
    padding: 14px 17px;
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: 800;
    list-style: none;
}

.form-box > summary::-webkit-details-marker, .server-editor > summary::-webkit-details-marker { display: none; }
.form-box > summary::before { content: "+"; width: 27px; height: 27px; margin-left: 10px; border-radius: 9px; display: grid; place-items: center; color: #ff7c86; background: rgba(237,55,67,.1); }
.form-box[open] > summary::before { content: "−"; }

.form-grid {
    padding: 18px;
    border-top: 1px solid rgba(255,255,255,.08);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
}

.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-start; gap: 10px; }
.form-actions .primary-button { min-width: 190px; }
.checkbox-label { min-height: 44px; display: flex; align-items: center; gap: 11px; cursor: pointer; }
.checkbox-label input { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--accent); }
.checkbox-label span { margin: 0; color: #d7deea; }
.helper-note { padding: 11px 13px; border-radius: 12px; color: #9eb0c7; background: rgba(54, 107, 157, .1); line-height: 1.6; font-size: .82rem; }
.helper-note.warning { color: #ffd08b; background: rgba(255, 176, 56, .08); }
.danger-form { padding: 0 18px 18px; }

.server-list-heading { margin: 25px 1px 12px; }
.server-list-heading h3 { margin: 0; }
.server-list-heading span, .group-heading span { color: var(--muted); }
.server-editors { display: grid; gap: 10px; }
.server-editor { border: 1px solid var(--line); border-radius: 17px; overflow: hidden; background: rgba(9,16,27,.78); }
.server-editor > summary { gap: 12px; }
.server-number { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; color: #ff8d95; background: rgba(237,55,67,.1); font-variant-numeric: tabular-nums; }
.server-summary { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.server-summary small { color: var(--muted); font-size: .7rem; }
.status-pill { border-radius: 999px; padding: 5px 9px; font-size: .7rem; font-weight: 800; }
.status-pill.ok { color: #87f0c6; background: rgba(67,214,155,.1); }
.status-pill.unsupported { color: #ffd08b; background: rgba(255,188,82,.1); }

.add-channel-panel { margin-top: 18px; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: rgba(4,9,17,.44); }
.filter-row { margin-top: 20px; display: grid; grid-template-columns: minmax(220px, 1fr) minmax(180px, 280px); gap: 12px; }

.channel-groups { display: grid; gap: 25px; }
.channel-group { scroll-margin-top: 100px; }
.group-heading { margin: 0 4px 12px; }
.group-heading h2 { margin: 0; font-size: 1.16rem; }
.channel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }

.channel-card {
    min-width: 0;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 19px;
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 12px;
    background: linear-gradient(145deg, rgba(18,29,46,.9), rgba(8,15,26,.9));
    box-shadow: 0 10px 25px rgba(0,0,0,.12);
    transition: transform .16s ease, border-color .16s ease;
}

.channel-card:hover { transform: translateY(-2px); border-color: rgba(255,255,255,.2); }
.channel-image { width: 56px; height: 56px; border-radius: 16px; overflow: hidden; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, #273b55, #111c2b); font-size: 1.35rem; font-weight: 900; }
.channel-image img { width: 100%; height: 100%; display: block; object-fit: cover; }
.channel-info { min-width: 0; }
.channel-info h3 { margin: 2px 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .97rem; }
.channel-info code { display: block; overflow: hidden; color: #8fa0b6; text-overflow: ellipsis; font-size: .69rem; white-space: nowrap; }
.channel-info p { margin: 6px 0 0; color: var(--muted); font-size: .73rem; }
.channel-actions { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.channel-actions a, .channel-actions button { min-height: 36px; border: 1px solid rgba(255,255,255,.09); border-radius: 10px; display: grid; place-items: center; color: #dce5f2; background: rgba(255,255,255,.04); text-decoration: none; cursor: pointer; font-size: .75rem; }
.channel-actions a:first-child { color: #fff; background: rgba(237,55,67,.16); }
.channel-actions a:hover, .channel-actions button:hover { background: rgba(255,255,255,.09); }

.empty-state { padding: 30px 18px; border: 1px dashed rgba(255,255,255,.15); border-radius: 17px; color: var(--muted); text-align: center; }
.catalog-note { margin: 28px 0 0; color: #728198; text-align: center; font-size: .78rem; }
.admin-toast { position: fixed; z-index: 100; right: 50%; bottom: 22px; transform: translateX(50%); max-width: min(90vw, 430px); padding: 12px 18px; border: 1px solid rgba(255,255,255,.13); border-radius: 999px; color: #fff; background: rgba(12,20,32,.95); box-shadow: var(--shadow); text-align: center; }
.is-hidden { display: none !important; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgba(237,55,67,.65);
}

@media (max-width: 780px) {
    .admin-header { min-height: 68px; }
    .header-brand .eyebrow { display: none; }
    .brand-mark.small { width: 42px; height: 42px; border-radius: 13px; }
    .stats-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stats-row article { min-height: 88px; padding: 15px; }
    .editor-heading, .section-heading { align-items: flex-start; flex-direction: column; }
    .form-grid { grid-template-columns: 1fr; padding: 14px; }
    .form-grid .wide { grid-column: auto; }
    .filter-row { grid-template-columns: 1fr; }
    .channel-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

@media (max-width: 480px) {
    .login-view { padding: 12px; }
    .login-card { padding: 28px 21px; border-radius: 24px; }
    .admin-header { padding-right: 11px; padding-left: 11px; }
    .header-brand h1 { max-width: 155px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .admin-header .ghost-button { min-height: 40px; padding: 8px 11px; font-size: .76rem; }
    .admin-main { padding-right: 10px; padding-left: 10px; }
    .stats-row { gap: 8px; }
    .editor-panel, .dashboard-tools { padding: 13px; border-radius: 20px; }
    .channel-grid { grid-template-columns: 1fr; }
    .heading-actions { width: 100%; }
    .heading-actions a { flex: 1; }
    .form-actions .primary-button { width: 100%; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
