:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface-2: #243044;
    --border: #2d3a4f;
    --text: #e8eef7;
    --muted: #8b9cb3;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 12px;
    --font: "DM Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

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

.text-muted { color: var(--muted); }
.text-danger { color: var(--danger); font-size: 0.875rem; }

/* Auth */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at top, #1e3a5f 0%, var(--bg) 60%);
}

.auth-shell { width: 100%; max-width: 420px; padding: 2rem; }

.auth-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: 0 20px 50px rgba(0,0,0,.35);
}

.auth-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }

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

.sidebar {
    width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 0.25rem; }

.nav-link {
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
    transition: background .15s, color .15s;
}

.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

.nav-section {
    margin-top: 1rem;
    margin-bottom: 0.25rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
}

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

.sidebar-account-menu { margin: 0; }

.sidebar-account-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
    cursor: pointer;
    list-style: none;
    user-select: none;
    transition: background .15s;
}

.sidebar-account-trigger::-webkit-details-marker { display: none; }

.sidebar-account-trigger::marker { content: ""; }

.sidebar-account-trigger:hover { background: var(--surface-2); }

.sidebar-account-user {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.sidebar-account-hint {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sidebar-account-chevron {
    flex-shrink: 0;
    width: 0.5rem;
    height: 0.5rem;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
    margin-top: -0.15rem;
    transition: transform .2s ease;
}

.sidebar-account-menu[open] .sidebar-account-chevron {
    transform: rotate(-135deg);
    margin-top: 0.15rem;
}

.sidebar-account-panel {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 0.5rem;
    padding-left: 0.25rem;
}

.user-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text);
    margin-bottom: 0;
    word-break: break-all;
}

.main-content { flex: 1; padding: 2rem; overflow-x: auto; }

/* Layout components */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.page-header h1 { margin: 0; font-size: 1.75rem; }

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

.alert-link { color: var(--primary); font-weight: 600; margin-left: 0.35rem; }

.section-title { margin: 2rem 0 1rem; font-size: 1.1rem; }

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

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

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

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
}

.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.detail-grid .span-2 { grid-column: span 2; }

@media (max-width: 900px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; }
    .detail-grid { grid-template-columns: 1fr; }
    .detail-grid .span-2 { grid-column: span 1; }
}

.detail-list {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 0.5rem 1rem;
}

.detail-list dt { color: var(--muted); margin: 0; }
.detail-list dd { margin: 0; }

.description-block { white-space: pre-wrap; background: var(--surface-2); padding: 1rem; border-radius: 8px; }

.message-thread { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1.5rem; }
.message {
    padding: 1rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.message-requester { border-left: 3px solid var(--primary); }
.message-support { border-left: 3px solid var(--success); }
.message-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}
.message-header time { margin-left: auto; color: var(--muted); font-size: 0.8rem; }
.message-body { white-space: pre-wrap; line-height: 1.55; }
.message-reply-form { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.message-closed { margin-top: 1rem; font-size: 0.9rem; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.timeline small { display: block; color: var(--muted); margin-top: 0.25rem; }

/* Forms */
.form-control, .form-select {
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
}

.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.25);
}

.form-label { display: block; margin-bottom: 0.35rem; font-size: 0.875rem; color: var(--muted); }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-grid .span-2 { grid-column: span 2; }
.form-group { display: flex; flex-direction: column; }
.form-actions { display: flex; gap: 0.75rem; align-items: center; }
.stack-form { display: flex; flex-direction: column; gap: 0.75rem; }
.change-password-form,
.edit-user-form { max-width: 36rem; }
.sidebar-account-panel .btn {
    width: 100%;
    justify-content: flex-start;
    margin-bottom: 0;
}

.sidebar-account-panel form { margin: 0; }

.sidebar-account-panel form .btn { width: 100%; }
.inline-form { display: inline; }
.table-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.agent-note-display { background: var(--surface-2, #f4f6f8); border-left: 3px solid var(--accent, #2563eb); padding: 0.75rem 1rem; border-radius: 0 6px 6px 0; white-space: pre-wrap; }

.row-mine td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.badge-mine { background: rgba(59, 130, 246, 0.15); color: var(--primary); font-size: 0.7rem; margin-left: 0.35rem; vertical-align: middle; }
.badge-readonly { background: var(--surface-2); color: var(--muted); font-size: 0.7rem; margin-left: 0.35rem; vertical-align: middle; }

.form-check { display: flex; align-items: center; gap: 0.5rem; }
.form-check-input { width: 1rem; height: 1rem; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 1.1rem;
    border-radius: 8px;
    border: none;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, transform .1s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; text-decoration: none; }

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

.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.w-100 { width: 100%; }

/* Table */
.table-responsive { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .04em; }
.data-table tbody tr:hover { background: var(--surface-2); }
.row-overdue { background: rgba(239,68,68,.08) !important; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.priority-low { background: #1e3a2f; color: #86efac; }
.priority-medium { background: #3b3520; color: #fcd34d; }
.priority-high { background: #3b2518; color: #fdba74; }
.priority-critical { background: #3b1818; color: #fca5a5; }

.status-new { background: #1e2a3b; color: #93c5fd; }
.status-open { background: #1e2f3b; color: #67e8f9; }
.status-waiting { background: #3b3520; color: #fcd34d; }
.status-progress { background: #2a1e3b; color: #c4b5fd; }
.status-resolved { background: #1e3a2f; color: #86efac; }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-danger { background: rgba(239,68,68,.15); border: 1px solid var(--danger); color: #fecaca; }
.alert-success { background: rgba(34,197,94,.15); border: 1px solid var(--success); color: #bbf7d0; }

/* Landing */
.landing {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    background: radial-gradient(ellipse at center, #1e3a5f 0%, var(--bg) 70%);
}

.landing h1 { font-size: 2.5rem; margin-bottom: 0.5rem; }
.landing-actions { display: flex; gap: 1rem; margin-top: 2rem; flex-wrap: wrap; justify-content: center; }
