:root {
    --primary: #6bbf2d;
    --primary-dark: #53991f;
    --primary-soft: #eef8e4;
    --success: #059669;
    --success-soft: #d1fae5;
    --warning: #b45309;
    --warning-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --info: #0369a1;
    --info-soft: #e0f2fe;
    --muted: #6b7280;
    --muted-soft: #f3f4f6;
    --border: #e5e7eb;
    --bg: #f4f5f3;
    --text: #111827;
    --sidebar: #111111;
    --sidebar-text: #a3a3a3;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.nowrap { white-space: nowrap; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }

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

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-text);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    padding: 1rem .75rem 2rem;
}

.brand { display: flex; align-items: center; gap: .6rem; color: #fff; padding: .25rem .5rem 1.25rem; }
.brand:hover { text-decoration: none; }
.brand-logo { display: block; width: 100%; max-width: 200px; height: auto; border-radius: 8px; background: #fff; }
.brand-login { justify-content: center; padding: 0 0 1rem; }
.brand-login .brand-logo { max-width: 260px; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 9px;
    background: linear-gradient(135deg, #6bbf2d, #111);
    display: grid; place-items: center; font-weight: 800; color: #fff;
}
.brand-name { font-weight: 700; font-size: 1rem; }

.nav-group {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
    color: #6b7280; margin: 1rem .5rem .35rem;
}
.nav-link {
    display: block; color: var(--sidebar-text); padding: .5rem .75rem;
    border-radius: 7px; margin-bottom: 2px; font-weight: 500;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; gap: 1rem;
    background: #fff; border-bottom: 1px solid var(--border);
    padding: .65rem 1.5rem; position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-weight: 600; font-size: 1rem; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: .75rem; }
.user-chip { display: flex; align-items: center; gap: .5rem; color: var(--text); }
.user-chip:hover { text-decoration: none; }
.avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft);
    color: var(--primary); display: grid; place-items: center; font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta small { color: var(--muted); }
.menu-toggle { display: none; background: none; border: 0; font-size: 1.4rem; cursor: pointer; }

.content { padding: 1.5rem; flex: 1; }
.footer { padding: 1rem 1.5rem; color: var(--muted); font-size: .8rem; }

/* Page header ------------------------------------------------------------ */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: .75rem; margin-bottom: 1.25rem;
}
.page-header h1 { margin: 0; }
.page-header .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Cards ------------------------------------------------------------------ */
.card {
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .9rem 1.1rem; border-bottom: 1px solid var(--border);
}
.card-header h2 { margin: 0; font-size: 1rem; }
.card-body { padding: 1.1rem; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-sidebar { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat {
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem 1.1rem; box-shadow: var(--shadow); border-left: 4px solid var(--primary);
}
.stat.success { border-left-color: var(--success); }
.stat.warning { border-left-color: #f59e0b; }
.stat.danger { border-left-color: var(--danger); }
.stat-link { display: block; color: inherit; cursor: pointer; transition: box-shadow .15s, transform .15s; }
.stat-link:hover { text-decoration: none; box-shadow: 0 0 0 2px var(--danger-soft), var(--shadow); }
#pending-dues { scroll-margin-top: 4.5rem; }
.dues-pending { color: var(--danger); font-weight: 700; }
.dues-pending:hover { color: var(--danger); text-decoration: underline; }
.dues-pending small { font-weight: 600; }
.dues-cleared { color: var(--success); font-weight: 700; }
.stat.info { border-left-color: #0ea5e9; }
.stat-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.6rem; font-weight: 700; margin-top: .2rem; }
.stat-sub { color: var(--muted); font-size: .8rem; }

/* Tables ----------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .65rem .9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { background: #f9fafb; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.table tbody tr:hover { background: #fafafa; }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions > * { margin-left: .25rem; }
.table tfoot td { font-weight: 700; background: #f9fafb; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

.detail-list { display: grid; grid-template-columns: minmax(6rem, max-content) minmax(0, 1fr); gap: .5rem 1rem; margin: 0; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.detail-list-stacked { grid-template-columns: minmax(0, 1fr); gap: 0; }
.detail-list-stacked dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.detail-list-stacked dd { padding-bottom: .6rem; margin-bottom: .6rem; border-bottom: 1px solid var(--border); }
.detail-list-stacked dd:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }

/* Forms ------------------------------------------------------------------ */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.25rem; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .85rem; }
.req { color: var(--danger); }
.form-control {
    width: 100%; padding: .55rem .7rem; border: 1px solid #d1d5db; border-radius: 7px;
    font: inherit; background: #fff; color: var(--text); transition: border-color .15s, box-shadow .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
.form-control.is-invalid { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .8rem; margin-top: .25rem; }
.form-hint { color: var(--muted); font-size: .8rem; margin-top: .25rem; }
.form-actions { display: flex; gap: .5rem; padding-top: .5rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1rem 0; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0 .4rem; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; padding: 1rem 1.1rem; border-bottom: 1px solid var(--border); }
.filters .form-control { width: auto; min-width: 150px; }
.filters .grow { flex: 1; min-width: 200px; }
.filters label { display: block; font-size: .75rem; color: var(--muted); margin-bottom: .2rem; }

.inline-form { display: inline; }

.pagination-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; padding: .75rem 1.1rem; }
.pagination { display: flex; gap: .25rem; }
.page-link { padding: .3rem .65rem; border: 1px solid var(--border); border-radius: 6px; color: var(--text); background: #fff; }
.page-link:hover { text-decoration: none; background: var(--muted-soft); }
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Buttons ---------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    padding: .55rem 1rem; border-radius: 7px; border: 1px solid transparent;
    font: inherit; font-weight: 600; cursor: pointer; line-height: 1.2;
    background: var(--muted-soft); color: var(--text); white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); filter: none; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-light { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline { background: #fff; border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-block { width: 100%; }

/* Badges & alerts -------------------------------------------------------- */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-muted { background: var(--muted-soft); color: var(--muted); }

.alert { padding: .8rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; transition: opacity .4s; }
.alert.fade { opacity: 0; }
.alert-success { background: var(--success-soft); color: #065f46; border-color: #a7f3d0; }
.alert-error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--warning-soft); color: #92400e; border-color: #fde68a; }
.alert-info { background: var(--info-soft); color: #075985; border-color: #bae6fd; }

/* Bar chart -------------------------------------------------------------- */
.bar-chart { display: flex; align-items: flex-end; gap: 1rem; height: 220px; padding: 1rem .5rem 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.bar { width: 100%; max-width: 56px; background: linear-gradient(180deg, #818cf8, var(--primary)); border-radius: 6px 6px 0 0; min-height: 2px; }
.bar-value { font-size: .7rem; color: var(--muted); margin-bottom: .25rem; white-space: nowrap; }
.bar-label { font-size: .75rem; color: var(--muted); margin-top: .4rem; }

.progress { background: var(--muted-soft); border-radius: 999px; height: 8px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); }

/* Timetable -------------------------------------------------------------- */
.timetable { display: grid; grid-template-columns: repeat(7, minmax(140px, 1fr)); gap: .75rem; overflow-x: auto; }
.tt-day h3 { font-size: .8rem; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; margin-bottom: .5rem; }
.tt-day.today h3 { color: var(--primary); }
.tt-item { background: var(--primary-soft); border-left: 3px solid var(--primary); border-radius: 6px; padding: .5rem .6rem; margin-bottom: .5rem; font-size: .8rem; }
.tt-item strong { display: block; font-size: .85rem; }
.tt-item.inactive { opacity: .5; }

/* Auth ------------------------------------------------------------------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0a0a0a, #1a1a1a 45%, #2f5a12); padding: 1rem; }
.attendance-grid { font-size: .8rem; }
.attendance-grid th, .attendance-grid td { padding: .35rem .2rem; text-align: center; }
.attendance-grid .sticky-col { position: sticky; left: 0; background: #fff; text-align: left; min-width: 140px; z-index: 1; padding-left: .75rem; }
.attendance-grid thead .sticky-col { background: #f9fafb; z-index: 2; }
.attendance-grid .day-col { min-width: 28px; }
.attendance-grid .today { background: #f0fdf4; }
.attendance-grid .present { color: var(--success); font-weight: 700; }
.attendance-grid .absent { color: var(--danger); font-weight: 700; }
.attendance-grid .att-tick { color: var(--success); font-weight: 700; }
.attendance-grid .att-x { color: var(--danger); font-weight: 700; }
.attendance-grid .count-present { color: var(--success); font-weight: 700; min-width: 4rem; }
.attendance-grid .count-absent { color: var(--danger); font-weight: 700; min-width: 4rem; }
.btn-att { border: 0; background: transparent; cursor: pointer; width: 100%; padding: .15rem; border-radius: 4px; font: inherit; color: inherit; }
.btn-att.on { color: var(--success); font-weight: 700; }
.btn-att.off { color: var(--danger); font-weight: 700; }
.btn-att:hover { background: var(--primary-soft); }
.pay-inline { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; justify-content: flex-end; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 14px; padding: 2rem; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.auth-card .brand { color: var(--text); padding: 0 0 1.25rem; justify-content: center; }
.auth-card h1 { font-size: 1.25rem; text-align: center; }
.auth-card p.muted { text-align: center; margin-top: 0; }
.error-card { text-align: center; }
.error-code { font-size: 3.5rem; font-weight: 800; color: var(--primary); line-height: 1; margin-bottom: .5rem; }

/* Receipt ---------------------------------------------------------------- */
.receipt { max-width: 720px; margin: 2rem auto; background: #fff; padding: 2.5rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.receipt-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2px solid var(--text); padding-bottom: 1rem; margin-bottom: 1.25rem; }
.receipt-total { font-size: 1.5rem; font-weight: 800; }
.receipt-foot { margin-top: 2rem; text-align: center; color: var(--muted); }
.no-print { text-align: center; margin: 1rem; }
.btn-whatsapp { background: #25d366; color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.receipt-alert { max-width: 720px; margin: 0 auto 1rem; text-align: left; }
.receipt-hint { max-width: 720px; margin: .75rem auto 0; font-size: .85rem; }
.notify-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; align-items: start; margin-bottom: 1rem; }
.notify-grid .card { margin-bottom: 0; }
.notify-message textarea { font-family: inherit; line-height: 1.45; }
.wa-chat { background: #efeae2; border-radius: 0 0 var(--radius, 10px) var(--radius, 10px); min-height: 12rem; }
.wa-chat .wa-bubble { margin: 0 0 0 auto; }
@media (max-width: 900px) { .notify-grid { grid-template-columns: 1fr; } }
.wa-preview { max-width: 720px; margin: .75rem auto 0; text-align: left; }
.wa-preview summary { cursor: pointer; color: var(--primary); font-weight: 600; text-align: center; }
.wa-bubble {
    margin: .75rem auto 0; max-width: 420px; background: #dcf8c6; color: #111b21;
    padding: .75rem .9rem; border-radius: 10px 10px 2px 10px; box-shadow: 0 1px 1px rgba(0, 0, 0, .15);
    font-size: .9rem; line-height: 1.45; word-break: break-word;
}

@media print {
    body { background: #fff; }
    .no-print, .sidebar, .topbar, .footer { display: none !important; }
    .receipt { box-shadow: none; margin: 0; max-width: none; }
}

/* Responsive ------------------------------------------------------------- */
@media (max-width: 1100px) {
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-sidebar { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; }
    .sidebar.open { left: 0; }
    .menu-toggle { display: block; }
    .grid-2, .grid-3, .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: auto; }
    .user-meta { display: none; }
    .content { padding: 1rem; }
    .detail-list { grid-template-columns: 1fr; }
    .detail-list dt { margin-top: .4rem; }
}
