:root {
    --sidebar-bg: #1a2332;
    --sidebar-border: #243044;
    --sidebar-text: #c5d0de;
    --sidebar-muted: #7b8ba3;
    --sidebar-active: #20a53a;
    --sidebar-active-bg: rgba(32, 165, 58, 0.12);
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-width: 240px;

    --main-bg: #eef1f6;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 16px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 8px 30px rgba(15, 23, 42, 0.12);
}

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

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

/* ── App shell (sidebar layout) ── */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--sidebar-active), #1d8f3a);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-icon svg {
    width: 20px;
    height: 20px;
    color: white;
}

.brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
}

.brand-sub {
    font-size: 0.7rem;
    color: var(--sidebar-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.5rem;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.85rem;
    margin-bottom: 0.2rem;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.nav-item.active {
    background: var(--sidebar-active-bg);
    color: #fff;
    border-left-color: var(--sidebar-active);
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.85;
}

.nav-item.active .nav-icon {
    opacity: 1;
    color: var(--sidebar-active);
}

.nav-icon svg {
    width: 100%;
    height: 100%;
}

.sidebar-footer {
    padding: 0.75rem 0.5rem 1rem;
    border-top: 1px solid var(--sidebar-border);
}

.sidebar-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--sidebar-muted);
    padding: 0.5rem 0.85rem;
    margin-bottom: 0.5rem;
}

.sidebar-status.is-ok { color: #6ee7a0; }
.sidebar-status.is-warn { color: #fcd34d; }

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.6rem 0.85rem;
    margin-bottom: 0.35rem;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: white;
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.7rem;
    color: var(--sidebar-muted);
    text-transform: capitalize;
}

.nav-logout {
    color: var(--sidebar-muted);
}

.nav-logout:hover {
    color: #fca5a5;
}

.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.sidebar-toggle {
    display: none;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-toggle svg {
    width: 20px;
    height: 20px;
}

.topbar-titles {
    flex: 1;
    min-width: 0;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.3;
}

.page-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.main-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1440px;
    width: 100%;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 150;
}

body.sidebar-open .sidebar-backdrop {
    display: block;
}

/* ── Legacy .app wrapper (unused but kept safe) ── */

.app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

/* ── Status badges ── */

.status-badge {
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-ok {
    background: rgba(22, 163, 74, 0.1);
    color: var(--success);
    border: 1px solid rgba(22, 163, 74, 0.25);
}

.status-warn {
    background: rgba(217, 119, 6, 0.1);
    color: var(--warning);
    border: 1px solid rgba(217, 119, 6, 0.25);
}

/* ── Cards ── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.35rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.card h2, .card h3 {
    font-size: 1.05rem;
    margin-bottom: 0.85rem;
    color: var(--text);
    font-weight: 600;
}

.alert-card code, .alert-card pre {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text);
}

.alert-card pre {
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;
}

.alert-card a {
    color: var(--primary);
}

/* ── Forms ── */

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

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* ── Buttons ── */

.btn {
    padding: 0.6rem 1.15rem;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}

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

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: #cbd5e1;
}

.btn-danger {
    background: rgba(220, 38, 38, 0.08);
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.2);
}

.btn-danger:hover:not(:disabled) {
    background: rgba(220, 38, 38, 0.14);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

a.btn {
    display: inline-block;
    text-decoration: none;
    text-align: center;
}

/* ── Loading & alerts ── */

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.95rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
}

.error-card {
    background: rgba(220, 38, 38, 0.06);
    border-color: rgba(220, 38, 38, 0.2);
    color: #b91c1c;
}

.hidden {
    display: none !important;
}

/* ── Stats grid ── */

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

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s;
}

.stat-card:hover {
    box-shadow: var(--shadow-lg);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
}

.stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

/* ── Charts ── */

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.chart-card {
    overflow: hidden;
}

.chart-host {
    min-height: 300px;
}

.chart-host-wide {
    min-height: 340px;
}

.chart-wide {
    grid-column: 1 / -1;
}

/* ── Tables ── */

.table-wrap {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead th {
    text-align: left;
    padding: 0.7rem 1rem;
    background: var(--surface-2);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: rgba(37, 99, 235, 0.03);
}

.score-high { color: var(--success); font-weight: 700; }
.score-mid { color: var(--warning); font-weight: 700; }
.score-low { color: var(--danger); font-weight: 700; }

/* ── Login page ── */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, #1a2332 0%, #0f172a 50%, #1e3a5f 100%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    margin-bottom: 0.5rem;
}

.login-brand .brand-icon {
    width: 44px;
    height: 44px;
}

.login-card h1 {
    font-size: 1.35rem;
    margin-bottom: 0;
    color: var(--text);
}

.login-form {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.alert-error {
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.2);
    color: #b91c1c;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-top: 1rem;
}

.alert-success {
    background: rgba(22, 163, 74, 0.08);
    border: 1px solid rgba(22, 163, 74, 0.2);
    color: #15803d;
}

.role-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
}

.role-admin {
    background: rgba(124, 58, 237, 0.1);
    color: #7c3aed;
}

.role-user {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
}

.badge-you {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 0.35rem;
}

.inline-form {
    display: inline;
}

.assign-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.form-select-inline {
    width: auto;
    min-width: 160px;
}

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

.section-note {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: -0.35rem 0 0.85rem;
    line-height: 1.5;
}

.sync-status {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.tickets-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.tickets-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
}

#tickets-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

#tickets-table th.sortable:hover {
    color: var(--text);
}

#tickets-table th.sort-active {
    color: var(--primary);
}

#tickets-table .sort-ind {
    font-size: 0.7rem;
    margin-left: 0.2rem;
}

#tickets-table tbody tr.ticket-row {
    cursor: pointer;
}

#tickets-table tbody tr.ticket-row:hover {
    background: rgba(37, 99, 235, 0.05);
}

#tickets-table tbody tr.ticket-row.expanded {
    background: rgba(37, 99, 235, 0.08);
}

#tickets-table .ticket-key {
    color: var(--primary);
    font-weight: 600;
    white-space: nowrap;
}

#tickets-table .ticket-title {
    max-width: 280px;
}

.status-pill {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-done {
    background: rgba(22, 163, 74, 0.1);
    color: #15803d;
}

.status-progress {
    background: rgba(217, 119, 6, 0.1);
    color: #b45309;
}

.status-todo {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
}

.status-other {
    background: rgba(100, 116, 139, 0.1);
    color: var(--text-muted);
}

.ticket-details-row td {
    padding: 0 !important;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.ticket-details {
    padding: 1rem 1.25rem 1.25rem 1.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    white-space: pre-wrap;
    line-height: 1.55;
    max-height: 280px;
    overflow-y: auto;
}

.ticket-details.empty {
    font-style: italic;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.pagination-info {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.pagination-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.pagination-controls .btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ── Responsive ── */

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .main-wrapper {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: flex;
    }

    .topbar-actions .status-badge {
        display: none;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .chart-wide {
        grid-column: 1;
    }

    .main-content {
        padding: 1rem;
    }
}
