/* ═══════════════════════════════════════════════════════════
   Karthikeya Cot  –  Admin Dashboard CSS
   ═══════════════════════════════════════════════════════════ */

:root {
    --primary:      #1e3a5f;
    --primary-light:#2a527f;
    --accent:       #f0c040;
    --success:      #27ae60;
    --warning:      #f39c12;
    --danger:       #e74c3c;
    --info:         #2980b9;
    --bg:           #f0f2f5;
    --card-bg:      #ffffff;
    --sidebar-w:    250px;
    --header-h:     60px;
    --text:         #2c3e50;
    --text-muted:   #7f8c8d;
    --border:       #e0e4e8;
    --shadow:       0 2px 12px rgba(0,0,0,.08);
    --radius:       10px;
}

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--primary);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform .3s ease;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px;
    background: rgba(0,0,0,.18);
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .brand-icon {
    width: 38px; height: 38px;
    background: var(--accent);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: var(--primary);
}
.sidebar-brand .brand-text { color: #fff; }
.sidebar-brand .brand-text .name { font-size: 14px; font-weight: 700; line-height: 1.1; }
.sidebar-brand .brand-text .subtitle { font-size: 10px; opacity: .7; }

.sidebar-nav { flex: 1; padding: 16px 0; }
.nav-section-label {
    font-size: 10px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 1px; color: rgba(255,255,255,.4);
    padding: 12px 20px 6px;
}
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 20px; color: rgba(255,255,255,.7);
    font-size: 14px; font-weight: 500;
    border-radius: 0; position: relative;
    transition: background .2s, color .2s;
}
.nav-link i { width: 18px; text-align: center; font-size: 15px; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active {
    background: rgba(255,255,255,.12);
    color: var(--accent);
    border-left: 3px solid var(--accent);
}
.nav-link .badge-pill {
    margin-left: auto;
    background: var(--danger);
    color: #fff; font-size: 10px;
    padding: 2px 7px; border-radius: 20px;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: 11px; color: rgba(255,255,255,.4);
    text-align: center;
}

/* ── Top Header ───────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0; left: var(--sidebar-w); right: 0;
    height: var(--header-h);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
    z-index: 900;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left .page-title { font-size: 17px; font-weight: 600; color: var(--text); }
.topbar-left .breadcrumb { font-size: 12px; color: var(--text-muted); margin: 0; }
.breadcrumb-item + .breadcrumb-item::before { content: "/"; padding: 0 6px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-right .btn-icon {
    width: 36px; height: 36px; border-radius: 50%;
    border: none; background: var(--bg); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 15px;
    transition: background .2s;
}
.topbar-right .btn-icon:hover { background: var(--border); color: var(--text); }
.month-selector { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.month-selector input[type="month"] {
    border: 1px solid var(--border); border-radius: 6px;
    padding: 5px 10px; font-size: 13px; color: var(--text);
    background: var(--bg); cursor: pointer;
}

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    padding-top: var(--header-h);
    min-height: 100vh;
}
.page-content { padding: 24px; }

/* ── Stat Cards ───────────────────────────────────────────── */
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow);
    display: flex; align-items: flex-start; justify-content: space-between;
    border-left: 4px solid transparent;
    transition: transform .2s, box-shadow .2s;
    height: 100%;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.12); }
.stat-card.income  { border-color: var(--success); }
.stat-card.pending { border-color: var(--warning); }
.stat-card.expense { border-color: var(--danger); }
.stat-card.balance { border-color: var(--info); }
.stat-card.residents { border-color: var(--primary); }
.stat-card.rooms    { border-color: #9b59b6; }

.stat-info .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.stat-info .value { font-size: 24px; font-weight: 700; margin: 4px 0; line-height: 1; }
.stat-info .sub   { font-size: 12px; color: var(--text-muted); }
.stat-icon {
    width: 48px; height: 48px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
}
.stat-card.income  .stat-icon { background: #d5f5e3; color: var(--success); }
.stat-card.pending .stat-icon { background: #fef9e7; color: var(--warning); }
.stat-card.expense .stat-icon { background: #fdedec; color: var(--danger); }
.stat-card.balance .stat-icon { background: #d6eaf8; color: var(--info); }
.stat-card.residents .stat-icon { background: #d6e4f0; color: var(--primary); }
.stat-card.rooms    .stat-icon { background: #e8daef; color: #9b59b6; }

/* ── Charts Card ──────────────────────────────────────────── */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: none;
}
.card-header-custom {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px 0; font-size: 15px; font-weight: 600;
}
.card-header-custom .sub { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.chart-container { padding: 12px 16px 16px; position: relative; }

/* ── Table ────────────────────────────────────────────────── */
.table-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.table-card .table-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.table-card .table-header h5 { margin: 0; font-size: 15px; font-weight: 600; }
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
    background: #f8f9fa; color: var(--text-muted);
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; padding: 10px 14px; border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

/* ── Badges ───────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success  { background: #d5f5e3; color: #1e8449; }
.badge-warning  { background: #fef9e7; color: #9c6a00; }
.badge-danger   { background: #fdedec; color: #c0392b; }
.badge-info     { background: #d6eaf8; color: #1a5276; }
.badge-secondary{ background: #eaeded; color: #566573; }
.badge-primary  { background: #d6e4f0; color: #1e3a5f; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: 7px; font-size: 13.5px;
    font-weight: 500; border: none; cursor: pointer;
    transition: all .2s; outline: none;
}
.btn-primary   { background: var(--primary);   color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-success   { background: var(--success);   color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger    { background: var(--danger);    color: #fff; }
.btn-danger:hover  { filter: brightness(1.1); }
.btn-warning   { background: var(--warning);   color: #fff; }
.btn-outline   { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon-sm {
    width: 30px; height: 30px; padding: 0;
    border-radius: 6px; display: inline-flex;
    align-items: center; justify-content: center;
    font-size: 13px;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 2000;
    display: none; align-items: center; justify-content: center;
    padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal-box {
    background: var(--card-bg);
    border-radius: 12px;
    width: 100%; max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    animation: modalIn .25s ease;
}
@keyframes modalIn { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 16px; font-weight: 600;
}
.modal-body  { padding: 20px; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 10px;
}
.btn-close {
    width: 30px; height: 30px; border-radius: 50%;
    border: none; background: var(--bg);
    cursor: pointer; font-size: 16px; color: var(--text-muted);
}
.btn-close:hover { background: var(--border); color: var(--text); }

/* ── Form Controls ────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { font-size: 12.5px; font-weight: 600; color: var(--text); margin-bottom: 5px; display: block; }
.form-control {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: 7px;
    font-size: 13.5px; color: var(--text); background: var(--card-bg);
    transition: border .2s, box-shadow .2s;
}
.form-control:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30,58,95,.1);
}
select.form-control { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ── Toast notification ───────────────────────────────────── */
.toast-container { position: fixed; top: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--card-bg);
    border-radius: 8px; padding: 12px 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
    display: flex; align-items: center; gap: 10px;
    font-size: 13.5px; min-width: 260px;
    animation: toastIn .3s ease;
    border-left: 4px solid var(--success);
}
.toast.error  { border-color: var(--danger);  }
.toast.warning{ border-color: var(--warning); }
@keyframes toastIn  { from { transform: translateX(20px); opacity: 0; } }

/* ── Utility ──────────────────────────────────────────────── */
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger)  !important; }
.text-warning { color: var(--warning) !important; }
.text-muted   { color: var(--text-muted) !important; }
.fw-bold   { font-weight: 700; }
.fw-medium { font-weight: 500; }
.fs-sm     { font-size: 12px; }
.mt-4      { margin-top: 24px; }
.mb-4      { margin-bottom: 24px; }
.gap-2     { gap: 8px; }
.d-flex    { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

/* ── Progress bar ─────────────────────────────────────────── */
.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 3px; background: var(--success); transition: width .4s; }

/* ── Search / Filter bar ──────────────────────────────────── */
.filter-bar {
    display: flex; flex-wrap: wrap; gap: 10px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: #fafbfd;
}
.filter-bar .form-control { max-width: 200px; }
.search-input { position: relative; }
.search-input i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-input input { padding-left: 32px; }

/* ── Responsive ───────────────────────────────────────────── */
.hamburger { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text); }

/* ── Tablet (≤ 992px) ─────────────────── */
@media (max-width: 992px) {
    :root { --sidebar-w: 220px; }
    .stat-card .value { font-size: 22px; }
    .page-content { padding: 18px; }
}

/* ── Mobile (≤ 768px) ─────────────────────────────────────── */
@media (max-width: 768px) {
    :root { --sidebar-w: 260px; }

    /* Sidebar slides off-canvas */
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .topbar { left: 0; padding: 0 14px; }
    .topbar-left .breadcrumb { display: none; }
    .hamburger { display: block; }

    /* Page content */
    .page-content { padding: 12px; }

    /* Stats grid: 2 columns on mobile */
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }
    .stat-card { padding: 14px; }
    .stat-card .value { font-size: 18px; }
    .stat-card .label { font-size: 11px; }
    .stat-icon { width: 38px; height: 38px; font-size: 16px; }

    /* Forms */
    .form-row, .form-row-3 { grid-template-columns: 1fr; gap: 10px; }

    /* Filter bar: vertical stack */
    .filter-bar { gap: 8px; padding: 10px 12px; }
    .filter-bar .form-control { max-width: 100%; width: 100%; }
    .filter-bar .search-input { width: 100%; }
    .filter-bar .search-input input { width: 100%; }
    .filter-bar .btn { width: 100%; justify-content: center; }

    /* Table: horizontal scroll wrapper */
    .table-responsive { -webkit-overflow-scrolling: touch; }
    table { font-size: 12.5px; }
    thead th { padding: 8px 10px; font-size: 10px; }
    tbody td { padding: 9px 10px; }

    /* Hide less-important table columns on very small screens */
    .col-hide-mobile { display: none !important; }

    /* Table action buttons in cells */
    .btn-icon-sm { width: 26px; height: 26px; font-size: 11px; }

    /* Page header */
    .page-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }
    .page-header .btn { width: 100%; justify-content: center; }
    .table-card .table-header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px;
    }
    .table-card .table-header .btn { font-size: 12px; padding: 6px 12px; }

    /* Cards */
    .card-header-custom { flex-wrap: wrap; gap: 8px; padding: 12px 14px 0; }

    /* Modal: near-fullscreen on mobile */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal-box {
        max-width: 100%;
        max-height: 95vh;
        border-radius: 16px 16px 0 0;
    }

    /* Charts */
    .chart-container canvas { max-height: 220px !important; }

    /* Toast: show at bottom on mobile */
    .toast-container { top: auto; bottom: 80px; right: 12px; left: 12px; }
    .toast { min-width: unset; width: 100%; font-size: 13px; }

    /* Food-cost big metric */
    .big-metric .metric-value { font-size: 30px; }

    /* Topbar: shrink Add button on mobile */
    .topbar-right .btn { font-size: 12px; padding: 6px 10px; }
    .topbar-right .btn i + * { display: none; }

    /* KPIs: make value smaller */
    .stat-card .sub { font-size: 11px; }
}

/* ── Extra-small (≤ 480px) ────────────────────────────────── */
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr !important; }
    .stat-card { padding: 12px 14px; }
    .page-content { padding: 8px; }
    .table-card .table-header { padding: 10px; }
    .modal-footer { flex-direction: column; }
    .modal-footer .btn { width: 100%; justify-content: center; }
}

/* ── Collapse 2-col inline grids on mobile ──────────────────
   CSS attribute selectors override the inline style="..." grids.
   Works because !important beats inline specificity.            */
@media (max-width: 768px) {
    .page-content [style*="grid-template-columns:1fr 1fr"],
    .page-content [style*="grid-template-columns: 1fr 1fr"],
    .page-content [style*="grid-template-columns:2fr 1fr"],
    .page-content [style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    /* Tighten auto-fill grids so cards fit 2-per-row on small phones */
    .page-content [style*="minmax(200px"],
    .page-content [style*="minmax(180px"],
    .page-content [style*="minmax(170px"],
    .page-content [style*="minmax(160px"] {
        grid-template-columns: repeat(auto-fill, minmax(140px,1fr)) !important;
    }
}

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 48px 20px; color: var(--text-muted);
}
.empty-state i { font-size: 48px; opacity: .3; margin-bottom: 12px; display: block; }
.empty-state p { margin: 0; font-size: 14px; }

/* ── Amount colors ────────────────────────────────────────── */
.amount-positive { color: var(--success); font-weight: 600; }
.amount-negative { color: var(--danger);  font-weight: 600; }
.amount-neutral  { color: var(--text);    font-weight: 600; }

/* ── Resident photo thumbnail ─────────────────────────────── */
.resident-thumb {
    display: flex; align-items: center; gap: 10px;
}
.resident-thumb .name  { font-weight: 500; }
.resident-thumb .phone { font-size: 12px; color: var(--text-muted); }

/* ── Food cost page ───────────────────────────────────────── */
.big-metric {
    text-align: center; padding: 24px;
}
.big-metric .metric-label { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.big-metric .metric-value { font-size: 42px; font-weight: 700; color: var(--primary); line-height: 1.1; }
.big-metric .metric-sub   { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c5cdd5; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a0aab2; }

/* ── Sidebar overlay for mobile ───────────────────────────── */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.4); z-index: 999;
}
.sidebar-overlay.show { display: block; }
