:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --bg: #f8fafc;
    --surface: #fff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --orange: #f59e0b;
    --orange-bg: #fef3c7;
    --green: #10b981;
    --green-bg: #d1fae5;
    --red: #ef4444;
    --red-bg: #fee2e2;
    --blue: #3b82f6;
    --blue-bg: #dbeafe;
    --purple: #8b5cf6;
    --purple-bg: #ede9fe;
    --gray: #6b7280;
    --gray-bg: #f1f5f9;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.1);
    --radius: 10px;
}
* { box-sizing: border-box; margin:0; padding:0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ LOGIN ============ */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}
.login-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 30px; }
.login-logo svg { color: var(--primary); margin-bottom: 10px; }
.login-logo h1 { font-size: 24px; color: var(--text); }
.login-logo p { color: var(--text-muted); font-size: 13px; margin-top: 5px; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin-top: 14px; margin-bottom: 5px; color: var(--text); }
.login-card input[type="email"], .login-card input[type="password"], .login-card input[type="text"] {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border .2s;
}
.login-card input:focus { outline: none; border-color: var(--primary); }
.login-card .btn-primary { width: 100%; margin-top: 20px; }
.login-demo {
    margin-top: 28px;
    padding: 16px;
    background: var(--primary-light);
    border-radius: var(--radius);
    font-size: 12px;
}
.login-demo strong { display: block; color: var(--primary); margin-bottom: 8px; }
.login-demo ul { list-style: none; }
.login-demo li { padding: 2px 0; color: var(--text); }
.login-demo code { background: rgba(0,0,0,.05); padding: 1px 6px; border-radius: 4px; font-size: 11px; }

.alert { padding: 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 10px; }
.alert-error { background: var(--red-bg); color: var(--red); }
.alert-success { background: var(--green-bg); color: var(--green); }

/* ============ LAYOUT ============ */
.app-layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}
.sidebar-brand {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-brand svg { color: var(--primary); }
.sidebar-brand span { font-weight: 700; font-size: 16px; }
.sidebar-nav { padding: 16px 10px; flex: 1; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text-muted);
    border-radius: 8px;
    margin-bottom: 3px;
    font-weight: 500;
    transition: all .15s;
}
.sidebar-nav a:hover { background: var(--gray-bg); color: var(--text); text-decoration: none; }
.sidebar-nav a.active { background: var(--primary-light); color: var(--primary); }
.sidebar-nav a svg { flex-shrink: 0; }
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}
.user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: var(--gray-bg);
    border-radius: 8px;
    margin-bottom: 10px;
}
.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-muted); }
.btn-logout {
    display: block; text-align: center; padding: 8px; font-size: 12px;
    color: var(--red); border: 1px solid var(--red-bg); border-radius: 6px; background: transparent;
}
.btn-logout:hover { background: var(--red-bg); text-decoration: none; }

.main {
    flex: 1;
    margin-left: 240px;
    padding: 24px 32px;
    min-width: 0;
}
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 { font-size: 22px; }
.page-header .subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ============ BUTTONS ============ */
.btn-primary, .btn-secondary, .btn-success, .btn-danger, .btn-warning, .btn-info {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; color: white; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--gray-bg); text-decoration: none; }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: #059669; color: white; text-decoration: none; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #dc2626; color: white; text-decoration: none; }
.btn-warning { background: var(--orange); color: white; }
.btn-info { background: var(--blue); color: white; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ============ CARDS / STATS ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.stat-card .stat-icon {
    width: 44px; height: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 12px;
}
.stat-icon.orange { background: var(--orange-bg); color: var(--orange); }
.stat-icon.green { background: var(--green-bg); color: var(--green); }
.stat-icon.red { background: var(--red-bg); color: var(--red); }
.stat-icon.blue { background: var(--blue-bg); color: var(--blue); }
.stat-icon.purple { background: var(--purple-bg); color: var(--purple); }
.stat-icon.indigo { background: var(--primary-light); color: var(--primary); }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 3px; }

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}
@media (max-width: 900px) {
    .charts-grid { grid-template-columns: 1fr; }
}
.chart-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.chart-card h3 { font-size: 14px; margin-bottom: 16px; color: var(--text); }
.chart-wrap { position: relative; height: 280px; }

/* ============ TABLE ============ */
.table-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.table-header h3 { font-size: 15px; }
.table-filters { display: flex; gap: 10px; flex-wrap: wrap; }
.table-filters input, .table-filters select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: white;
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.data-table th { background: var(--gray-bg); font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.data-table tbody tr:hover { background: var(--gray-bg); }
.data-table tbody tr:last-child td { border-bottom: none; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-gray { background: var(--gray-bg); color: var(--gray); }

/* ============ FORMS ============ */
.form-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    max-width: 800px;
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) {
    .form-grid { grid-template-columns: 1fr; }
}
.form-group label {
    display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px;
}
.form-group label .req { color: var(--red); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: white;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-actions { margin-top: 24px; display: flex; gap: 12px; justify-content: flex-end; }

/* ============ MODAL ============ */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: 14px;
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { font-size: 17px; }
.modal-close {
    background: none; border: none; cursor: pointer; color: var(--text-muted);
    width: 32px; height: 32px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--gray-bg); color: var(--text); }
.modal-body { padding: 22px; }
.modal-footer {
    padding: 16px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; margin-bottom: 18px; }
.detail-item label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.detail-item .v { font-size: 14px; color: var(--text); font-weight: 500; margin-top: 2px; }

.timeline { border-left: 2px solid var(--border); padding-left: 18px; margin-top: 20px; }
.timeline-item { position: relative; padding-bottom: 16px; }
.timeline-item:before {
    content: '';
    position: absolute;
    left: -25px;
    top: 4px;
    width: 12px; height: 12px;
    background: var(--primary);
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 0 0 2px var(--primary);
}
.timeline-action { font-weight: 600; font-size: 13px; }
.timeline-meta { font-size: 11px; color: var(--text-muted); }
.timeline-detail { font-size: 12px; color: var(--text); margin-top: 3px; padding: 6px 10px; background: var(--gray-bg); border-radius: 6px; }

.section-title { font-size: 14px; font-weight: 700; margin: 18px 0 12px; color: var(--text); }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state svg { margin-bottom: 12px; opacity: .4; }

/* ============ TOAST ============ */
#toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    pointer-events: none;
}
.toast-msg {
    background: var(--text);
    color: white;
    padding: 12px 18px;
    border-radius: 10px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    pointer-events: auto;
    animation: slideIn .25s;
}
.toast-msg.success { background: var(--green); }
.toast-msg.error { background: var(--red); }
@keyframes slideIn { from { transform: translateX(120%); } to { transform: translateX(0); } }

/* MOBILE */
.mobile-menu-btn {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
}
@media (max-width: 768px) {
    .mobile-menu-btn { display: inline-flex; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s;
        z-index: 999;
    }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; padding: 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-value { font-size: 22px; }
    .data-table th, .data-table td { padding: 8px; font-size: 12px; }
    .detail-grid { grid-template-columns: 1fr; }
}
