:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --line: #d9e0ea;
    --dark: #151922;
    --dark-2: #202636;
    --red: #cf2f2f;
    --green: #0f8a5f;
    --blue: #2563eb;
    --amber: #b7791f;
    --violet: #6d4aff;
    --shadow: 0 18px 45px rgba(18, 24, 38, .08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

body.dark {
    --bg: #0f131a;
    --panel: #171d27;
    --text: #e8eef7;
    --muted: #9aa7bb;
    --line: #2b3545;
    --dark: #0b0f15;
    --dark-2: #1e2838;
    --shadow: 0 18px 45px rgba(0, 0, 0, .24);
}

a {
    color: inherit;
}

img {
    max-width: 100%;
}

.login-screen {
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(21, 25, 34, .92), rgba(36, 31, 43, .82)),
        url("/assets/login-bg.jpg") center/cover fixed;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-shell {
    width: min(980px, 100%);
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    gap: 24px;
    align-items: stretch;
}

.login-brand,
.login-card {
    background: rgba(255, 255, 255, .92);
    border: 1px solid rgba(255, 255, 255, .5);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.login-brand {
    color: var(--text);
    padding: 44px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-height: 460px;
}

.login-brand img {
    width: 190px;
    height: auto;
    margin-bottom: auto;
}

.login-brand h1,
.login-card h2 {
    margin: 0;
    font-size: clamp(34px, 5vw, 58px);
    letter-spacing: 0;
}

.login-brand p,
.login-card p {
    margin: 8px 0 0;
    color: var(--muted);
}

.login-card {
    padding: 34px;
    display: grid;
    gap: 18px;
    align-content: center;
}

.login-card label {
    display: grid;
    gap: 8px;
    font-weight: 700;
}

.login-card input,
.filters input,
.filters select,
.form-panel input,
.form-panel select,
.form-panel textarea,
.inline-form input,
.inline-form select,
.inline-form textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    padding: 0 12px;
    font: inherit;
}

.form-panel textarea,
.inline-form textarea {
    min-height: 92px;
    padding: 10px 12px;
    resize: vertical;
}

select[multiple] {
    min-height: 148px;
    padding: 8px;
}

.native-select {
    display: none !important;
}

.custom-select {
    position: relative;
    width: 100%;
    min-width: 0;
}

.custom-select-button {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    padding: 0 36px 0 12px;
    font: inherit;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    position: relative;
}

.custom-select-button span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-select-button::after {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    position: absolute;
    right: 14px;
    top: 16px;
    transform: rotate(45deg);
    transition: transform .15s ease;
}

.custom-select.open .custom-select-button::after {
    transform: rotate(225deg);
    top: 19px;
}

.custom-select-menu {
    display: none;
    position: absolute;
    z-index: 80;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 8px;
}

.custom-select.open .custom-select-menu {
    display: grid;
    gap: 8px;
}

.custom-select-search {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    padding: 0 10px;
    font: inherit;
}

.custom-select-list {
    max-height: 260px;
    overflow: auto;
    display: grid;
    gap: 3px;
}

.custom-select-option {
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    min-height: 36px;
    padding: 8px 10px;
    text-align: left;
}

.custom-select-option:hover,
.custom-select-option[aria-selected="true"] {
    background: rgba(207, 47, 47, .1);
    color: var(--red);
}

.custom-select-option[aria-selected="true"] {
    font-weight: 850;
}

.custom-select-option:disabled {
    cursor: not-allowed;
    color: var(--muted);
    opacity: .55;
}

.custom-select-empty {
    color: var(--muted);
    padding: 10px;
    font-size: 13px;
    font-weight: 800;
}

.primary-button,
.ghost-button,
.icon-button {
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.primary-button {
    background: var(--red);
    color: #fff;
    padding: 0 18px;
}

.primary-button.compact {
    min-height: 40px;
}

.ghost-button,
.icon-button {
    background: #eef2f7;
    color: var(--text);
    padding: 0 14px;
}

.notice {
    border-radius: 6px;
    padding: 12px 14px;
    font-weight: 700;
}

.notice.error {
    color: #8f1d1d;
    background: #ffe7e7;
}

.notice.success {
    color: #075b3f;
    background: #dff8ec;
    margin-bottom: 16px;
}

body.dark .notice.success {
    color: #97f0c4;
    background: #143728;
}

body.dark .notice.error {
    color: #ffb4b4;
    background: #3b1717;
}

.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--dark);
    color: #fff;
    padding: 22px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    font-size: 19px;
    font-weight: 900;
    margin-bottom: 24px;
}

.brand img {
    width: 46px;
    height: 46px;
    object-fit: contain;
    background: #fff;
    border-radius: 6px;
    padding: 4px;
}

.sidebar nav {
    display: grid;
    gap: 8px;
}

.nav-section {
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 8px;
    background: rgba(255, 255, 255, .025);
    overflow: hidden;
}

.nav-section summary {
    min-height: 38px;
    padding: 0 11px;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #9aa7bb;
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0;
}

.nav-section summary::-webkit-details-marker {
    display: none;
}

.nav-section summary::after {
    content: "";
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform .15s ease;
}

.nav-section[open] summary::after {
    transform: rotate(225deg);
}

.nav-section div {
    display: grid;
    gap: 3px;
    padding: 0 5px 6px;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    border-radius: 6px;
    color: #d8dee9;
    text-decoration: none;
    padding: 0 10px;
    font-weight: 750;
    font-size: 14px;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    color: #fff;
    background: var(--dark-2);
}

.nav-dot {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: #7c8799;
}

.sidebar nav a.active .nav-dot {
    background: var(--red);
}

.workspace {
    min-width: 0;
    padding: 20px clamp(16px, 3vw, 34px) 42px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 62px;
    margin-bottom: 18px;
}

.topbar div {
    margin-left: auto;
    text-align: right;
}

.topbar strong,
.topbar span {
    display: block;
}

.topbar span {
    color: var(--muted);
    font-size: 13px;
}

.icon-button {
    display: none;
}

.server-strip {
    display: grid;
    grid-template-columns: repeat(5, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.server-strip article {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 15px;
    display: grid;
    gap: 4px;
}

.server-strip span,
.server-strip small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.server-strip strong {
    font-size: 26px;
    letter-spacing: 0;
}

.meter {
    display: block;
    height: 7px;
    width: 100%;
    border-radius: 999px;
    background: #e5ebf3;
    overflow: hidden;
}

.meter i {
    display: block;
    height: 100%;
    max-width: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--green), var(--amber), var(--red));
}

body.dark .meter {
    background: #263244;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.form-grid.wide {
    grid-template-columns: 1fr;
}

.form-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.form-panel summary {
    cursor: pointer;
    padding: 14px 16px;
    font-weight: 900;
    border-bottom: 1px solid var(--line);
}

.form-panel form {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(3, minmax(120px, 1fr));
    gap: 12px;
    align-items: end;
}

.form-panel label,
.inline-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.form-panel .wide {
    grid-column: span 2;
}

.content-form {
    grid-template-columns: repeat(4, minmax(140px, 1fr)) !important;
}

.content-form .wide {
    grid-column: span 2;
}

.checkline {
    display: flex !important;
    align-items: center;
    gap: 10px !important;
    color: var(--text) !important;
    min-height: 40px;
    cursor: pointer;
}

.checkline input[type="checkbox"] {
    appearance: none;
    width: 46px !important;
    min-width: 46px;
    height: 25px;
    min-height: 25px !important;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #dbe3ee;
    cursor: pointer;
    padding: 0 !important;
    position: relative;
    transition: background .18s ease, border-color .18s ease;
}

.checkline input[type="checkbox"]::before {
    content: "";
    position: absolute;
    width: 19px;
    height: 19px;
    top: 2px;
    left: 2px;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 2px 5px rgba(18, 24, 38, .22);
    transition: transform .18s ease;
}

.checkline input[type="checkbox"]:checked {
    background: var(--red);
    border-color: var(--red);
}

.checkline input[type="checkbox"]:checked::before {
    transform: translateX(21px);
}

.checkline input[type="checkbox"]:focus-visible,
.custom-select-button:focus-visible,
.custom-select-search:focus-visible,
.custom-select-option:focus-visible {
    outline: 3px solid rgba(207, 47, 47, .24);
    outline-offset: 2px;
}

.row-actions {
    min-width: 300px;
}

.row-actions summary {
    cursor: pointer;
    color: var(--red);
    font-weight: 900;
}

.inline-form,
.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.inline-form input {
    width: 110px;
    min-height: 34px;
}

.row-actions.editor {
    min-width: 520px;
}

.content-editor {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(140px, 1fr));
    gap: 10px;
    align-items: end;
}

.content-editor input,
.content-editor select {
    width: 100%;
    min-height: 36px;
}

.content-editor .wide {
    grid-column: span 3;
}

.button-row {
    margin-top: 8px;
}

.ghost-button.mini {
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
}

.ghost-button.danger {
    color: #b91c1c;
}

body.dark .ghost-button,
body.dark .icon-button {
    background: #263244;
    color: var(--text);
}

.page-title {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: end;
    margin-bottom: 18px;
}

.page-title p {
    margin: 0 0 4px;
    color: var(--red);
    font-weight: 900;
    text-transform: uppercase;
    font-size: 12px;
}

.page-title h1 {
    margin: 0;
    font-size: clamp(28px, 4vw, 44px);
    letter-spacing: 0;
}

.page-title span {
    color: var(--muted);
    font-weight: 750;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stat-card {
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
    padding: 18px;
    min-height: 122px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-top: 4px solid #9aa4b2;
}

.stat-card span {
    color: var(--muted);
    font-weight: 800;
    font-size: 13px;
}

.stat-card strong {
    font-size: 30px;
    letter-spacing: 0;
}

.stat-card.green {
    border-top-color: var(--green);
}

.stat-card.blue {
    border-top-color: var(--blue);
}

.stat-card.red {
    border-top-color: var(--red);
}

.stat-card.amber {
    border-top-color: var(--amber);
}

.stat-card.violet {
    border-top-color: var(--violet);
}

.two-column {
    display: grid;
    grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
    gap: 18px;
    margin-bottom: 18px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.stack-panel {
    margin-top: 18px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
}

.panel-head h2 {
    margin: 0;
    font-size: 18px;
}

.panel-head a {
    color: var(--red);
    font-weight: 800;
    text-decoration: none;
}

.metric-list,
.activity-list {
    display: grid;
}

.metric-list div,
.activity-list div {
    display: grid;
    gap: 2px;
    padding: 13px 18px;
    border-bottom: 1px solid #eef2f7;
}

.metric-list div {
    grid-template-columns: 1fr auto;
    align-items: center;
}

.metric-list span,
.activity-list span,
.activity-list small,
small {
    color: var(--muted);
}

.ticket-list {
    display: grid;
    max-height: 640px;
    overflow: auto;
}

.ticket-list a,
.empty-state {
    display: grid;
    gap: 4px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    text-decoration: none;
}

.ticket-list a.active {
    background: rgba(207, 47, 47, .08);
}

.ticket-list span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.message-list {
    display: grid;
    gap: 10px;
    padding: 16px;
    max-height: 520px;
    overflow: auto;
}

.message {
    width: min(680px, 86%);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #f8fafc;
}

.message.support {
    margin-left: auto;
    background: #eaf2ff;
}

body.dark .message {
    background: #121821;
}

body.dark .message.support {
    background: #17243a;
}

.message p {
    margin: 6px 0;
    white-space: pre-wrap;
}

.reply-box {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 16px;
    border-top: 1px solid var(--line);
}

.reply-box textarea {
    min-height: 84px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    padding: 10px 12px;
    font: inherit;
    resize: vertical;
}

.poster-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(120px, 1fr));
    gap: 14px;
    padding: 16px;
}

.poster-item {
    display: grid;
    gap: 8px;
    text-decoration: none;
    min-width: 0;
}

.poster-item img,
.poster-empty {
    aspect-ratio: 2 / 3;
    width: 100%;
    object-fit: cover;
    border-radius: 6px;
    background: #d8dee9;
}

.poster-item strong,
.poster-item small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filters {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(160px, 240px) minmax(120px, 160px) auto;
    gap: 10px;
    margin-bottom: 14px;
}

.filters select:nth-last-child(2):first-of-type {
    grid-column: auto;
}

.table-wrap {
    overflow: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
}

th,
td {
    text-align: left;
    padding: 13px 16px;
    border-bottom: 1px solid #eef2f7;
    vertical-align: middle;
}

th {
    background: #f8fafc;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
}

body.dark th {
    background: #121821;
}

body.dark th,
body.dark td,
body.dark .metric-list div,
body.dark .activity-list div {
    border-bottom-color: var(--line);
}

.title-cell {
    display: flex;
    gap: 10px;
    align-items: center;
    min-width: 260px;
}

.title-cell img {
    width: 42px;
    height: 56px;
    object-fit: cover;
    border-radius: 5px;
    background: #d8dee9;
    flex: 0 0 auto;
}

.title-cell span {
    min-width: 0;
}

.title-cell strong,
.title-cell small {
    display: block;
    max-width: 480px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.title-cell a {
    color: var(--red);
    font-weight: 800;
    text-decoration: none;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 900;
}

.badge.ok {
    background: #dff8ec;
    color: #087046;
}

.badge.muted {
    background: #eef2f7;
    color: #596274;
}

@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .server-strip {
        grid-template-columns: repeat(3, 1fr);
    }

    .poster-grid {
        grid-template-columns: repeat(4, minmax(120px, 1fr));
    }
}

@media (max-width: 900px) {
    .login-shell,
    .two-column,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .login-brand {
        min-height: 280px;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(280px, 86vw);
        transform: translateX(-105%);
        transition: transform .2s ease;
        z-index: 30;
    }

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

    .icon-button {
        display: inline-flex;
    }

    .topbar div {
        text-align: left;
        margin-left: 0;
    }

    .content-form,
    .content-editor {
        grid-template-columns: 1fr 1fr !important;
    }

    .content-editor .wide,
    .content-form .wide {
        grid-column: span 2;
    }
}

@media (max-width: 720px) {
    .workspace {
        padding: 14px;
    }

    .stats-grid,
    .server-strip,
    .poster-grid,
    .filters {
        grid-template-columns: 1fr;
    }

    .form-panel form {
        grid-template-columns: 1fr;
    }

    .form-panel .wide {
        grid-column: auto;
    }

    .content-form,
    .content-editor {
        grid-template-columns: 1fr !important;
    }

    .content-editor .wide,
    .content-form .wide {
        grid-column: auto;
    }

    .page-title {
        display: grid;
        align-items: start;
    }
}
