/* =============================================
   SAMITICLOUD APP — WHITE SIDEBAR UI
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* Auto-style all Django form widgets */
input[type="text"], input[type="number"], input[type="password"],
input[type="email"], input[type="tel"], input[type="date"],
select, textarea {
    padding: 0.7rem 0.9rem;
    border-radius: 8px;
    border: 1.5px solid #e8edf3;
    background: #fff;
    color: #0f172a;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    width: 100%;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

input[type="text"]:focus, input[type="number"]:focus, input[type="password"]:focus,
input[type="email"]:focus, input[type="tel"]:focus, input[type="date"]:focus,
select:focus, textarea:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

input[type="checkbox"] {
    width: 18px; height: 18px; cursor: pointer; accent-color: #4f46e5;
}

textarea { resize: vertical; min-height: 100px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; background-size: 16px; padding-right: 2.5rem; }


:root {
    --sidebar-w: 260px;
    --topbar-h: 60px;

    /* Colors */
    --white: #ffffff;
    --bg: #f5f7fb;
    --bg-card: #ffffff;
    --border: #e8edf3;
    --border-light: #f0f4f8;

    --text-1: #0f172a;
    --text-2: #475569;
    --text-3: #94a3b8;

    --primary: #4f46e5;
    --primary-light: rgba(79,70,229,0.08);
    --primary-hover: #4338ca;

    --success: #059669;
    --success-light: rgba(5,150,105,0.08);
    --warning: #d97706;
    --warning-light: rgba(217,119,6,0.08);
    --danger: #dc2626;
    --danger-light: rgba(220,38,38,0.08);
    --info: #0ea5e9;
    --info-light: rgba(14,165,233,0.08);

    --sidebar-bg: #1e1b4b;
    --sidebar-hover: rgba(255,255,255,0.07);
    --sidebar-active: rgba(255,255,255,0.12);
    --sidebar-text: rgba(255,255,255,0.75);
    --sidebar-text-active: #fff;
    --sidebar-border: rgba(255,255,255,0.08);

    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body.app-body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text-1);
    display: flex;
    min-height: 100vh;
    font-size: 0.925rem;
    -webkit-font-smoothing: antialiased;
}

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

/* ============ SIDEBAR ============ */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    height: 100vh;
    position: fixed;
    left: 0; top: 0;
    display: flex;
    flex-direction: column;
    z-index: 200;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    transition: transform 0.3s ease;
}

.sidebar::-webkit-scrollbar { display: none; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--sidebar-border);
    min-height: var(--topbar-h);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--sidebar-text-active);
    font-size: 1.05rem;
    text-decoration: none;
}

.sidebar-brand:hover { color: var(--sidebar-text-active); }

.sidebar-brand-icon {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 1rem; color: #fff;
    flex-shrink: 0;
}

.sidebar-brand span { font-weight: 400; letter-spacing: -0.3px; }
.sidebar-brand strong { font-weight: 700; }

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 4px;
}

.sidebar-close svg { width: 20px; height: 20px; }

/* Samiti Info Strip */
.sidebar-samiti-info {
    padding: 0.85rem 1.25rem;
    background: rgba(255,255,255,0.05);
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-samiti-name {
    font-weight: 600;
    color: var(--sidebar-text-active);
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-role-badges { display: flex; flex-wrap: wrap; gap: 4px; }

/* Nav */
.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-section-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--sidebar-text);
    opacity: 0.5;
    padding: 0.75rem 0.5rem 0.25rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.85rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-decoration: none;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}

.nav-item.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text-active);
    font-weight: 600;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-user { display: flex; align-items: center; gap: 0.6rem; flex: 1; min-width: 0; }

.sidebar-user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; font-weight: 700; color: #fff;
    flex-shrink: 0;
}

.sidebar-user-info { min-width: 0; }
.sidebar-user-name { font-size: 0.82rem; font-weight: 600; color: var(--sidebar-text-active); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-phone { font-size: 0.72rem; color: var(--sidebar-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-logout-btn {
    background: none; border: none; cursor: pointer;
    color: var(--sidebar-text); padding: 6px; border-radius: 6px;
    transition: all 0.2s ease;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.sidebar-logout-btn svg { width: 18px; height: 18px; }
.sidebar-logout-btn:hover { background: rgba(239,68,68,0.15); color: #f87171; }

/* Overlay */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 190;
    background: rgba(0,0,0,0.5);
}

/* ============ MAIN AREA ============ */
.app-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}

/* Top Bar */
.app-topbar {
    height: var(--topbar-h);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.75rem;
    position: sticky; top: 0; z-index: 100;
    box-shadow: var(--shadow-sm);
}

.topbar-hamburger {
    display: none;
    background: none; border: none; cursor: pointer; padding: 4px;
    color: var(--text-2);
}
.topbar-hamburger svg { width: 22px; height: 22px; }

.topbar-breadcrumb {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-1);
    flex: 1;
}

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

.topbar-code-badge {
    display: flex; align-items: center; gap: 0.4rem;
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    font-size: 0.8rem;
}

/* Page Content */
.app-content { padding: 1.75rem; flex: 1; }

/* Messages */
.app-messages { padding: 1rem 1.75rem 0; }

.app-alert {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem; font-weight: 500;
    margin-bottom: 0.75rem;
}

.app-alert-success { background: var(--success-light); color: var(--success); border: 1px solid rgba(5,150,105,0.2); }
.app-alert-error, .app-alert-danger { background: var(--danger-light); color: var(--danger); border: 1px solid rgba(220,38,38,0.2); }
.app-alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid rgba(217,119,6,0.2); }
.app-alert-info { background: var(--info-light); color: var(--info); border: 1px solid rgba(14,165,233,0.2); }

.app-alert-close { background: none; border: none; cursor: pointer; font-size: 1.25rem; color: inherit; opacity: 0.7; padding: 0 0 0 1rem; }
.app-alert-close:hover { opacity: 1; }

/* ============ ROLE PILLS ============ */
.role-pill {
    font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
    padding: 0.2rem 0.5rem; border-radius: 9999px;
}
.role-pill.admin { background: rgba(239,68,68,0.2); color: #fca5a5; }
.role-pill.collector { background: rgba(59,130,246,0.2); color: #93c5fd; }
.role-pill.approver { background: rgba(16,185,129,0.2); color: #6ee7b7; }
.role-pill.member { background: rgba(148,163,184,0.2); color: #cbd5e1; }

/* ============ CARDS ============ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

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

.card-title {
    font-size: 0.95rem; font-weight: 700; color: var(--text-1);
}

.card-body { padding: 1.5rem; }

/* ============ KPI STAT CARDS ============ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.4rem 1.5rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.25s;
}

.kpi-card:hover { box-shadow: var(--shadow); }

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--kpi-color, var(--primary));
}

.kpi-icon {
    width: 40px; height: 40px;
    border-radius: var(--radius-sm);
    background: var(--kpi-bg, var(--primary-light));
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 1rem;
}

.kpi-icon svg { width: 20px; height: 20px; color: var(--kpi-color, var(--primary)); }

.kpi-value {
    font-size: 1.85rem; font-weight: 800; color: var(--text-1); line-height: 1;
    margin-bottom: 0.35rem; font-variant-numeric: tabular-nums;
}

.kpi-label { font-size: 0.8rem; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; }

.kpi-trend {
    margin-top: 0.6rem; font-size: 0.8rem; font-weight: 600;
    display: flex; align-items: center; gap: 0.3rem;
}

.kpi-trend.up { color: var(--success); }
.kpi-trend.down { color: var(--danger); }
.kpi-trend.neutral { color: var(--text-3); }

/* ============ PAGE HEADER ============ */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.75rem;
    flex-wrap: wrap; gap: 0.75rem;
}

.page-title { font-size: 1.5rem; font-weight: 800; color: var(--text-1); }
.page-subtitle { font-size: 0.875rem; color: var(--text-3); margin-top: 0.2rem; font-weight: 400; }

/* ============ BUTTONS ============ */
.btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem; font-weight: 600;
    cursor: pointer; border: none;
    transition: all 0.2s ease;
    white-space: nowrap;
    text-decoration: none;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}
.btn-primary:hover { background: var(--primary-hover); color: #fff; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(79,70,229,0.4); }

.btn-success {
    background: var(--success);
    color: #fff;
    box-shadow: 0 2px 8px rgba(5,150,105,0.3);
}
.btn-success:hover { background: #047857; color: #fff; transform: translateY(-1px); }

.btn-danger {
    background: var(--danger);
    color: #fff;
    box-shadow: 0 2px 8px rgba(220,38,38,0.3);
}
.btn-danger:hover { background: #b91c1c; color: #fff; transform: translateY(-1px); }

.btn-outline {
    background: transparent;
    color: var(--text-2);
    border: 1.5px solid var(--border);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-ghost {
    background: transparent; color: var(--text-3);
    border: none;
}
.btn-ghost:hover { color: var(--primary); background: var(--primary-light); }

.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.8rem; }
.btn-lg { padding: 0.85rem 1.75rem; font-size: 1rem; }

/* ============ TABLES ============ */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

table.data-table {
    width: 100%; border-collapse: collapse;
    background: var(--bg-card);
    font-size: 0.875rem;
}

table.data-table th {
    background: var(--bg); color: var(--text-3);
    font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.8px;
    padding: 0.85rem 1.25rem; text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.data-table td {
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-1); vertical-align: middle;
}

table.data-table tr:last-child td { border-bottom: none; }
table.data-table tbody tr { transition: background 0.15s; }
table.data-table tbody tr:hover { background: var(--bg); }

/* ============ BADGES ============ */
.badge {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.25rem 0.65rem; border-radius: 9999px;
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.3px;
    white-space: nowrap;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-pending { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-gray { background: rgba(148,163,184,0.1); color: var(--text-3); }

.badge-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: currentColor;
    display: inline-block;
}

/* ============ FORMS ============ */
.form-grid { display: grid; gap: 1.25rem; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }

.form-group { display: flex; flex-direction: column; gap: 0.4rem; }

.form-label {
    font-size: 0.82rem; font-weight: 600; color: var(--text-2);
}

.form-control {
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--white);
    color: var(--text-1);
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    width: 100%;
    transition: all 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.form-control::placeholder { color: var(--text-3); }
.form-hint { font-size: 0.78rem; color: var(--text-3); }
.form-error { font-size: 0.78rem; color: var(--danger); }

/* ============ CHART ============ */
.chart-container { position: relative; height: 260px; width: 100%; }

/* ============ EMPTY STATE ============ */
.empty-state {
    text-align: center; padding: 4rem 2rem;
    display: flex; flex-direction: column; align-items: center; gap: 1rem;
}

.empty-state-icon {
    width: 64px; height: 64px;
    background: var(--bg);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-3);
}

.empty-state-icon svg { width: 32px; height: 32px; }
.empty-state h3 { font-size: 1.1rem; font-weight: 700; color: var(--text-1); }
.empty-state p { font-size: 0.9rem; color: var(--text-3); max-width: 400px; line-height: 1.6; }

/* ============ SECTION TABS ============ */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; }

.tab-link {
    padding: 0.75rem 1.25rem; font-size: 0.875rem; font-weight: 600;
    color: var(--text-3); border: none; background: none; cursor: pointer;
    border-bottom: 2px solid transparent; margin-bottom: -2px;
    transition: all 0.2s; text-decoration: none; display: inline-block;
}

.tab-link:hover { color: var(--text-1); }
.tab-link.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ============ AVATAR ============ */
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; font-weight: 700; color: #fff;
    flex-shrink: 0;
}

/* ============ STATS ROW ============ */
.stats-inline {
    display: flex; gap: 1.5rem; flex-wrap: wrap;
}

.stat-pill {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.82rem; color: var(--text-2);
}

.stat-pill strong { color: var(--text-1); font-weight: 700; }

/* ============ COLLECTOR FILTER BAR ============ */
.filter-bar {
    display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.filter-btn {
    padding: 0.4rem 0.9rem; border-radius: 9999px;
    font-size: 0.8rem; font-weight: 600; border: 1.5px solid var(--border);
    background: transparent; color: var(--text-2); cursor: pointer; transition: all 0.2s;
}

.filter-btn:hover, .filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ============ COLLECTOR TIMER BADGE ============ */
.edit-timer {
    display: inline-flex; align-items: center; gap: 0.3rem;
    font-size: 0.72rem; color: var(--warning); font-weight: 600;
}

/* ============ ACTION GROUP ============ */
.action-group { display: flex; gap: 0.5rem; align-items: center; }

/* ============ SECTION HEADER ============ */
.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.25rem;
}

.section-title { font-size: 1rem; font-weight: 700; color: var(--text-1); }

/* ============ CHECKBOX LIST ============ */
.checkbox-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}

.checkbox-list li {
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.checkbox-list li:last-child {
    border-bottom: none;
}

.checkbox-list li:hover {
    background: var(--bg-hover);
}

.checkbox-list label {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-2);
    margin: 0;
    user-select: none;
}

.checkbox-list input[type="checkbox"] {
    margin: 0;
    margin-right: 0.75rem;
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary);
    cursor: pointer;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay.active { display: block; }
    .sidebar-close { display: flex; }
    .app-main { margin-left: 0; }
    .topbar-hamburger { display: block; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid-2 { grid-template-columns: 1fr; }
    .app-content { padding: 1.25rem; }
}

@media (max-width: 500px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; }
}

/* ============ UTILITIES ============ */
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-muted { color: var(--text-3) !important; }
.text-primary { color: var(--primary) !important; }
.fw-bold { font-weight: 700 !important; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: 0.5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.font-mono { font-family: 'Courier New', monospace; }
.w-full { width: 100%; }
