:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --sidebar-bg: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-text-active: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-light: #64748b;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* ── Layout: sidebar + main ── */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    padding: 8px 12px 24px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.sidebar-nav a {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.sidebar-nav a.active {
    background: var(--primary);
    color: #fff;
}

.sidebar-cta {
    text-align: center;
    margin-top: 12px;
}

.sidebar-logout {
    text-align: center;
    margin-top: 8px;
    padding: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.82rem;
    opacity: 0.7;
}

.sidebar-logout:hover {
    opacity: 1;
}

.main {
    flex: 1;
    min-width: 0;
}

/* ── Mobile topbar + bottom nav (hidden on desktop) ── */
.topbar,
.bottom-nav {
    display: none;
}

/* ── Container ── */
.container {
    max-width: 1300px;
    margin: 0 auto;
    padding: 28px 32px;
}

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

.page-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
}

.page-subtitle {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-top: 4px;
}

.back-link {
    display: inline-block;
    color: var(--text-light);
    text-decoration: none;
    font-size: 0.85rem;
    margin-bottom: 6px;
}

.back-link:hover {
    color: var(--primary);
}

/* ── Buttons ── */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: #cbd5e1;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn-large {
    padding: 12px 24px;
    font-size: 1rem;
}

.btn-link {
    font-size: 0.85rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.btn-link:hover {
    text-decoration: underline;
}

/* ── Cards ── */
.card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 14px;
}

.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.card-header-row h3 {
    margin-bottom: 0;
}

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

.dash-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

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

/* ── KPI cards ── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

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

.kpi-card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 18px 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border-left: 3px solid var(--border);
}

.kpi-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
}

.kpi-label {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 4px;
}

.kpi-accent-new { border-left-color: #3b82f6; }
.kpi-accent-progress { border-left-color: #f59e0b; }
.kpi-accent-warn { border-left-color: #dc2626; }
.kpi-accent-done { border-left-color: #16a34a; }

/* ── Key-value tables (detail cards) ── */
.kv-table {
    width: 100%;
    border-collapse: collapse;
}

.kv-table td {
    padding: 7px 0;
    font-size: 0.9rem;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

.kv-table td:first-child {
    color: var(--text-light);
    width: 40%;
}

.kv-label {
    font-size: 0.8rem;
    color: var(--text-light);
    text-transform: uppercase;
    margin: 14px 0 6px;
}

.plain-list {
    list-style: none;
    font-size: 0.9rem;
}

.plain-list li {
    padding: 3px 0;
}

.plain-list li::before {
    content: "• ";
    color: var(--primary);
}

.problem-desc {
    background: #f8fafc;
    border-radius: 8px;
    padding: 12px 14px;
    margin-top: 14px;
    font-size: 0.9rem;
    color: var(--text-light);
}

.doc-links {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

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

.mini-table td {
    padding: 8px 4px;
    font-size: 0.87rem;
    border-bottom: 1px solid var(--border);
}

/* ── Timeline ── */
.timeline {
    list-style: none;
    position: relative;
    padding-left: 20px;
}

.timeline::before {
    content: "";
    position: absolute;
    left: 4px;
    top: 6px;
    bottom: 6px;
    width: 2px;
    background: var(--border);
}

.timeline li {
    position: relative;
    padding-bottom: 18px;
}

.timeline-dot {
    position: absolute;
    left: -20px;
    top: 4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
}

.timeline-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.timeline-detail {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 2px;
}

.timeline-meta {
    font-size: 0.78rem;
    color: var(--text-light);
    margin-top: 2px;
}

/* ── Form ── */
.form-container {
    max-width: 800px;
    background: var(--card-bg);
    border-radius: 10px;
    padding: 32px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.form-container h2 {
    margin-bottom: 24px;
}

fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

legend {
    font-weight: 600;
    padding: 0 8px;
    color: var(--primary);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
}

input[type="text"],
input[type="tel"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    background: white;
    transition: border-color 0.15s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea {
    resize: vertical;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-warning {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* ── Search ── */
.search-form {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.search-form input {
    flex: 1;
    max-width: 400px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
}

/* ── Filters ── */
.filters {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-label {
    font-weight: 600;
    margin-right: 8px;
}

/* ── Tables ── */
.tickets-table {
    width: 100%;
    border-collapse: collapse;
}

.tickets-table th {
    text-align: left;
    padding: 12px;
    border-bottom: 2px solid var(--border);
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-light);
}

.tickets-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}

.tickets-table tr:hover {
    background: #f8fafc;
}

.row-link {
    cursor: pointer;
}

.ticket-id {
    font-family: monospace;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
}

.text-light {
    color: var(--text-light);
}

.text-right {
    text-align: right;
}

/* ── Status badges ── */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 500;
    white-space: nowrap;
}

.status-lg {
    padding: 8px 16px;
    font-size: 0.95rem;
    border-radius: 8px;
}

.status-new {
    background: #dbeafe;
    color: #1e40af;
}

.status-assigned {
    background: #d1fae5;
    color: #065f46;
}

.status-progress {
    background: #fef3c7;
    color: #92400e;
}

.status-done {
    background: #f1f5f9;
    color: #475569;
}

.status-cancelled {
    background: #fee2e2;
    color: #991b1b;
}

/* ── Row highlights ── */
tr.status-new td:first-child {
    border-left: 3px solid #3b82f6;
}

tr.status-assigned td:first-child {
    border-left: 3px solid #16a34a;
}

tr.status-progress td:first-child {
    border-left: 3px solid #f59e0b;
}

/* ── Inline forms ── */
.inline-form {
    display: inline;
}

.status-form {
    margin-top: 14px;
}

.status-select {
    width: auto;
    padding: 4px 8px;
    font-size: 0.8rem;
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 48px;
    color: var(--text-light);
}

.empty-state p {
    margin-bottom: 16px;
    font-size: 1.1rem;
}

/* ── Highlight animation ── */
@keyframes highlight {
    0% { background: #fef3c7; }
    100% { background: transparent; }
}

.highlight {
    animation: highlight 2s ease-out;
}

/* ── Tables: horizontal scroll on narrow screens instead of squeezing ── */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding: 0 4px;
}

.table-scroll table {
    min-width: 640px;
}

/* ══════════════════════════════════════════════════════════
   MOBILE (≤860px): sidebar → top bar + bottom tab bar
   ══════════════════════════════════════════════════════════ */
@media (max-width: 860px) {
    .layout {
        flex-direction: column;
    }

    .sidebar {
        display: none;
    }

    .topbar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: var(--sidebar-bg);
        color: #fff;
        padding: 12px 16px;
        position: sticky;
        top: 0;
        z-index: 30;
    }

    .topbar-brand {
        font-weight: 700;
        font-size: 1.05rem;
    }

    .topbar-actions {
        display: flex;
        gap: 8px;
    }

    .topbar-icon-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        border-radius: 8px;
        background: rgba(255,255,255,0.12);
        text-decoration: none;
        font-size: 1.15rem;
    }

    .main {
        width: 100%;
    }

    .container {
        padding: 16px 16px calc(88px + env(safe-area-inset-bottom));
    }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--card-bg);
        border-top: 1px solid var(--border);
        z-index: 30;
        padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    }

    .bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 8px 2px;
        text-decoration: none;
        color: var(--text-light);
        font-size: 0.68rem;
        font-weight: 500;
        border-radius: 8px;
    }

    .bottom-nav a span {
        font-size: 1.25rem;
    }

    .bottom-nav a.active {
        color: var(--primary);
        background: #eff6ff;
    }
}

/* ══════════════════════════════════════════════════════════
   SMALL SCREENS (≤640px): stack grids, forms, cards
   ══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
    .card {
        padding: 16px;
    }

    .form-container {
        padding: 20px 16px;
    }

    .detail-grid,
    .dash-columns,
    .form-row,
    .kpi-grid-sm {
        grid-template-columns: 1fr;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .kpi-card {
        padding: 14px 16px;
    }

    .kpi-value {
        font-size: 1.3rem;
    }

    .page-header {
        flex-direction: column;
        gap: 10px;
    }

    .card-header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .search-form {
        flex-direction: column;
        align-items: stretch;
    }

    .search-form input {
        max-width: none;
    }

    .doc-links {
        flex-direction: column;
    }

    .doc-links .btn {
        text-align: center;
    }

    .filters {
        gap: 6px;
    }

    fieldset {
        padding: 14px;
    }
}
