:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --sidebar: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #ffffff;
    --success: #059669;
    --error: #dc2626;
    --warning: #d97706;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

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

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

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

.sidebar {
    width: 240px;
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-brand { padding: 1.25rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-brand a { display: flex; align-items: center; gap: 0.75rem; color: #fff; text-decoration: none; }
.brand-icon {
    width: 36px; height: 36px; border-radius: 8px;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
}
.brand-text { font-weight: 600; font-size: 15px; }

.sidebar-nav { flex: 1; padding: 1rem 0.5rem; }
.nav-item {
    display: block; padding: 0.6rem 0.75rem; margin-bottom: 2px;
    border-radius: 8px; color: var(--sidebar-text); text-decoration: none;
    font-size: 14px;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(37, 99, 235, 0.35); color: var(--sidebar-active); font-weight: 500; }
.nav-item-muted { opacity: 0.7; font-size: 13px; }

.sidebar-footer { padding: 1rem; border-top: 1px solid rgba(255,255,255,0.08); }
.user-menu { margin-top: 0.75rem; font-size: 13px; }
.user-name { display: block; color: #fff; font-weight: 500; }
.user-role { display: block; color: var(--sidebar-text); font-size: 12px; margin-bottom: 0.25rem; }
.logout-link { color: var(--sidebar-text); font-size: 12px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 1rem;
    padding: 1rem 1.5rem; background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.menu-toggle {
    display: none; background: none; border: 1px solid var(--border);
    border-radius: 6px; padding: 0.35rem 0.6rem; cursor: pointer; font-size: 18px;
}
.page-title { margin: 0; font-size: 1.25rem; font-weight: 600; }
.main-content { padding: 1.5rem; flex: 1; }

/* Public pages */
.public-shell { min-height: 100vh; display: flex; flex-direction: column; }
.public-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.public-logo { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.public-login { font-size: 14px; }
.public-main { flex: 1; padding: 2rem 1rem; max-width: 720px; margin: 0 auto; width: 100%; }
.public-footer { text-align: center; padding: 1.5rem; color: var(--text-muted); font-size: 13px; }
.public-card, .auth-card, .install-card {
    background: var(--surface); border-radius: var(--radius);
    padding: 2rem; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.public-lead, .auth-lead, .install-lead { color: var(--text-muted); margin-top: 0; }
.auth-card, .install-card { max-width: 440px; margin: 4rem auto; }
.page-install { background: linear-gradient(160deg, #eef2ff 0%, var(--bg) 50%); }
.auth-footer { margin-top: 1.5rem; text-align: center; font-size: 14px; color: var(--text-muted); }

.token-box {
    background: #f8fafc; border: 1px dashed var(--border);
    border-radius: 8px; padding: 1rem; word-break: break-all; margin: 1rem 0;
}

/* Panels & tables */
.panel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.panel-header h2, .panel h2, .panel h3 { margin: 0 0 1rem; font-size: 1rem; font-weight: 600; }
.panel-header h2 { margin: 0; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { padding: 0.65rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table tbody tr:hover { background: #f8fafc; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.25rem; box-shadow: var(--shadow);
}
.stat-value { display: block; font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stat-label { display: block; font-size: 13px; color: var(--text-muted); margin-top: 0.25rem; }
.stat-urgent .stat-value { color: var(--error); }

.reports-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.report-list { list-style: none; margin: 0; padding: 0; }
.report-list li { display: flex; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.report-list li:last-child { border-bottom: none; }

/* Badges */
.badge {
    display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em;
}
.badge-open { background: #dbeafe; color: #1d4ed8; }
.badge-progress { background: #fef3c7; color: #b45309; }
.badge-waiting { background: #fce7f3; color: #be185d; }
.badge-resolved { background: #d1fae5; color: #047857; }
.badge-closed { background: #e2e8f0; color: #475569; }
.badge-internal { background: #fef9c3; color: #854d0e; }

.priority-low { background: #f1f5f9; color: #64748b; }
.priority-normal { background: #dbeafe; color: #1d4ed8; }
.priority-high { background: #ffedd5; color: #c2410c; }
.priority-urgent { background: #fee2e2; color: #b91c1c; }

.category-tag {
    display: inline-block; padding: 0.15rem 0.5rem; border-radius: 6px; font-size: 12px;
    background: color-mix(in srgb, var(--cat-color) 15%, white);
    color: var(--cat-color); border: 1px solid color-mix(in srgb, var(--cat-color) 30%, white);
}

/* Forms */
.form-stack { display: flex; flex-direction: column; gap: 1rem; }
.form-narrow { max-width: 400px; }
.form-group label, .sidebar-form label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 0.35rem; }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 0.55rem 0.75rem; border: 1px solid var(--border);
    border-radius: 8px; font: inherit; background: #fff;
}
.form-input-sm { padding: 0.35rem 0.5rem; font-size: 13px; }
.form-textarea { resize: vertical; min-height: 100px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-divider { border: none; border-top: 1px solid var(--border); margin: 0.5rem 0; }
.checkbox-label { font-size: 14px; display: flex; align-items: center; gap: 0.5rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.55rem 1rem; border-radius: 8px; font: inherit; font-size: 14px;
    font-weight: 500; cursor: pointer; border: 1px solid transparent; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: #f8fafc; text-decoration: none; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); padding: 0.35rem 0.5rem; }
.btn-sm { font-size: 13px; padding: 0.35rem 0.65rem; }
.btn-block { width: 100%; }

.filter-bar {
    display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.25rem;
    align-items: center;
}
.filter-bar .form-input { max-width: 220px; }
.filter-bar .form-select { max-width: 160px; }

/* Ticket detail */
.ticket-layout { display: grid; grid-template-columns: 1fr 280px; gap: 1.25rem; align-items: start; }
.ticket-title-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.75rem; margin-bottom: 0.75rem; }
.ticket-title-row h2 { margin: 0; font-size: 1.25rem; }
.ticket-number { font-weight: 700; color: var(--text-muted); }
.ticket-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.requester-info { display: grid; gap: 0.5rem; margin: 0; font-size: 14px; }
.requester-info div { display: grid; grid-template-columns: 100px 1fr; gap: 0.5rem; }
.requester-info dt { margin: 0; color: var(--text-muted); font-weight: 500; }
.requester-info dd { margin: 0; }

.timeline { margin-bottom: 1.25rem; }
.timeline-item {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem; margin-bottom: 0.75rem;
}
.timeline-internal { border-left: 3px solid #eab308; background: #fffbeb; }
.timeline-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; font-size: 14px; }
.timeline-body { font-size: 14px; white-space: pre-wrap; word-break: break-word; }

.attachment-list { list-style: none; margin: 0.5rem 0 0; padding: 0; font-size: 13px; }
.attachment-list li { margin-top: 0.25rem; }

.sidebar-panel .sidebar-form { margin-bottom: 1rem; }
.sidebar-panel .sidebar-form:last-child { margin-bottom: 0; }

.activity-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.activity-list li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.activity-list li:last-child { border-bottom: none; }
.activity-text { display: block; }
.text-muted { color: var(--text-muted); font-size: 13px; }

.actions-cell { white-space: nowrap; }
.inline-form { display: inline; }
.inline-details { display: inline-block; }
.inline-reset-form { display: flex; gap: 0.5rem; margin-top: 0.5rem; padding: 0.5rem; background: #f8fafc; border-radius: 8px; }
.color-input { width: 60px; padding: 0.2rem; height: 36px; }

.empty-state { color: var(--text-muted); text-align: center; padding: 2rem; }

/* Alerts */
.alert {
    padding: 0.75rem 1rem; border-radius: 8px; margin: 0 1.5rem 0; font-size: 14px;
}
.page-public .alert, .page-install .alert { margin: 0 0 1rem; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.main .alert { margin: 1rem 1.5rem 0; }

@media (max-width: 900px) {
    .ticket-layout { grid-template-columns: 1fr; }
    .form-row-2 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed; inset: 0 auto 0 0; z-index: 100;
        transform: translateX(-100%); transition: transform 0.2s;
    }
    .sidebar.open { transform: translateX(0); }
    .menu-toggle { display: block; }
}
