:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #657282;
    --line: #d8dee6;
    --primary: #176b87;
    --primary-dark: #0f4d61;
    --bad: #a52834;
    --ok: #237447;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.45;
}
body.theme-dark {
    color-scheme: dark;
    --bg: #12161b;
    --panel: #1b222b;
    --text: #eef3f7;
    --muted: #a6b1bd;
    --line: #34404d;
    --primary: #49a6c4;
    --primary-dark: #2f86a2;
}
@media (prefers-color-scheme: dark) {
    body.theme-system {
        color-scheme: dark;
        --bg: #12161b;
        --panel: #1b222b;
        --text: #eef3f7;
        --muted: #a6b1bd;
        --line: #34404d;
        --primary: #49a6c4;
        --primary-dark: #2f86a2;
    }
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    min-height: 64px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 0 28px;
}
.brand {
    color: var(--text);
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0;
}
.topbar nav {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

.wrap {
    width: min(1180px, calc(100% - 32px));
    margin: 28px auto 56px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 22px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.auth { max-width: 420px; margin: 80px auto; }
h1, h2 { margin: 0 0 16px; line-height: 1.15; }
h1 { font-size: clamp(28px, 4vw, 42px); }
h2 { font-size: 20px; margin-top: 24px; }
.muted { color: var(--muted); }
.pre { white-space: pre-wrap; }

.stack { display: grid; gap: 14px; }
label { display: grid; gap: 7px; font-weight: 650; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 11px 12px;
    color: var(--text);
    background: var(--panel);
    font: inherit;
}
textarea { resize: vertical; }
button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    padding: 9px 14px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}
.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.primary:hover { background: var(--primary-dark); text-decoration: none; }
.inline { display: inline; margin: 0; }

.flash {
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 16px;
    background: #edf8f1;
    color: var(--ok);
    border: 1px solid #bce3ca;
}
.flash.bad {
    background: #fff0f1;
    color: var(--bad);
    border-color: #efc4c9;
}

.dash-head, .ticket-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}
.ticket-head { align-items: flex-start; }
.grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 18px;
    align-items: start;
}
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badges span {
    display: inline-flex;
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 999px;
    padding: 7px 12px;
    font-weight: 750;
}

table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    border-bottom: 1px solid var(--line);
    text-align: left;
    padding: 12px 10px;
    vertical-align: top;
}
th {
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.comment {
    border-top: 1px solid var(--line);
    padding: 14px 0;
}
.comment span, .comment em {
    margin-left: 8px;
    color: var(--muted);
    font-size: 14px;
}
.comment em {
    color: var(--bad);
    font-style: normal;
    font-weight: 800;
}
.check {
    display: flex;
    align-items: center;
    gap: 9px;
}
.check input { width: auto; }

.user-form {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 150px auto;
    gap: 10px;
    margin-bottom: 20px;
}
.filterbar {
    display: grid;
    grid-template-columns: repeat(6, minmax(120px, 1fr));
    gap: 10px;
    align-items: end;
    margin-bottom: 16px;
}
.filterbar.compact {
    grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
}
.field-list {
    display: grid;
    grid-template-columns: minmax(140px, 220px) 1fr;
    gap: 8px 14px;
    margin: 10px 0 20px;
}
.field-list dt {
    color: var(--muted);
    font-weight: 800;
}
.field-list dd { margin: 0; }
.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}
.attachments img {
    width: 140px;
    height: 100px;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: zoom-in;
    display: block;
}
.paste-zone {
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 14px;
    color: var(--muted);
    background: color-mix(in srgb, var(--panel) 86%, var(--primary) 14%);
    outline: none;
}
.paste-zone:focus {
    border-color: var(--primary);
    color: var(--text);
}
.paste-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.paste-thumb {
    width: 140px;
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
    background: var(--panel);
}
.paste-thumb img {
    width: 100%;
    height: 90px;
    object-fit: cover;
    display: block;
}
.paste-thumb span {
    display: block;
    padding: 7px;
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: rgba(0, 0, 0, .82);
}
.lightbox:target { display: flex; }
.lightbox img {
    width: auto;
    height: auto;
    max-width: min(1100px, 92vw);
    max-height: 82vh;
    object-fit: contain;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 8px;
    cursor: default;
}
.lightbox p {
    position: fixed;
    left: 32px;
    bottom: 22px;
    right: 32px;
    color: #fff;
    text-align: center;
}
.lightbox-close {
    position: fixed;
    top: 18px;
    right: 24px;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255,255,255,.14);
    color: #fff;
    font-size: 34px;
    line-height: 1;
}
.lightbox-close:hover {
    background: rgba(255,255,255,.24);
    text-decoration: none;
}
.swatch {
    display: inline-block;
    width: 28px;
    height: 18px;
    border-radius: 4px;
    border: 1px solid var(--line);
}

@media (max-width: 820px) {
    .topbar { align-items: flex-start; flex-direction: column; padding: 16px; }
    .dash-head, .ticket-head { align-items: stretch; flex-direction: column; }
    .grid { grid-template-columns: 1fr; }
    .user-form { grid-template-columns: 1fr; }
    .filterbar, .filterbar.compact { grid-template-columns: 1fr; }
    .field-list { grid-template-columns: 1fr; }
    table { display: block; overflow-x: auto; white-space: nowrap; }
}
