:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-soft: #eef0ff;
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f7f8fc;
    --border: #e6e8f0;
    --text: #191c2c;
    --muted: #6b7290;
    --danger: #dc2626;
    --danger-soft: #fdecec;
    --success: #059669;
    --success-soft: #e6f7f1;
    --warning: #b45309;
    --warning-soft: #fef3e2;
    --info: #2563eb;
    --info-soft: #eaf1ff;
    --slate: #56607a;
    --slate-soft: #eef0f5;
    --radius-lg: 16px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 6px 16px rgba(16, 24, 40, 0.07);
    --shadow-lg: 0 20px 40px rgba(16, 24, 40, 0.14);
    --ring: 0 0 0 3px rgba(79, 70, 229, 0.16);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.01em;
}

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

/* Every inline SVG in this app is a hand-drawn outline icon (no photos/illustrations),
   so style svg elements globally rather than requiring class="icon" everywhere. */
svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
svg.icon { width: 1em; height: 1em; vertical-align: -0.15em; }

h1, h2, h3 { font-weight: 750; letter-spacing: -0.02em; margin: 0; }
h1 { font-size: 1.7rem; display: flex; align-items: center; gap: 0.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; display: flex; align-items: center; gap: 0.5rem; }

.muted { color: var(--muted); }

.container { max-width: 1140px; margin: 0 auto; padding: 1.75rem 1.5rem 3rem; }
.container-narrow { max-width: 640px; }

/* ---------- Top nav ---------- */

.topnav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(10px) saturate(1.2);
    -webkit-backdrop-filter: blur(10px) saturate(1.2);
    border-bottom: 1px solid var(--border);
    padding: 0.7rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 20;
    flex-wrap: wrap;
}

.topnav-brand a {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--text);
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
}

.topnav-brand .brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(145deg, var(--primary), #8b7cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: var(--shadow-sm);
}
.topnav-brand .brand-mark svg { width: 18px; height: 18px; stroke-width: 2.1; }

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    flex: 0 0 auto;
}

.icon-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    transition: background 0.15s ease, color 0.15s ease;
}
.icon-link:hover { background: var(--surface-2); color: var(--danger); }

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

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0.25rem 0 1.25rem;
    flex-wrap: wrap;
}
.section-heading { display: flex; align-items: center; gap: 0.55rem; margin-top: 2rem; }

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.9rem;
    margin-top: 0.25rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 0.85rem;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.open { background: var(--info-soft); color: var(--info); }
.stat-icon.in_progress { background: var(--warning-soft); color: var(--warning); }
.stat-icon.resolved { background: var(--success-soft); color: var(--success); }
.stat-icon.closed { background: var(--slate-soft); color: var(--slate); }

.stat-count { font-size: 1.5rem; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.stat-label { font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; font-weight: 500; }

/* ---------- Filters ---------- */

.filter-bar { display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 1.25rem 0 1rem; }

.filter-bar select {
    padding: 0.5rem 2rem 0.5rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7290' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") no-repeat right 0.55rem center;
    background-size: 15px;
    appearance: none;
    -webkit-appearance: none;
    color: var(--text);
    font-size: 0.86rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s ease;
}
.filter-bar select:hover { border-color: var(--primary); }
.filter-bar select:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, button:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--ring);
}

/* ---------- Table / ticket list ---------- */

.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    /* Scroll a wide table inside its own card rather than letting it push the page
       sideways — the alternative is columns silently falling off the right edge. */
    overflow-x: auto;
}

.ticket-table { width: 100%; border-collapse: collapse; }

.ticket-table th, .ticket-table td {
    padding: 0.8rem 1.1rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 0.88rem;
}
.ticket-table tbody tr:last-child td { border-bottom: none; }

.ticket-table th {
    background: var(--surface-2);
    font-weight: 650;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.ticket-id { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }

.clickable-row { cursor: pointer; transition: background 0.12s ease; }
.clickable-row:hover { background: var(--surface-2); }

.desc-cell { max-width: 320px; color: var(--text); }

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 3.5rem 1rem;
    color: var(--muted);
}
.empty-state svg { width: 44px; height: 44px; color: var(--border); stroke-width: 1.3; }
.empty-state strong { color: var(--text); font-size: 0.95rem; }

/* ---------- Badges ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}
.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.badge-priority-low { background: var(--slate-soft); color: var(--slate); }
.badge-priority-medium { background: var(--warning-soft); color: var(--warning); }
.badge-priority-high { background: #ffe4d1; color: #b3541a; }
.badge-priority-urgent { background: var(--danger-soft); color: var(--danger); }

.badge-status-open { background: var(--info-soft); color: var(--info); }
.badge-status-in_progress { background: var(--warning-soft); color: var(--warning); }
.badge-status-resolved { background: var(--success-soft); color: var(--success); }
.badge-status-closed { background: var(--slate-soft); color: var(--slate); }

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.6rem 1.1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 650;
    font-family: inherit;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--border) 40%, var(--muted)); }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: linear-gradient(155deg, var(--primary), var(--primary-dark));
    color: #fff;
    border-color: transparent;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: var(--shadow-md); filter: brightness(1.05); }

.btn-warn { border-color: color-mix(in srgb, var(--warning) 45%, var(--border)); color: var(--warning); }
.btn-danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); color: var(--danger); }
.btn-small { padding: 0.4rem 0.75rem; font-size: 0.8rem; }

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

.card-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.4rem;
    margin: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 1.05rem;
    max-width: 560px;
    box-shadow: var(--shadow-sm);
}

.card-form label {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 650;
}

.card-form input, .card-form select, .card-form textarea {
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.94rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.card-form input:focus, .card-form select:focus, .card-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--ring);
}
.card-form textarea { resize: vertical; min-height: 5.5rem; }

.inline-form { display: inline-flex; gap: 0.5rem; align-items: center; margin: 0; }
.inline-form select {
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    background: var(--surface);
    color: var(--text);
}

.actions-row { display: flex; gap: 0.7rem; flex-wrap: wrap; align-items: center; }

/* Two stacked inline forms (reset password / activate) in one table cell. */
.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; justify-content: flex-end; }

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

.field-hint { display: block; margin-top: 0.3rem; font-size: 0.76rem; font-weight: 500; color: var(--muted); }
.card-form input[type="file"] {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.85rem;
}
.card-form input[type="file"]:hover { border-color: var(--primary); }

.attachment-grid { display: flex; flex-wrap: wrap; align-items: stretch; gap: 0.7rem; margin-top: 0.9rem; }
.attachment {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    width: 160px;
    padding: 0.55rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.attachment:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); text-decoration: none; }
.attachment img {
    width: 100%;
    height: 108px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    margin-bottom: 0.25rem;
}
.attachment { min-height: 191px; }
.attachment-file svg { width: 34px; height: 34px; margin: auto; color: var(--muted); stroke-width: 1.4; }
.attachment-name { font-size: 0.78rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-meta { font-size: 0.71rem; color: var(--muted); }

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

.alert {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.8rem 1.05rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.88rem;
    font-weight: 550;
    border: 1px solid transparent;
}
.alert svg { width: 18px; height: 18px; flex-shrink: 0; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 20%, transparent); }
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 20%, transparent); }

/* ---------- Ticket detail ---------- */

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 0.9rem;
}
.back-link:hover { color: var(--primary); }
.back-link svg { width: 16px; height: 16px; }

.ticket-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.25rem;
}
.ticket-header h1 { max-width: 65%; }
.ticket-header .badges { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.ticket-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0.9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.3rem;
    margin: 1.1rem 0;
    box-shadow: var(--shadow-sm);
}
.ticket-meta .meta-item { display: flex; flex-direction: column; gap: 0.2rem; }
.ticket-meta .meta-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; }
.ticket-meta .meta-value { font-size: 0.92rem; font-weight: 600; }

.ticket-description {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.3rem;
    margin-bottom: 1.1rem;
    box-shadow: var(--shadow-sm);
}
.ticket-description h3 { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.ticket-description p { margin: 0; line-height: 1.6; }

.ticket-actions.card-form { max-width: none; }
.ticket-actions h3 { display: flex; align-items: center; gap: 0.5rem; }

.ticket-comments { margin-top: 1.5rem; }
.ticket-comments > h3 { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.9rem; }

.timeline { display: flex; flex-direction: column; gap: 0; margin-bottom: 1rem; }

.comment {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1.05rem;
    margin-bottom: 0.6rem;
    box-shadow: var(--shadow-sm);
}

.comment-system {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0.35rem 0.2rem 0.35rem 1.6rem;
    margin-bottom: 0.2rem;
    font-size: 0.82rem;
    position: relative;
}
.comment-system::before {
    content: "";
    position: absolute;
    left: 0.15rem;
    top: 0.6rem;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--border);
    border: 2px solid var(--muted);
}

.comment-meta { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.35rem; font-weight: 600; }
.comment-body { white-space: pre-wrap; line-height: 1.55; }

/* ---------- Auth pages ---------- */

.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr 1fr;
}

.auth-hero {
    background: linear-gradient(160deg, var(--primary) 0%, #6a5ff0 55%, #8b7cf6 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3rem 3.5rem;
    position: relative;
    overflow: hidden;
}
.auth-hero::before, .auth-hero::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
}
.auth-hero::before { width: 340px; height: 340px; top: -120px; right: -100px; }
.auth-hero::after { width: 220px; height: 220px; bottom: -80px; left: -60px; }

.auth-hero .brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.6rem;
}
.auth-hero .brand-mark svg { width: 28px; height: 28px; stroke-width: 1.8; }

.auth-hero h1 { font-size: 2rem; max-width: 20ch; line-height: 1.2; position: relative; z-index: 1; }
.auth-hero p { opacity: 0.85; max-width: 34ch; margin-top: 0.9rem; line-height: 1.6; position: relative; z-index: 1; }

.auth-hero .hero-points { list-style: none; margin: 2rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.85rem; position: relative; z-index: 1; }
.auth-hero .hero-points li { display: flex; align-items: center; gap: 0.65rem; font-size: 0.92rem; opacity: 0.92; }
.auth-hero .hero-points svg { width: 18px; height: 18px; flex-shrink: 0; }

.auth-form-side {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--bg);
}

.auth-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.2rem 2.4rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}

.auth-box .auth-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}
.auth-box .auth-icon svg { width: 22px; height: 22px; }

.auth-box h1 { font-size: 1.25rem; }
.auth-box h2 { font-weight: 600; color: var(--muted); font-size: 0.9rem; margin-top: 0.3rem; }

.auth-box form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.3rem;
}

.auth-box label {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.83rem;
    font-weight: 650;
}

.auth-box input {
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.auth-box input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }

.auth-box button {
    margin-top: 0.4rem;
    padding: 0.75rem;
    background: linear-gradient(155deg, var(--primary), var(--primary-dark));
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: box-shadow 0.15s ease, filter 0.15s ease;
    box-shadow: var(--shadow-sm);
}
.auth-box button:hover { box-shadow: var(--shadow-md); filter: brightness(1.05); }

@media (max-width: 860px) {
    .auth-page { grid-template-columns: 1fr; }
    .auth-hero { display: none; }
}

/* ---------- Reports page ---------- */

.filter-bar input[type="date"] {
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 0.86rem;
    font-weight: 500;
    font-family: inherit;
}
.filter-bar label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.report-period { color: var(--muted); font-size: 0.9rem; margin: -0.4rem 0 0.6rem; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.1rem; }
.report-grid .table-card { margin-bottom: 0; }
/* The machine breakdown carries the most columns — give it the whole row. */
.report-grid .span-full { grid-column: 1 / -1; }
.table-title {
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    font-weight: 650;
    font-size: 0.86rem;
}
.num { text-align: right; font-variant-numeric: tabular-nums; }
.ticket-table th.num { text-align: right; }
@media print {
    .topnav, .filter-bar, .report-actions, .no-print { display: none !important; }
    body { background: #fff; }
    .container { max-width: none; padding: 0; }
    .table-card, .stat-card { box-shadow: none; break-inside: avoid; }
    .report-grid { display: block; }
    .report-grid .table-card { margin-bottom: 1rem; }
}

/* ---------- Phones ---------- */

/* Staff raise tickets from the scanner room on their own phones, so the narrow layout is
   a first-class case, not a fallback. The ticket list becomes stacked cards rather than a
   table (each cell labelled by its column header via data-label), controls grow to a
   44px tap target, and the wide report tables scroll sideways inside their own card
   instead of pushing the page out. */

@media (max-width: 760px) {
    .container, .container-narrow { padding-left: 0.85rem; padding-right: 0.85rem; }

    .topnav {
        position: sticky;
        top: 0;
        z-index: 20;
        flex-wrap: wrap;
        gap: 0.5rem 0.75rem;
        padding: 0.6rem 0.85rem;
        padding-top: max(0.6rem, env(safe-area-inset-top));
    }
    .topnav-brand { flex: 1 1 auto; min-width: 0; }
    .topnav-brand a { font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

    h1 { font-size: 1.25rem; }
    .page-header { flex-direction: column; align-items: stretch; gap: 0.7rem; }

    .stats-row { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
    .stat-card { padding: 0.75rem; }
    .stat-count { font-size: 1.25rem; }

    .filter-bar { gap: 0.45rem; }
    .filter-bar select, .filter-bar input[type="date"], .filter-bar label { width: 100%; }
    .filter-bar label { justify-content: space-between; }

    .btn, .card-form button, .auth-box button { min-height: 44px; }
    .actions-row { flex-direction: column; align-items: stretch; }
    .actions-row .inline-form, .actions-row .btn { width: 100%; }
    /* A select plus its button must share one row without pushing past the card edge;
       min-width:0 lets the select actually shrink instead of forcing an overflow. */
    .inline-form { display: flex; width: 100%; flex-wrap: wrap; gap: 0.4rem; }
    .inline-form select { flex: 1 1 8rem; min-width: 0; }
    .inline-form .btn { flex: 0 1 auto; }
    .row-actions { justify-content: flex-start; }

    /* Ticket list: table markup, card presentation. */
    .ticket-table.stacked, .ticket-table.stacked tbody, .ticket-table.stacked tr, .ticket-table.stacked td {
        display: block;
        width: 100%;
    }
    .ticket-table.stacked thead { display: none; }
    .ticket-table.stacked tr {
        padding: 0.75rem 0.9rem;
        border-bottom: 1px solid var(--border);
    }
    .ticket-table.stacked tr:last-child { border-bottom: none; }
    .ticket-table.stacked td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 0.9rem;
        padding: 0.18rem 0;
        border: none;
        text-align: right;
    }
    .ticket-table.stacked td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        font-size: 0.72rem;
        font-weight: 650;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--muted);
        text-align: left;
    }
    .ticket-table.stacked td.desc-cell {
        display: block;
        max-width: none;
        margin: 0.25rem 0 0.4rem;
        text-align: left;
        font-weight: 550;
    }
    .ticket-table.stacked td.desc-cell::before { display: block; margin-bottom: 0.15rem; }
    .ticket-table.stacked td:empty { display: none; }

    /* Report tables keep their columns, but scroll inside the card. */
    .table-card { overflow-x: auto; }
    .report-grid { grid-template-columns: 1fr; }

    .ticket-meta { grid-template-columns: 1fr 1fr; }
    .attachment { width: calc(50% - 0.35rem); }

    .auth-page { display: block; }
    .auth-hero { display: none; }
    .auth-form-side { min-height: 100vh; padding: 1.2rem; }
    .auth-box { box-shadow: none; }
}

@media (max-width: 340px) {
    .stats-row { grid-template-columns: 1fr; }
    .attachment { width: 100%; }
}

/* Keep content clear of the iPhone home indicator when installed to the home screen. */
@supports (padding: max(0px)) {
    body { padding-bottom: env(safe-area-inset-bottom); }
}

/* Destructive action, kept visually apart from the workflow buttons so it cannot be
   hit by muscle memory while working through a ticket. */
.danger-zone {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1.5rem 0;
    padding: 0.9rem 1.1rem;
    border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
    border-radius: var(--radius);
    background: var(--danger-soft);
}
.danger-zone strong { display: block; font-size: 0.9rem; }
.danger-zone .muted { font-size: 0.8rem; }

@media (max-width: 760px) {
    .danger-zone { flex-direction: column; align-items: stretch; }
    .danger-zone .btn { width: 100%; }
}

/* Archive: reversible, so it reads as neutral admin tooling rather than a warning. */
.admin-zone {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1.5rem 0 0.75rem;
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
}
.admin-zone strong { display: block; font-size: 0.9rem; }
.admin-zone .muted { font-size: 0.8rem; }
.badge-archived { background: var(--slate-soft); color: var(--slate); }

@media (max-width: 760px) {
    .admin-zone { flex-direction: column; align-items: stretch; }
    .admin-zone .btn { width: 100%; }
}

/* Checkbox rows and grouped toggles (WhatsApp settings). */
.check-row { display: flex; align-items: center; gap: 0.6rem; font-weight: 550; }
.check-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); flex: 0 0 auto; }
.check-row span { font-size: 0.88rem; }
.check-group {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.8rem 0.95rem;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}
.check-group legend { padding: 0 0.35rem; font-size: 0.78rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.wa-input { width: 10rem; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: 0.84rem; }
@media (max-width: 760px) { .wa-input { width: 100%; } }

/* The number being confirmed — large enough to actually read back before agreeing to it. */
.confirm-number {
    margin: 0.2rem 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
}

/* PIN entry — wide spacing so four digits are readable at a glance on a phone. */
.pin-input { text-align: center; font-size: 1.6rem; letter-spacing: 0.6rem; font-variant-numeric: tabular-nums; }
.device-list { margin: 0.3rem 0 0.8rem; padding-left: 1.1rem; font-size: 0.85rem; }
.device-list li { margin-bottom: 0.2rem; }
.reset-summary { margin: 0.2rem 0; padding-left: 1.1rem; font-size: 0.88rem; }
.reset-summary li { margin-bottom: 0.15rem; }
.machine-name { width: 13rem; }
.machine-code { width: 5.5rem; text-transform: uppercase; }
.machine-name, .machine-code {
    padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font-size: 0.84rem;
}
@media (max-width: 760px) { .machine-name, .machine-code { width: 100%; } }

/* Admin forms stay readable even though the page itself is full width for the tables. */
.admin-form { max-width: 32rem; }

/* ---------- Bottom tab bar (phones) ---------- */

/* ---------- Bottom tab bar ---------- */

/* Shown at every width, so its appearance is defined here rather than inside a phone-only
   media query — that is what left the desktop pill with its icons on top of its labels. */
.tabbar {
    display: flex;
    position: fixed;
    z-index: 30;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px) saturate(1.2);
    -webkit-backdrop-filter: blur(12px) saturate(1.2);
}
.tabbar .tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    min-height: 56px;
    padding: 0.45rem 0.25rem 0.5rem;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s ease;
}
.tabbar .tab svg {
    width: 23px;
    height: 23px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.tabbar .tab:hover { color: var(--primary); text-decoration: none; }
.tabbar .tab.active { color: var(--primary); }
.tabbar .tab.active svg { stroke-width: 2.1; }
.tabbar .tab:active { background: var(--surface-2); }
.tabbar .tab-accent svg { stroke-width: 1.9; }
.tabbar .tab-accent.active svg { stroke-width: 2.3; }

/* Phone: a full-width bar pinned to the bottom edge. */
@media (max-width: 760px) {
    .tabbar {
        left: 0;
        right: 0;
        bottom: 0;
        border-top: 1px solid var(--border);
        /* Clear of the iPhone home indicator without a gap on phones that have none. */
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Content must clear the bar rather than hide behind it. This has to go on the content
       container, NOT on body: the base rules set html/body to height:100%, so padding on a
       fixed-height body sits inside that height and never extends the scrollable area. */
    main.container, main.container-narrow {
        padding-bottom: calc(76px + env(safe-area-inset-bottom));
    }

    /* Same for the big button above the list — the tab bar already offers it, and two
       ways to do one thing on a small screen is just clutter. */
    .hide-on-phone { display: none !important; }
}

/* ---------- Page background ---------- */

/* A single, very pale cross-section of the magnet bore. It sits behind everything, does not
   scroll, and is light enough that no text ever competes with it — the point is a quiet
   sense of place, not decoration. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(1100px 620px at 50% -180px, var(--primary-soft), transparent 70%),
        url("data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20600%20600%22%20fill=%22none%22%20stroke=%22%234f46e5%22%20stroke-width=%2210%22%3E%20%3Ccircle%20cx=%22300%22%20cy=%22300%22%20r=%22250%22/%3E%20%3Ccircle%20cx=%22300%22%20cy=%22300%22%20r=%22205%22/%3E%20%3Ccircle%20cx=%22300%22%20cy=%22300%22%20r=%22120%22/%3E%20%3Cpath%20d=%22M50%20300h60M490%20300h60%22/%3E%20%3Cpath%20d=%22M180%20420h240%22%20stroke-width=%2214%22%20stroke-linecap=%22round%22/%3E%20%3Cpath%20d=%22M215%20420v55M385%20420v55%22%20stroke-width=%228%22%20stroke-linecap=%22round%22/%3E%20%3Ccircle%20cx=%22300%22%20cy=%22262%22%20r=%2234%22/%3E%20%3Cpath%20d=%22M266%20300c8%2022%2060%2022%2068%200%22%20stroke-linecap=%22round%22/%3E%20%3C/svg%3E") no-repeat;
    background-size: auto, 780px 780px;
    background-position: center top, right -260px bottom -240px;
    opacity: 0.10;
    pointer-events: none;
}

@media (max-width: 760px) {
    body::before {
        background-size: auto, 560px 560px;
        background-position: center top, right -230px bottom -190px;
        opacity: 0.075;
    }
}

/* ---------- Header: brand + one settings control ---------- */

.settings-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
    padding: 0.35rem 0.6rem 0.35rem 0.35rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    text-decoration: none;
    transition: border-color 0.15s ease, color 0.15s ease;
}
.settings-button:hover, .settings-button.active { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.settings-button .icon { width: 19px; height: 19px; }
.avatar-sm { width: 26px; height: 26px; font-size: 0.7rem; }
.avatar-lg { width: 46px; height: 46px; font-size: 1rem; }

/* Laptop navigation lives in the header, so the bottom bar — a phone idiom — is not shown. */
.topnav-tabs { display: none; }

@media (min-width: 761px) {
    .tabbar { display: none; }

    .topnav-tabs { display: flex; gap: 0.35rem; margin-left: 1.25rem; }
    .topnav-tabs a {
        display: inline-flex;
        align-items: center;
        gap: 0.45rem;
        padding: 0.45rem 0.8rem;
        border-radius: var(--radius-sm);
        color: var(--muted);
        font-size: 0.87rem;
        font-weight: 600;
        text-decoration: none;
        white-space: nowrap;
        transition: background 0.15s ease, color 0.15s ease;
    }
    .topnav-tabs a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
    .topnav-tabs a.active { background: var(--primary-soft); color: var(--primary); }
    .topnav-tabs .icon { width: 17px; height: 17px; }

    /* Rows stretched across a full-width laptop window read as a phone app pulled wide;
       hold the content to a comfortable measure instead. */
    main.container { max-width: 900px; }
}

/* ---------- Login ID / sign-in choice ---------- */

.id-card {
    display: flex; flex-direction: column; gap: 2px;
    padding: 0.85rem 1.05rem; margin-bottom: 0.9rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.id-card .muted { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 650; }
.id-card strong { font-size: 0.98rem; word-break: break-all; }

.choice {
    display: flex; align-items: flex-start; gap: 0.7rem;
    padding: 0.85rem 0.95rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.choice.chosen { border-color: var(--primary); background: var(--primary-soft); }
.choice input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex: 0 0 auto; }
.choice-text strong { display: block; font-size: 0.92rem; }
.choice-text .muted { display: block; font-size: 0.8rem; }
.pin-fields { display: flex; flex-direction: column; gap: 0.75rem; }

/* ---------- Dashboard queues ---------- */

.greeting { margin: 0.2rem 0 0.9rem; font-size: 1.3rem; }
a.stat-card { text-decoration: none; color: inherit; }
a.stat-card:hover { border-color: var(--primary); text-decoration: none; }

.queue { margin-top: 1.5rem; }
.queue-empty { margin-top: 1.5rem; }
.queue-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.55rem; }
.queue-head h2 { display: flex; align-items: center; gap: 0.5rem; margin: 0; font-size: 1rem; letter-spacing: -0.01em; }
.queue-head a { font-size: 0.83rem; font-weight: 600; white-space: nowrap; }
.queue-count {
    display: inline-grid; place-items: center; min-width: 21px; height: 21px; padding: 0 6px;
    border-radius: 999px; font-size: 0.72rem; font-weight: 700;
    background: var(--slate-soft); color: var(--slate);
}
.queue-danger  .queue-count { background: var(--danger-soft);  color: var(--danger); }
.queue-warning .queue-count { background: var(--warning-soft); color: var(--warning); }
.queue-success .queue-count { background: var(--success-soft); color: var(--success); }
.queue-primary .queue-count { background: var(--primary-soft); color: var(--primary); }

.queue-list {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden;
}
/* A coloured edge tells you which queue a row belongs to without reading the heading again. */
.queue-danger  .queue-list { border-left: 3px solid var(--danger); }
.queue-warning .queue-list { border-left: 3px solid var(--warning); }
.queue-success .queue-list { border-left: 3px solid var(--success); }
.queue-primary .queue-list { border-left: 3px solid var(--primary); }

.queue-row {
    display: flex; align-items: flex-start; gap: 0.75rem;
    padding: 0.75rem 0.95rem; border-bottom: 1px solid var(--border);
    color: var(--text); text-decoration: none;
}
.queue-row:last-child { border-bottom: none; }
.queue-row:hover { background: var(--surface-2); text-decoration: none; }
.queue-id { flex: 0 0 auto; font-weight: 700; font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 1px; }
.queue-body { flex: 1; min-width: 0; }
.queue-body strong { display: block; font-size: 0.89rem; font-weight: 600; }
.queue-body .muted { display: block; font-size: 0.77rem; margin-top: 1px; }
.queue-badges { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; }

@media (max-width: 760px) {
    .queue-badges { flex-direction: row; }
    .queue-row { flex-wrap: wrap; }
    .queue-badges { width: 100%; justify-content: flex-start; padding-left: 2rem; }
}

/* ---------- Ticket list ---------- */

.list-head { display: flex; align-items: baseline; gap: 0.6rem; margin: 0.2rem 0 0.75rem; }
.list-head h1 { margin: 0; font-size: 1.3rem; }
.list-count { font-size: 0.83rem; color: var(--muted); font-weight: 600; }

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.5rem;
    margin-bottom: 0.9rem;
}
.filter-grid select {
    width: 100%;
    padding: 0.5rem 2rem 0.5rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7290' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") no-repeat right 0.55rem center;
    background-size: 15px;
    appearance: none;
    -webkit-appearance: none;
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 500;
}
.ticket-rows { border-left: 3px solid var(--border); }

/* ---------- Settings rows ---------- */

/* Settings reuse the ticket row so both read as one app: the icon takes the slot the
   ticket number occupies, and the chevron the slot the badges occupy. */
.row-icon { display: grid; place-items: center; width: 22px; padding-top: 0; }
.row-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.row-chevron { width: 16px; height: 16px; flex: 0 0 auto; align-self: center; color: var(--border); fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.row-danger .row-icon, .row-danger .queue-body strong { color: var(--danger); }
.avatar-lg { width: 46px; height: 46px; font-size: 1rem; }

/* ---------- Search and ageing ---------- */

.search-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.7rem;
    margin-bottom: 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.search-row .icon { width: 17px; height: 17px; color: var(--muted); flex: 0 0 auto; }
.search-row input[type="search"] {
    flex: 1;
    min-width: 0;
    border: 0;
    background: none;
    padding: 0.6rem 0;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
}
.search-row input[type="search"]:focus { outline: none; }
.search-row:focus-within { border-color: var(--primary); box-shadow: var(--ring); }

/* Only shown once a ticket is past the wait its priority allows, so seeing one always
   means something rather than being decoration on every row. */
.age-flag {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--warning-soft);
    color: var(--warning);
    font-size: 0.7rem;
    font-weight: 700;
}
