/* ============================================================
   Food Voucher Platform — Main Stylesheet
   ============================================================ */

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

:root {
    --primary: #1e5c3a;
    --primary-light: #2d7a52;
    --accent: #e85d2f;
    --accent-hover: #cf4f24;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #e2e5ea;
    --text: #1a1d23;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --green-badge-bg: #ecfdf5;
    --green-badge-text: #1e5c3a;
    --orange-badge-bg: #fff7ed;
    --orange-badge-text: #c2410c;
    --blue-badge-bg: #eff6ff;
    --blue-badge-text: #1d4ed8;
    --yellow-badge-bg: #fffbeb;
    --yellow-badge-text: #92400e;
    --sidebar-width: 240px;
    --header-height: 64px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ── Layout ─────────────────────────────────────────────── */

.layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    background: var(--primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-logo .brand {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo .brand-icon {
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.sidebar-nav {
    padding: 16px 0;
    flex: 1;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(255,255,255,.45);
    padding: 12px 20px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: rgba(255,255,255,.75);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, color .15s;
    border-radius: 0;
}

.nav-item:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
}

.nav-item.active {
    background: rgba(255,255,255,.15);
    color: #fff;
}

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

.nav-item.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.1);
    color: rgba(255,255,255,.6);
    font-size: 13px;
}

/* ── Main content ────────────────────────────────────────── */

.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

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

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    min-width: 220px;
}

.topbar-search input {
    border: none;
    background: transparent;
    outline: none;
    font-size: 13px;
    color: var(--text);
    width: 100%;
}

.topbar-search input::placeholder {
    color: var(--text-muted);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.topbar-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: background .15s;
}

.topbar-icon-btn:hover {
    background: var(--bg);
}

/* ── Page content ────────────────────────────────────────── */

.page-content {
    padding: 28px;
    flex: 1;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: background .15s, box-shadow .15s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-md);
}

.btn-outline {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: var(--bg);
}

/* ── Stat cards ──────────────────────────────────────────── */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.stat-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.1;
}

.stat-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.stat-meta .up {
    color: #16a34a;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 2px;
}

.stat-link {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 28px;
    height: 28px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    transition: background .15s;
}

.stat-link:hover {
    background: var(--bg);
}

/* ── Chart panel ─────────────────────────────────────────── */

.chart-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 32px;
    align-items: start;
}

.chart-header {
    margin-bottom: 16px;
}

.chart-value {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: #16a34a;
    background: #ecfdf5;
    border-radius: 20px;
    padding: 2px 8px;
}

.chart-date-range {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.chart-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg);
    border-radius: 8px;
    padding: 3px;
}

.chart-toggle-btn {
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    background: transparent;
    transition: background .15s, color .15s;
}

.chart-toggle-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.chart-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.chart-wrap {
    position: relative;
    height: 240px;
}

/* Donut chart side */
.donut-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding-top: 12px;
}

.donut-canvas-wrap {
    position: relative;
    width: 140px;
    height: 140px;
}

.donut-center-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.donut-legend {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.donut-legend li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── Table ───────────────────────────────────────────────── */

.table-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    padding: 12px 20px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

thead th .sort-icon {
    display: inline-flex;
    flex-direction: column;
    gap: 1px;
    vertical-align: middle;
    margin-left: 4px;
    color: var(--text-light);
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background .1s;
}

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

tbody tr:hover {
    background: var(--bg);
}

tbody td {
    padding: 14px 20px;
    font-size: 14px;
    color: var(--text);
}

.org-name {
    font-weight: 500;
}

/* ── Badges ──────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge-blue {
    background: var(--blue-badge-bg);
    color: var(--blue-badge-text);
}

.badge-yellow {
    background: var(--yellow-badge-bg);
    color: var(--yellow-badge-text);
}

.badge-green {
    background: var(--green-badge-bg);
    color: var(--green-badge-text);
}

.badge-orange {
    background: var(--orange-badge-bg);
    color: var(--orange-badge-text);
}

/* ── Action icon ─────────────────────────────────────────── */

.action-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 4px;
    transition: color .15s, background .15s;
}

.action-btn:hover {
    color: var(--text);
    background: var(--bg);
}

/* ── Messages / alerts ───────────────────────────────────── */

.messages {
    list-style: none;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
}

.message.success { background: #ecfdf5; color: #166534; border: 1px solid #bbf7d0; }
.message.error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.message.warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.message.info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 1024px) {
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .chart-panel {
        grid-template-columns: 1fr;
    }

    .donut-wrap {
        flex-direction: row;
        align-items: center;
        padding-top: 0;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s;
    }

    .sidebar.open {
        transform: translateX(0);
        width: 240px;
    }

    .main {
        margin-left: 0;
    }

    .stat-grid {
        grid-template-columns: 1fr;
    }

    .page-content {
        padding: 16px;
    }
}
