/* ==================================================================
   TaskFlow stylesheet
   Body text uses the system UI stack; every number, ticket id and
   timestamp is set in the mono face so the queue reads like a board.
   ================================================================== */

:root {
    --ink: #14171c;
    --ink-2: #48536a;
    --muted: #79839a;
    --line: #e2e6ee;
    --line-strong: #cbd2e0;
    --canvas: #f5f6f9;
    --surface: #ffffff;

    --shell: #191f2c;
    --shell-2: #29344a;
    --shell-ink: #cfd6e4;

    --accent: #16645c;
    --accent-dark: #0f4a44;
    --accent-soft: #e7f1ef;

    --danger: #b3261e;
    --danger-soft: #fdecea;
    --warn: #9a5b00;
    --warn-soft: #fdf3e2;
    --ok: #15803d;
    --ok-soft: #e9f6ee;

    --radius: 8px;
    --radius-sm: 5px;
    --shadow: 0 1px 2px rgba(20, 23, 28, .06), 0 4px 12px rgba(20, 23, 28, .05);

    --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font-ui);
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--canvas);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
a:hover { color: var(--accent-dark); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

/* ---------- Top bar ---------- */

.topbar {
    background: var(--shell);
    color: var(--shell-ink);
    border-bottom: 1px solid #0d111a;
}

.topbar-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 28px;
    min-height: 56px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 650;
    font-size: 15px;
    color: #fff;
    text-decoration: none;
    letter-spacing: -.01em;
    white-space: nowrap;
}

.brand .mark {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    background: linear-gradient(150deg, #2f8f83, var(--accent));
    display: grid;
    place-items: center;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    color: #fff;
}

.nav {
    display: flex;
    gap: 4px;
    flex: 1;
    flex-wrap: wrap;
}

.nav a {
    color: var(--shell-ink);
    text-decoration: none;
    padding: 6px 11px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
}

.nav a:hover { background: var(--shell-2); color: #fff; }
.nav a.is-active { background: var(--shell-2); color: #fff; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.topbar-user .who { text-align: right; line-height: 1.25; }
.topbar-user .who strong { display: block; color: #fff; font-size: 13.5px; font-weight: 550; }
.topbar-user .who span {
    font-family: var(--font-mono);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: #8b96ac;
}

.topbar-user a.signout {
    color: #8b96ac;
    font-size: 13px;
    text-decoration: none;
    padding: 5px 9px;
    border-radius: var(--radius-sm);
    border: 1px solid #333d52;
}
.topbar-user a.signout:hover { color: #fff; border-color: #4d5a75; }

/* ---------- Layout ---------- */

.page {
    max-width: 1240px;
    margin: 0 auto;
    padding: 26px 20px 64px;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.page-head h1 {
    margin: 0;
    font-size: 21px;
    font-weight: 620;
    letter-spacing: -.015em;
}

.page-head .sub {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 13.5px;
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 310px;
    gap: 20px;
    align-items: start;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card + .card { margin-top: 16px; }

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

.card-head h2 {
    margin: 0;
    font-size: 12px;
    font-weight: 620;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ink-2);
    font-family: var(--font-mono);
}

.card-body { padding: 18px; }

/* ---------- Stats ---------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    text-decoration: none;
    color: inherit;
    display: block;
    border-left: 3px solid var(--stat, var(--line-strong));
}

.stat:hover { border-color: var(--line-strong); border-left-color: var(--stat, var(--accent)); }
.stat:visited { color: inherit; }

.stat .n {
    font-family: var(--font-mono);
    font-size: 26px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.02em;
    display: block;
    line-height: 1.1;
}

.stat .k {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    font-weight: 550;
}

/* ---------- Ticket rows ---------- */

.ticket-list { display: flex; flex-direction: column; }

.ticket-row {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    padding: 13px 18px 13px 15px;
    border-bottom: 1px solid var(--line);
    text-decoration: none;
    color: inherit;
    border-left: 3px solid var(--sig, transparent);
}

.ticket-row:last-child { border-bottom: 0; }
.ticket-row:hover { background: #fafbfd; }
.ticket-row:visited { color: inherit; }

/* Grid children need this or long titles push the row wider than the card. */
.ticket-row > span { min-width: 0; }

.ticket-row .no {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
}

.ticket-row .title {
    font-weight: 550;
    font-size: 14.5px;
    margin: 0 0 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ticket-row .meta {
    font-size: 12.5px;
    color: var(--muted);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.ticket-row .meta b { font-weight: 550; color: var(--ink-2); }

.ticket-row .right {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-end;
}

/* ---------- Chips and tags ---------- */

.chip {
    display: inline-block;
    font-size: 11.5px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 20px;
    color: var(--chip, #667085);
    background: color-mix(in srgb, var(--chip, #667085) 11%, #fff);
    border: 1px solid color-mix(in srgb, var(--chip, #667085) 26%, #fff);
    white-space: nowrap;
}

.priority-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 550;
    color: var(--ink-2);
    white-space: nowrap;
}

.priority-tag .signal {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: var(--sig, #667085);
    flex: none;
}

.pill {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .07em;
    padding: 2px 7px;
    border-radius: 4px;
    background: #eef1f6;
    color: var(--ink-2);
    font-weight: 600;
}

.pill.overdue { background: var(--danger-soft); color: var(--danger); }
.pill.due-soon { background: var(--warn-soft); color: var(--warn); }

/* ---------- Avatars ---------- */

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: inline-grid;
    place-items: center;
    font-size: 11px;
    font-weight: 650;
    color: #fff;
    background: hsl(var(--hue, 200) 34% 42%);
    flex: none;
    letter-spacing: .02em;
}

.avatar.lg { width: 34px; height: 34px; font-size: 12.5px; }
.avatar.sm { width: 22px; height: 22px; font-size: 9.5px; }

/* ---------- Forms ---------- */

.field { margin-bottom: 16px; }

.field label,
.label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-2);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: .05em;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="search"],
input[type="number"],
input[type="color"],
select,
textarea {
    width: 100%;
    font-family: inherit;
    font-size: 14px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    transition: border-color .12s, box-shadow .12s;
}

input[type="color"] { padding: 3px; height: 36px; cursor: pointer; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { resize: vertical; min-height: 80px; }

.hint {
    font-size: 12.5px;
    color: var(--muted);
    margin-top: 5px;
}

.field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 560;
    padding: 8px 15px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .12s, border-color .12s;
}

.btn:hover { background: #f6f7fa; border-color: #b6bfd1; color: var(--ink); }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }

.btn-danger { color: var(--danger); border-color: #eccfcc; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); border-color: #e0b3ae; color: var(--danger); }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Search bar ---------- */

.searchbar {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.searchbar .row-1 {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.searchbar .row-1 input { flex: 1; }

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    align-items: end;
}

.filters .label { margin-bottom: 4px; font-size: 11px; }

/* ---------- Ticket thread ---------- */

.thread { display: flex; flex-direction: column; }

.entry {
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
}

.entry:last-child { border-bottom: 0; }

.entry-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.entry-head .name { font-weight: 600; font-size: 13.5px; }

.entry-head .when {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--muted);
    margin-left: auto;
}

.entry.is-system {
    background: #fafbfd;
    padding: 9px 18px;
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 12.5px;
    color: var(--ink-2);
}

.entry.is-system .when { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-left: auto; }

.entry.is-opening { background: #fcfdfe; }

/* Rendered editor output */
.rich {
    font-size: 14.5px;
    line-height: 1.6;
    overflow-wrap: break-word;
}

.rich > :first-child { margin-top: 0; }
.rich > :last-child { margin-bottom: 0; }
.rich p { margin: 0 0 .75em; }
.rich img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    display: block;
    margin: 12px 0;
    cursor: zoom-in;
}
.rich ul, .rich ol { padding-left: 22px; margin: 0 0 .75em; }
.rich li { margin-bottom: .25em; }
.rich blockquote {
    margin: 0 0 .75em;
    padding: 2px 0 2px 14px;
    border-left: 3px solid var(--line-strong);
    color: var(--ink-2);
}
.rich pre {
    background: #f4f6f9;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
}
.rich code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: #f0f3f7;
    padding: 1px 5px;
    border-radius: 3px;
}
.rich pre code { background: none; padding: 0; }
.rich table { border-collapse: collapse; width: 100%; margin: 0 0 .75em; font-size: 13.5px; }
.rich th, .rich td { border: 1px solid var(--line-strong); padding: 6px 9px; text-align: left; }
.rich th { background: #f4f6f9; font-weight: 600; }
.rich h1, .rich h2, .rich h3, .rich h4 { margin: 1.2em 0 .5em; line-height: 1.3; }
.rich h1 { font-size: 19px; }
.rich h2 { font-size: 17px; }
.rich h3 { font-size: 15.5px; }

/* ---------- Side panel ---------- */

.prop {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    font-size: 13.5px;
}

.prop:last-child { border-bottom: 0; }

.prop .k {
    color: var(--muted);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
    flex: none;
}

.prop .v { text-align: right; display: flex; align-items: center; gap: 7px; justify-content: flex-end; }
.prop .v.mono { font-family: var(--font-mono); font-size: 12.5px; }

/* ---------- Ticket header block ---------- */

.ticket-title-block {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

.ticket-no-big {
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 650;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    letter-spacing: -.02em;
}

/* ---------- Alerts ---------- */

.alert {
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13.5px;
    border: 1px solid;
}

.alert-success { background: var(--ok-soft); border-color: #bfe3cc; color: #14602f; }
.alert-error   { background: var(--danger-soft); border-color: #f0c4c0; color: var(--danger); }
.alert-info    { background: #eef4fb; border-color: #c9dcf0; color: #1c4e80; }
.alert-warning { background: var(--warn-soft); border-color: #eed7ae; color: var(--warn); }

/* ---------- Tables (admin) ---------- */

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

.table th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    font-weight: 650;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: #fafbfd;
    white-space: nowrap;
}

.table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.table tr:last-child td { border-bottom: 0; }
.table td.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.table .actions { text-align: right; white-space: nowrap; }

/* The inline delete forms would otherwise sit a couple of pixels low. */
.table .actions form { display: inline-flex; vertical-align: middle; }
.table .actions .btn { vertical-align: middle; }

.swatch {
    display: inline-block;
    width: 13px;
    height: 13px;
    border-radius: 3px;
    vertical-align: -2px;
    margin-right: 7px;
    border: 1px solid rgba(0, 0, 0, .12);
}

/* ---------- Empty state ---------- */

.empty {
    padding: 52px 24px;
    text-align: center;
    color: var(--muted);
}

.empty h3 { margin: 0 0 6px; font-size: 15px; color: var(--ink-2); font-weight: 600; }
.empty p { margin: 0 0 16px; font-size: 13.5px; }

/* ---------- Pagination ---------- */

.pager {
    display: flex;
    gap: 6px;
    justify-content: center;
    padding: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.pager a, .pager span {
    font-family: var(--font-mono);
    font-size: 12.5px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    text-decoration: none;
    color: var(--ink-2);
    background: var(--surface);
}

.pager a:hover { border-color: var(--line-strong); }
.pager .is-current { background: var(--accent); border-color: var(--accent); color: #fff; }
.pager .gap { border: 0; background: none; color: var(--muted); }

/* ---------- Login ---------- */

.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(1100px 460px at 50% -12%, #e5edf3 0%, transparent 62%),
        var(--canvas);
}

.auth-card {
    width: 100%;
    max-width: 392px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 11px;
    box-shadow: 0 1px 3px rgba(20, 23, 28, .07), 0 12px 34px rgba(20, 23, 28, .08);
    padding: 30px 30px 26px;
}

.auth-card .brand { color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.auth-card h1 { font-size: 17px; margin: 16px 0 4px; font-weight: 620; }
.auth-card .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }

.demo-keys {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--muted);
    line-height: 1.85;
}

.demo-keys b { color: var(--ink-2); font-weight: 600; }

/* ---------- Attachments ---------- */

.attach-grid {
    display: flex;
    gap: 9px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.attach-grid a {
    display: block;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: hidden;
    line-height: 0;
}

.attach-grid img { width: 74px; height: 74px; object-fit: cover; }

/* ---------- Lightbox ---------- */

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(16, 20, 27, .88);
    display: grid;
    place-items: center;
    padding: 32px;
    z-index: 900;
}

.lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

.lightbox .close {
    position: absolute;
    top: 18px;
    right: 22px;
    color: #fff;
    background: none;
    border: 0;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    padding: 6px 12px;
}

/* ---------- Utilities ---------- */

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; align-items: center; gap: 9px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Utilities have to outrank element selectors such as `.field label`. */
.hide { display: none !important; }

/* Present for screen readers, invisible on screen. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    .split { grid-template-columns: 1fr; }
    .split .side { order: -1; }
}

@media (max-width: 640px) {
    .topbar-inner {
        flex-wrap: wrap;
        padding: 10px 14px 0;
        gap: 10px;
        min-height: 0;
    }

    /* The brand and account sit on the first line, the nav gets its own
       row underneath and scrolls sideways rather than stacking. */
    .brand { margin-right: auto; }

    .nav {
        order: 3;
        flex: 0 0 100%;
        width: 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        padding-bottom: 8px;
    }

    .nav::-webkit-scrollbar { display: none; }

    .topbar-user .who { display: none; }

    .page { padding: 18px 14px 48px; }

    .page-head h1 { font-size: 19px; }

    .searchbar .row-1 { flex-wrap: wrap; }
    .searchbar .row-1 input { flex: 1 0 100%; }

    .ticket-row { grid-template-columns: 1fr; gap: 7px; padding: 13px 14px; }
    .ticket-row .right { justify-content: flex-start; }

    /* Long titles wrap on a narrow screen instead of being clipped. */
    .ticket-row .title { white-space: normal; overflow: visible; }

    .prop { flex-direction: column; align-items: flex-start; gap: 4px; }
    .prop .v { justify-content: flex-start; text-align: left; }

    .table { display: block; overflow-x: auto; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* ---------- Print ---------- */

@media print {
    .topbar, .side, .btn, .pager, .searchbar { display: none !important; }
    .card { box-shadow: none; border-color: #ccc; }
}
