:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-alt: #f1f3f5;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --radius: 6px;
    --nav-width: 220px;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-alt: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #fbbf24;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
}

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

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

/* Header */
.header {
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px;
    position: sticky; top: 0; z-index: 100;
    box-shadow: var(--shadow);
}
.header-logo a { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.header-actions { display: flex; align-items: center; gap: 12px; }
.user-name small { color: var(--text-muted); }
.theme-toggle {
    width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
    background: var(--surface-alt); color: var(--text); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

/* Layout */
.app-body { display: flex; flex: 1; }
.nav {
    width: var(--nav-width); background: var(--surface); border-right: 1px solid var(--border);
    padding: 16px 0; flex-shrink: 0;
}
.nav-link {
    display: block; padding: 10px 20px; color: var(--text); border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--surface-alt); text-decoration: none; }
.nav-link.active { border-left-color: var(--primary); color: var(--primary); background: var(--surface-alt); }

.content { flex: 1; padding: 20px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* Footer */
.footer {
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 10px 20px; font-size: 0.85rem; color: var(--text-muted);
    display: flex; justify-content: space-between; align-items: center;
}

/* Common */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h1 { margin: 0; font-size: 1.5rem; }

.panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.panel h2 { margin-top: 0; font-size: 1.1rem; margin-bottom: 12px; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; text-align: center; color: var(--text); box-shadow: var(--shadow);
    transition: transform .05s ease;
}
.card:hover { transform: translateY(-2px); text-decoration: none; }
.card-value { font-size: 2rem; font-weight: 700; }
.card-label { color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; }
.card-new .card-value { color: var(--primary); }
.card-work .card-value { color: var(--warning); }
.card-closed .card-value { color: var(--success); }
.card-overdue .card-value { color: var(--danger); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--border);
    background: var(--surface-alt); color: var(--text); cursor: pointer; font-size: 0.95rem;
}
.btn:hover { background: var(--border); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 4px 10px; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; color: var(--text-muted); font-size: 0.9rem; }
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text); font-size: 0.95rem; font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.form-actions { display: flex; gap: 10px; margin-top: 16px; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; }
.inline-form .btn { padding: 6px 10px; }

/* Filters */
.filters { margin-bottom: 6px; }
.filters-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.filters-actions { display: flex; gap: 10px; margin-top: 12px; }

/* Tables */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { background: var(--surface-alt); font-weight: 600; font-size: 0.85rem; color: var(--text-muted); }
.table tr:hover { background: var(--surface-alt); }
.table .empty { text-align: center; color: var(--text-muted); padding: 24px; }
.table-sm td, .table-sm th { padding: 6px 8px; font-size: 0.9rem; }

/* Status */
.status {
    display: inline-block; padding: 3px 8px; border-radius: 12px; font-size: 0.85rem; font-weight: 500;
    background: var(--surface-alt); color: var(--status-color, var(--text)); border: 1px solid var(--status-color, var(--border));
}

/* Lists */
.simple-list { list-style: none; margin: 0; padding: 0; }
.simple-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.badge { background: var(--surface-alt); padding: 2px 8px; border-radius: 10px; font-size: 0.85rem; }

/* Definition list */
.dl { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; }
.dl dt { color: var(--text-muted); font-size: 0.85rem; }
.dl dd { margin: 0; }

/* Timeline / comments */
.timeline, .activity-list, .attachment-list, .comments { list-style: none; margin: 0; padding: 0; }
.timeline li, .activity-list li, .attachment-list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline .time, .activity-list .activity-time { color: var(--text-muted); font-size: 0.8rem; margin-right: 8px; }
.timeline .comment, .comment-item { background: var(--surface-alt); padding: 10px; border-radius: var(--radius); margin-top: 6px; }
.comment-header { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.comment-header .role { color: var(--text-muted); font-size: 0.8rem; }
.comment-header .time { color: var(--text-muted); font-size: 0.8rem; margin-left: auto; }
.pre-wrap { white-space: pre-wrap; line-height: 1.5; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
[data-theme="dark"] .alert-error { background: #450a0a; color: #fecaca; border-color: #7f1d1d; }
[data-theme="dark"] .alert-success { background: #052e16; color: #bbf7d0; border-color: #14532d; }

/* Auth */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-wrapper { width: 100%; max-width: 380px; padding: 20px; }
.auth-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.auth-box h1 { margin-top: 0; font-size: 1.4rem; margin-bottom: 18px; }

/* Pagination */
.pagination { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 16px 0; }
.page-link { padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.page-info { color: var(--text-muted); }

/* Error pages */
.error-page { text-align: center; padding: 60px 20px; }
.error-page h1 { font-size: 4rem; margin: 0; color: var(--primary); }

/* Misc */
.total-info { color: var(--text-muted); margin-bottom: 8px; }
.big-value { font-size: 1.6rem; font-weight: 700; margin: 0; color: var(--primary); }

/* Responsive */
@media (max-width: 1024px) {
    .cards { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .filters-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
    .nav { width: 100%; position: fixed; bottom: 0; left: 0; border-right: none; border-top: 1px solid var(--border); display: flex; overflow-x: auto; z-index: 90; padding: 0; }
    .nav-link { white-space: nowrap; border-left: none; border-bottom: 2px solid transparent; }
    .nav-link.active { border-bottom-color: var(--primary); border-left: none; }
    .content { padding-bottom: 80px; }
    .app-body { flex-direction: column; }
    .cards { grid-template-columns: repeat(2, 1fr); }
    .filters-grid { grid-template-columns: 1fr; }
    .dl { grid-template-columns: 1fr; }
    .footer { flex-direction: column; gap: 4px; align-items: flex-start; }
}

@media (max-width: 480px) {
    .cards { grid-template-columns: 1fr; }
    .header-actions { gap: 6px; }
    .user-name { display: none; }
}
