/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
    --font-sans: 'DM Sans', system-ui, sans-serif;
    --font-mono: 'DM Mono', monospace;

    /* Dark theme (default) */
    --bg-base:       #0f1117;
    --bg-surface:    #161b27;
    --bg-elevated:   #1e2535;
    --bg-hover:      #252d3d;
    --border:        #2a3347;
    --border-subtle: #1e2535;

    --text-primary:   #e8ecf4;
    --text-secondary: #8892a4;
    --text-muted:     #4f5a6e;

    --accent:        #3b7ef4;
    --accent-hover:  #5292ff;
    --accent-subtle: rgba(59,126,244,0.12);

    --success:       #22c55e;
    --success-subtle:#14532d26;
    --warning:       #f59e0b;
    --warning-subtle:#78350f26;
    --danger:        #ef4444;
    --danger-subtle: #7f1d1d26;
    --info:          #06b6d4;

    --priority-low:      #22c55e;
    --priority-medium:   #f59e0b;
    --priority-high:     #f97316;
    --priority-critical: #ef4444;

    --status-open:       #3b7ef4;
    --status-progress:   #a855f7;
    --status-review:     #f59e0b;
    --status-blocked:    #ef4444;
    --status-closed:     #4f5a6e;

    --sidebar-w: 220px;
    --radius-sm: 4px;
    --radius:    8px;
    --radius-lg: 12px;
    --shadow:    0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

[data-theme="light"] {
    --bg-base:       #f0f2f7;
    --bg-surface:    #ffffff;
    --bg-elevated:   #f8f9fc;
    --bg-hover:      #eef1f8;
    --border:        #dde2ee;
    --border-subtle: #eef1f8;

    --text-primary:   #1a2030;
    --text-secondary: #4f5a6e;
    --text-muted:     #9aa3b2;

    --accent:        #2563eb;
    --accent-hover:  #1d4ed8;
    --accent-subtle: rgba(37,99,235,0.08);

    --success-subtle: rgba(34,197,94,0.1);
    --warning-subtle: rgba(245,158,11,0.1);
    --danger-subtle:  rgba(239,68,68,0.1);

    --shadow:    0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

/* ── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background 0.2s, color 0.2s;
}

a { color: var(--accent); text-decoration: none; cursor: pointer; }
a:hover { color: var(--accent-hover); }

/* ── Login ──────────────────────────────────────────────────────────────────── */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-base);
    background-image: radial-gradient(ellipse 60% 50% at 50% 0%, rgba(59,126,244,0.08) 0%, transparent 70%);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 2rem;
}

.logo-mark {
    width: 40px; height: 40px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.logo-mark.sm { width: 28px; height: 28px; font-size: 0.9rem; border-radius: 6px; }

.logo-name { font-size: 1.1rem; font-weight: 600; line-height: 1; }
.logo-sub  { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; }

.login-divider {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin: 1rem 0;
    position: relative;
}
.login-divider::before, .login-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 44%;
    height: 1px;
    background: var(--border);
}
.login-divider::before { left: 0; }
.login-divider::after  { right: 0; }

/* ── App Shell ──────────────────────────────────────────────────────────────── */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.2s, min-width 0.2s;
}

.sidebar.collapsed {
    width: 52px;
    min-width: 52px;
}
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .user-pill { display: none; }
.sidebar.collapsed .sidebar-collapse { transform: rotate(180deg); }

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 14px;
    border-bottom: 1px solid var(--border-subtle);
}
.sidebar-title {
    font-weight: 600;
    font-size: 0.95rem;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-collapse {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px 4px;
    transition: transform 0.2s, color 0.2s;
    flex-shrink: 0;
}
.sidebar-collapse:hover { color: var(--text-primary); }

.sidebar-nav {
    flex: 1;
    padding: 8px 8px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 450;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
    user-select: none;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent-subtle); color: var(--accent); font-weight: 500; }

.nav-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.nav-section-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 12px 10px 4px;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-pill {
    font-size: 0.78rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 2px 0;
}

.theme-toggle {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: left;
    transition: background 0.15s;
}
.theme-toggle:hover { background: var(--bg-hover); }

/* ── Main Content ───────────────────────────────────────────────────────────── */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.view { padding: 24px; }

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}
.page-title { font-size: 1.3rem; font-weight: 600; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.card-title { font-weight: 500; font-size: 0.9rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Grid Layouts ───────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

@media (max-width: 900px) {
    .grid-4 { grid-template-columns: 1fr 1fr; }
    .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .sidebar { display: none; }
}

/* Stat card */
.stat-value  { font-size: 2rem; font-weight: 600; line-height: 1; }
.stat-label  { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }
.stat-delta  { font-size: 0.75rem; color: var(--success); margin-top: 6px; }

/* ── Table ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
    text-align: left;
    padding: 8px 12px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody tr {
    border-bottom: 1px solid var(--border-subtle);
    transition: background 0.1s;
    cursor: pointer;
}
tbody tr:hover { background: var(--bg-hover); }
tbody td { padding: 10px 12px; vertical-align: middle; }

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.badge-priority-low      { background: rgba(34,197,94,0.15);  color: var(--priority-low); }
.badge-priority-medium   { background: rgba(245,158,11,0.15); color: var(--priority-medium); }
.badge-priority-high     { background: rgba(249,115,22,0.15); color: var(--priority-high); }
.badge-priority-critical { background: rgba(239,68,68,0.15);  color: var(--priority-critical); border: 1px solid rgba(239,68,68,0.3); }

.badge-status-open       { background: rgba(59,126,244,0.15);  color: var(--status-open); }
.badge-status-in_progress{ background: rgba(168,85,247,0.15); color: var(--status-progress); }
.badge-status-in_review  { background: rgba(245,158,11,0.15); color: var(--status-review); }
.badge-status-blocked    { background: rgba(239,68,68,0.15);  color: var(--status-blocked); }
.badge-status-closed     { background: rgba(79,90,110,0.15);  color: var(--status-closed); }
.badge-status-wont_fix   { background: rgba(79,90,110,0.15);  color: var(--text-muted); }

.badge-type-bug          { background: rgba(239,68,68,0.12);  color: #f87171; }
.badge-type-feature      { background: rgba(34,197,94,0.12);  color: #4ade80; }
.badge-type-improvement  { background: rgba(59,126,244,0.12); color: #60a5fa; }
.badge-type-task         { background: rgba(100,116,139,0.12);color: #94a3b8; }
.badge-type-question     { background: rgba(245,158,11,0.12); color: #fbbf24; }
.badge-type-customer_request { background: rgba(168,85,247,0.12); color: #c084fc; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
    white-space: nowrap;
    user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline  { background: transparent; color: var(--text-primary); border-color: var(--border); }
.btn-outline:hover { background: var(--bg-hover); }
.btn-ghost    { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-full     { width: 100%; justify-content: center; margin-top: 8px; }
.btn.sm       { padding: 4px 10px; font-size: 0.78rem; }
.btn.xs       { padding: 2px 7px; font-size: 0.72rem; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-group label { font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    padding: 7px 10px;
    width: 100%;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--bg-elevated); }

.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
}
.search-bar input {
    background: none;
    border: none;
    padding: 0;
    flex: 1;
}
.search-bar input:focus { box-shadow: none; }

/* ── Progress bar ───────────────────────────────────────────────────────────── */
.progress-bar {
    height: 4px;
    background: var(--bg-elevated);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 6px;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s;
}

/* ── Ticket list ────────────────────────────────────────────────────────────── */
.ticket-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: background 0.1s;
}
.ticket-row:hover { background: var(--bg-hover); }
.ticket-ref { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-muted); min-width: 70px; }
.ticket-title { flex: 1; font-size: 0.875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-meta { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* ── Project tree ───────────────────────────────────────────────────────────── */
.project-tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.1s;
}
.project-tree-item:hover { background: var(--bg-hover); }
.project-tree-children { padding-left: 20px; border-left: 1px solid var(--border-subtle); margin-left: 14px; }
.project-tree-name { flex: 1; font-size: 0.875rem; }
.project-tree-key { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted); background: var(--bg-elevated); padding: 1px 5px; border-radius: 3px; }

/* ── Ticket detail ──────────────────────────────────────────────────────────── */
.ticket-detail-grid {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 20px;
    align-items: start;
}
@media (max-width: 800px) { .ticket-detail-grid { grid-template-columns: 1fr; } }

.ticket-sidebar-card { display: flex; flex-direction: column; gap: 12px; }
.detail-field { display: flex; flex-direction: column; gap: 3px; }
.detail-field label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.detail-field .val { font-size: 0.875rem; }

.comments-section { margin-top: 24px; }
.comment-item {
    padding: 12px;
    background: var(--bg-elevated);
    border-radius: var(--radius);
    margin-bottom: 8px;
    border-left: 2px solid var(--border);
}
.comment-item.internal { border-left-color: var(--warning); }
.comment-header { display: flex; justify-content: space-between; margin-bottom: 6px; }
.comment-author { font-size: 0.8rem; font-weight: 500; }
.comment-time   { font-size: 0.72rem; color: var(--text-muted); }
.comment-body   { font-size: 0.875rem; line-height: 1.5; }

/* Task checklist */
.task-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.875rem;
}
.task-item input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }
.task-item.done span { text-decoration: line-through; color: var(--text-muted); }

/* AI panel */
.ai-panel {
    background: linear-gradient(135deg, rgba(59,126,244,0.08) 0%, rgba(168,85,247,0.08) 100%);
    border: 1px solid rgba(59,126,244,0.2);
    border-radius: var(--radius);
    padding: 14px;
    margin-top: 12px;
}
.ai-panel-header { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 500; color: var(--accent); margin-bottom: 8px; }
.ai-panel-body { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; }

/* ── Drag & drop zone ────────────────────────────────────────────────────────── */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}
.drop-zone.drag-over { border-color: var(--accent); background: var(--accent-subtle); color: var(--accent); }
.drop-zone:hover { border-color: var(--text-muted); }

.attachment-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
}
.attachment-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-size { color: var(--text-muted); flex-shrink: 0; }

/* ── Dashboard ──────────────────────────────────────────────────────────────── */
.dashboard-greeting { font-size: 1.1rem; font-weight: 500; margin-bottom: 6px; }
.dashboard-date     { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 24px; }

/* ── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 14px;
}
.alert-error   { background: var(--danger-subtle);  color: var(--danger);  border: 1px solid rgba(239,68,68,0.3); }
.alert-success { background: var(--success-subtle); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; }
.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.2s ease;
    max-width: 300px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; padding: 4px; border-radius: 4px; }
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-body { padding: 20px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Utility ────────────────────────────────────────────────────────────────── */
.hidden   { display: none !important; }
.flex     { display: flex; }
.flex-1   { flex: 1; }
.gap-8    { gap: 8px; }
.gap-12   { gap: 12px; }
.mt-8     { margin-top: 8px; }
.mt-16    { margin-top: 16px; }
.mt-24    { margin-top: 24px; }
.text-muted { color: var(--text-secondary); }
.text-sm    { font-size: 0.8rem; }
.text-mono  { font-family: var(--font-mono); }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
