:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --purple: #8b5cf6;

    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --border-light: #f1f5f9;

    --text: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;

    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #2563eb;
    --sidebar-text: #94a3b8;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.5;
}

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

/* ===== APP LAYOUT ===== */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: width 0.2s ease;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand .logo-icon {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--primary), #06b6d4);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1.25rem;
}

.sidebar-brand .logo-text {
    color: #fff;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}

.sidebar-brand .logo-sub {
    color: var(--text-light);
    font-size: 0.7rem;
    display: block;
    font-weight: 400;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0.75rem;
}

.sidebar-section {
    margin-bottom: 0.5rem;
}

.sidebar-section-title {
    padding: 0.5rem 1rem 0.25rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-light);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    margin: 2px 0;
    color: var(--sidebar-text);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
    text-decoration: none;
}

.sidebar-link i { font-size: 1.05rem; width: 20px; text-align: center; }

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-link.active {
    background: var(--sidebar-active);
    color: #fff;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-footer .sidebar-link {
    color: var(--warning);
}

.main-area {
    margin-left: 260px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: 64px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-icon-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
}

.topbar-icon-btn:hover {
    background: var(--border-light);
    color: var(--text);
}

.topbar-icon-btn .badge-dot {
    position: absolute;
    top: 8px; right: 8px;
    width: 8px; height: 8px;
    background: var(--danger);
    border-radius: 50%;
    border: 2px solid var(--surface);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
}

.user-menu:hover { background: var(--border-light); }

.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--info));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
}

.user-info { line-height: 1.2; }
.user-info .user-name { font-size: 0.85rem; font-weight: 600; color: var(--text); }
.user-info .user-role { font-size: 0.72rem; color: var(--text-muted); }

.content-wrapper {
    padding: 1.5rem;
    flex: 1;
}

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

.page-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 0.25rem 0;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
}

/* ===== CARDS ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h5, .card-header h6 { margin: 0; font-weight: 600; }

.card-body { padding: 1.25rem; }

/* ===== STAT CARDS ===== */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s, transform 0.2s;
    height: 100%;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card .stat-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-card .stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-card .stat-change {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.icon-primary { background: var(--primary-light); color: var(--primary); }
.icon-success { background: #d1fae5; color: var(--success); }
.icon-warning { background: #fef3c7; color: var(--warning); }
.icon-danger { background: #fee2e2; color: var(--danger); }
.icon-info { background: #cffafe; color: var(--info); }
.icon-purple { background: #ede9fe; color: var(--purple); }

/* ===== BUTTONS ===== */
.btn {
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); color: #fff; box-shadow: 0 2px 8px rgba(37,99,235,0.3); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; color: #fff; }

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; color: #fff; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }

.btn-outline-primary {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
}
.btn-outline-primary:hover { background: var(--primary); color: #fff; }

.btn-outline-secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.btn-outline-secondary:hover { background: var(--border-light); color: var(--text); }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.78rem; }

/* ===== BADGES ===== */
.badge {
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.badge::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge.bg-primary { background: var(--primary-light) !important; color: var(--primary) !important; }
.badge.bg-success { background: #d1fae5 !important; color: var(--success) !important; }
.badge.bg-warning { background: #fef3c7 !important; color: var(--warning) !important; }
.badge.bg-danger { background: #fee2e2 !important; color: var(--danger) !important; }
.badge.bg-info { background: #cffafe !important; color: var(--info) !important; }
.badge.bg-secondary { background: #e2e8f0 !important; color: var(--text-muted) !important; }

/* ===== TABLES ===== */
.table {
    width: 100%;
    margin-bottom: 0;
    color: var(--text);
}

.table thead th {
    background: var(--border-light);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table tbody td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.table tbody tr:hover { background: var(--border-light); }

.table tbody tr:last-child td { border-bottom: none; }

/* ===== FORMS ===== */
.form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text);
    margin-bottom: 0.4rem;
}

.form-control, .form-select {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
    outline: none;
}

.input-group-text {
    background: var(--border-light);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

/* ===== ALERTS ===== */
.alert {
    border: none;
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.alert-success { background: #d1fae5; color: #065f46; }
.alert-danger { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info { background: #cffafe; color: #155e75; }

/* ===== PROGRESS ===== */
.progress {
    height: 8px;
    border-radius: 20px;
    background: var(--border-light);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    border-radius: 20px;
    transition: width 0.3s;
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

/* ===== LEAFLET OVERRIDE ===== */
.leaflet-container {
    border-radius: var(--radius);
    z-index: 1;
}

/* ===== MISC ===== */
.text-muted { color: var(--text-muted) !important; }
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }

.bg-primary { background-color: var(--primary) !important; }
.bg-light { background-color: var(--border-light) !important; }

.border { border-color: var(--border) !important; }

.cursor-pointer { cursor: pointer; }

/* ===== RESPONSIVE ===== */
@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1050;
        transition: transform 0.25s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    }
    .sidebar.open { transform: translateX(0); }
    .main-area { margin-left: 0; }
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 1040;
    }
    .sidebar-overlay.show { display: block; }
}

/* ===== SCROLLBAR ===== */
.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

/* ===== SIGNATURE PAD ===== */
.signature-pad {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: #fafafa;
    cursor: crosshair;
    touch-action: none;
}
