/* ==========================================================================
   Tuition Class Manager — desktop layout + full mobile app style
   ========================================================================== */
:root {
    --primary: #4f46e5;
    --primary-600: #4338ca;
    --primary-50: #eef2ff;
    --primary-100: #e0e7ff;
    --accent: #7c3aed;
    --bg: #f4f5fb;
    --surface: #ffffff;
    --text: #1e1b3a;
    --muted: #6b6a85;
    --line: #e6e6f0;
    --good: #0f9d58;
    --good-bg: #e6f6ee;
    --warn: #b7791f;
    --warn-bg: #fdf4e3;
    --bad: #d93025;
    --bad-bg: #fdecea;
    --info-bg: #e8f1fd;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(30, 27, 58, .04), 0 6px 24px rgba(30, 27, 58, .06);
    --shadow-lg: 0 20px 50px rgba(30, 27, 58, .18);
    --sidebar: 264px;
    --appbar: 60px;
    --bottom: 68px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; }
img { max-width: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.mb0 { margin-bottom: 0; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.flex-1 { flex: 1; min-width: 0; }
.between { justify-content: space-between; }
.ico { flex-shrink: 0; vertical-align: middle; }

/* ---------------------------------------------------------------- Sidebar */
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
    background: linear-gradient(180deg, #1e1b4b 0%, #312e81 60%, #4c1d95 100%);
    color: #e0e7ff; display: flex; flex-direction: column; z-index: 60;
    padding: 18px 14px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 18px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 12px; }
.brand img { width: 44px; height: 44px; object-fit: contain; border-radius: 12px; background: #fff; padding: 4px; }
.brand-mark { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; background: linear-gradient(135deg, #818cf8, #c084fc); color: #fff; }
.brand strong { display: block; color: #fff; font-size: 15px; line-height: 1.2; }
.brand small { color: #a5b4fc; font-size: 12px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar a, .sidebar .install-btn {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
    color: #c7d2fe; font-weight: 500; font-size: 14px; border: 0; background: none; cursor: pointer; font-family: inherit; width: 100%; text-align: left;
}
.sidebar a:hover, .sidebar .install-btn:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar a.active { background: rgba(255,255,255,.14); color: #fff; box-shadow: inset 3px 0 0 #a5b4fc; }
.side-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 10px; margin-top: 10px; }

/* ---------------------------------------------------------------- App bar */
.appbar {
    position: sticky; top: 0; z-index: 40; height: calc(var(--appbar) + var(--safe-t)); padding-top: var(--safe-t);
    display: flex; align-items: center; gap: 8px; padding-left: 12px; padding-right: 12px;
    background: rgba(244,245,251,.85); backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--line);
}
.appbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-actions { display: flex; gap: 4px; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: var(--text);
    display: inline-grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--primary-50); color: var(--primary); }

.content { padding: 24px 28px 40px; max-width: 1400px; }
body.with-nav { padding-left: var(--sidebar); }
body.with-nav .menu-toggle { display: none; }

/* ---------------------------------------------------------------- Bottom nav (mobile) */
.bottom-nav { display: none; }

/* ---------------------------------------------------------------- Page header */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- Cards */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; border: 1px solid rgba(230,230,240,.6); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 16px; }
.card.flat { box-shadow: none; }
.card.p0 { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

/* KPI tiles */
.kpi { background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; border: 1px solid rgba(230,230,240,.6); }
.kpi .k-label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .k-value { font-size: 26px; font-weight: 800; margin-top: 4px; letter-spacing: -.02em; }
.kpi .k-sub { font-size: 12.5px; color: var(--muted); }
.kpi .k-ico { position: absolute; right: 14px; top: 14px; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-50); color: var(--primary); }
.kpi.hero { background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); color: #fff; border: 0; }
.kpi.hero .k-label, .kpi.hero .k-sub { color: #e0e7ff; }
.kpi.hero .k-ico { background: rgba(255,255,255,.18); color: #fff; }

/* ---------------------------------------------------------------- Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > label, .label { font-weight: 600; font-size: 13px; color: #3b3960; }
.req { color: var(--bad); }
.hint { font-size: 12px; color: var(--muted); }
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month], input[type=time], input[type=url], input[type=search], select, textarea {
    width: 100%; font: inherit; color: var(--text); background: #fff; border: 1.5px solid var(--line);
    border-radius: var(--radius-sm); padding: 10px 12px; min-height: 44px; outline: none; transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none; appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b6a85' stroke-width='2' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79,70,229,.12); }
.input-group { display: flex; gap: 0; }
.input-group > * { border-radius: 0; }
.input-group > :first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group > :last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-group > select { max-width: 130px; flex-shrink: 0; border-right: 0; }
.input-group > input { flex: 1; min-width: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }

/* toggle switch */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--line); cursor: pointer; }
.switch:last-child { border-bottom: 0; }
.switch .s-text strong { display: block; font-size: 14px; }
.switch .s-text small { color: var(--muted); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .slider { width: 46px; height: 26px; border-radius: 20px; background: #d6d6e3; position: relative; flex-shrink: 0; transition: background .2s; }
.switch .slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::after { transform: translateX(20px); }
.switch input:disabled + .slider { opacity: .45; }

/* segmented control */
.seg { display: inline-flex; background: #eceef7; padding: 4px; border-radius: 12px; gap: 2px; flex-wrap: wrap; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; padding: 7px 12px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg input:checked + span { background: #fff; color: var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* ---------------------------------------------------------------- Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; font-size: 14px;
    padding: 10px 16px; min-height: 42px; border-radius: 12px; border: 0; cursor: pointer; background: var(--primary); color: #fff;
    transition: transform .08s, background .15s, box-shadow .15s; white-space: nowrap; text-decoration: none;
    box-shadow: 0 4px 14px rgba(79,70,229,.25);
}
.btn:hover { background: var(--primary-600); }
.btn:active { transform: scale(.97); }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 13px; border-radius: 10px; }
.btn-xs { padding: 3px 9px; min-height: 28px; font-size: 12px; border-radius: 8px; box-shadow: none; }
.btn-light { background: var(--primary-50); color: var(--primary); box-shadow: none; }
.btn-light:hover { background: var(--primary-100); }
.btn-ghost { background: transparent; color: var(--text); box-shadow: none; border: 1.5px solid var(--line); }
.btn-ghost:hover { background: #fff; border-color: #cfcfe0; }
.btn-danger { background: var(--bad); box-shadow: 0 4px 14px rgba(217,48,37,.2); }
.btn-danger:hover { background: #b3261e; }
.btn-good { background: var(--good); box-shadow: 0 4px 14px rgba(15,157,88,.2); }
.btn-good:hover { background: #0b7f47; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn-icon { width: 36px; height: 36px; min-height: 36px; padding: 0; border-radius: 10px; box-shadow: none; }

/* ---------------------------------------------------------------- Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: #eceef7; color: #4a4870; white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.primary { background: var(--primary-50); color: var(--primary); }
.badge.dark { background: #1e1b4b; color: #fff; }

/* ---------------------------------------------------------------- Alerts / toasts */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 500; border: 1px solid transparent; }
.alert-success { background: var(--good-bg); color: #0b6b3c; border-color: #bfe6d0; }
.alert-danger, .alert-error { background: var(--bad-bg); color: #a3241b; border-color: #f6c7c3; }
.alert-warning { background: var(--warn-bg); color: #8a5a12; border-color: #f2dcae; }
.alert-info { background: var(--info-bg); color: #1d4f91; border-color: #c9dcf7; }
.toast-wrap { position: fixed; z-index: 200; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; background: #1e1b3a; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); font-weight: 500; max-width: 360px; animation: toastIn .25s ease; display: flex; gap: 10px; align-items: center; }
.toast.good { background: #0b7f47; }
.toast.bad { background: #b3261e; }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } }

/* ---------------------------------------------------------------- Tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1.5px solid var(--line); background: #fafafe; white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:hover td { background: #fafaff; }
.table tfoot td { font-weight: 800; background: #fafafe; }
.table .actions { white-space: nowrap; text-align: right; }

/* ---------------------------------------------------------------- Lists / avatars */
.avatar { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; color: #fff; background: linear-gradient(135deg, #6366f1, #a855f7); flex-shrink: 0; font-size: 15px; }
.avatar.lg { width: 64px; height: 64px; border-radius: 18px; font-size: 22px; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { color: var(--muted); }
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }

/* ---------------------------------------------------------------- Tabs */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 9px 16px; border-radius: 12px; font-weight: 600; color: var(--muted); background: #fff; border: 1.5px solid var(--line); white-space: nowrap; display: inline-flex; gap: 8px; align-items: center; }
.tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------------------------------------------------------------- Empty state */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-ico { font-size: 40px; margin-bottom: 8px; }
.empty h2, .empty h3 { color: var(--text); }

/* ---------------------------------------------------------------- Modal */
.modal { position: fixed; inset: 0; z-index: 150; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(20,18,40,.5); backdrop-filter: blur(3px); }
.modal.open { display: flex; animation: fade .15s; }
.modal-box { background: #fff; border-radius: 20px; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; padding: 20px; box-shadow: var(--shadow-lg); animation: pop .2s ease; }
.modal-box.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.96) translateY(10px); opacity: 0; } }
.steps { padding-left: 20px; line-height: 1.9; }
.kbd { display: inline-block; background: var(--primary-50); color: var(--primary); border-radius: 6px; padding: 0 6px; font-weight: 700; }

/* ---------------------------------------------------------------- Schedule rows / dynamic rows */
.row-card { border: 1.5px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; position: relative; background: #fcfcff; }
.row-card .row-remove { position: absolute; top: 8px; right: 8px; }
.row-grid { display: grid; grid-template-columns: 1.3fr 1fr 1fr 2fr; gap: 12px; padding-right: 40px; }
.row-grid.enroll { grid-template-columns: 2fr 1.4fr 1fr 1fr; }

/* commission blocks */
.comm-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.comm-box { border: 1.5px solid var(--line); border-radius: 14px; padding: 14px; background: linear-gradient(180deg, #fff, #fafaff); }
.comm-box .label { display: flex; justify-content: space-between; margin-bottom: 8px; }
.comm-preview { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------------------------------------------------------------- Month boxes */
.month-boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.mbox {
    border-radius: 12px; padding: 8px 8px 7px; border: 1.5px solid var(--line); background: #fff; text-align: center;
    cursor: pointer; position: relative; transition: transform .1s, box-shadow .15s; font: inherit; color: inherit;
}
.mbox:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(30,27,58,.08); }
.mbox .m-name { font-weight: 800; font-size: 14px; line-height: 1.1; }
.mbox .m-year { font-size: 10.5px; color: var(--muted); }
.mbox .m-state { font-size: 10.5px; font-weight: 700; margin-top: 4px; text-transform: uppercase; letter-spacing: .03em; }
.mbox .m-att { position: absolute; top: -7px; right: -7px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; background: #1e1b4b; color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; border: 2px solid #fff; }
.mbox.paid { background: var(--good-bg); border-color: #a8dcbf; }
.mbox.paid .m-state { color: var(--good); }
.mbox.unpaid { background: var(--bad-bg); border-color: #f3b9b4; }
.mbox.unpaid .m-state { color: var(--bad); }
.mbox.partial { background: var(--warn-bg); border-color: #efd29b; }
.mbox.partial .m-state { color: var(--warn); }
.mbox.free { background: #eef0ff; border-color: #c7cbfb; cursor: default; }
.mbox.free .m-state { color: var(--primary); }
.mbox.future { background: #fff; border-style: dashed; }
.mbox.future .m-state { color: var(--muted); }
.mbox.current { outline: 2.5px solid var(--primary); outline-offset: 2px; }
.class-status { border: 1.5px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 12px; background: #fff; }
.class-status.marked { border-color: #8fd3ae; box-shadow: 0 0 0 4px rgba(15,157,88,.08); }
.class-status .cs-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 12px; flex-wrap: wrap; }
.class-status .cs-head strong { font-size: 15px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 4px; vertical-align: -2px; border: 1.5px solid; }

.adm-pending { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 12px 14px; border-radius: 14px; background: var(--warn-bg); border: 1.5px solid #efd29b; margin-bottom: 12px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- Scanner */
.scan-layout { display: grid; grid-template-columns: 420px 1fr; gap: 18px; align-items: start; }
.scanner { position: relative; border-radius: 20px; overflow: hidden; background: #0f0d24; aspect-ratio: 1 / 1; }
.scanner .reader { width: 100%; height: 100%; }
.scanner .reader video { object-fit: cover; width: 100% !important; height: 100% !important; }
.scanner .scan-frame { position: absolute; inset: 15%; border-radius: 18px; box-shadow: 0 0 0 9999px rgba(15,13,36,.35); pointer-events: none; }
.scanner .scan-frame::before { content: ""; position: absolute; left: 6%; right: 6%; height: 2px; top: 10%; background: linear-gradient(90deg, transparent, #a5b4fc, transparent); animation: scanline 2s ease-in-out infinite; }
@keyframes scanline { 50% { top: 88%; } }
.scanner .scan-ctl { position: absolute; bottom: 12px; left: 0; right: 0; display: flex; justify-content: center; gap: 10px; }
.scanner .scan-ctl .btn { background: rgba(255,255,255,.18); backdrop-filter: blur(6px); box-shadow: none; }
.scanner .scan-off { position: absolute; inset: 0; display: grid; place-items: center; color: #c7d2fe; text-align: center; padding: 20px; }
.code-input { display: flex; gap: 8px; }
.code-input input { font-size: 18px; font-weight: 700; letter-spacing: .04em; }
.running { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.run-chip { flex-shrink: 0; padding: 8px 12px; border-radius: 12px; background: var(--good-bg); color: #0b6b3c; font-weight: 600; font-size: 13px; border: 1.5px solid #a8dcbf; }
.run-chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--good); margin-right: 6px; animation: pulse 1.5s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.flash-ok { animation: flashok .6s; }
@keyframes flashok { 0% { box-shadow: 0 0 0 0 rgba(15,157,88,.6); } 100% { box-shadow: 0 0 0 20px rgba(15,157,88,0); } }
.result-head { display: flex; gap: 14px; align-items: center; }

/* ---------------------------------------------------------------- Attendance panel */
.att-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; border: 1.5px solid var(--line); background: #fff; margin-bottom: 8px; }
.att-row.present { border-color: #8fd3ae; background: #f3fbf6; }
.att-toggle { width: 46px; height: 46px; border-radius: 14px; border: 2px solid var(--line); background: #fff; display: grid; place-items: center; cursor: pointer; flex-shrink: 0; color: transparent; transition: all .15s; }
.att-toggle:hover { border-color: var(--good); }
.present .att-toggle { background: var(--good); border-color: var(--good); color: #fff; }
.pay-chip { font-size: 12px; font-weight: 700; padding: 6px 10px; border-radius: 10px; border: 1.5px solid; cursor: pointer; background: #fff; font-family: inherit; white-space: nowrap; }
.pay-chip.paid { color: var(--good); border-color: #a8dcbf; background: var(--good-bg); cursor: default; }
.pay-chip.unpaid { color: var(--bad); border-color: #f3b9b4; background: var(--bad-bg); }
.pay-chip.free { color: var(--primary); border-color: #c7cbfb; background: #eef0ff; cursor: default; }
.pay-chip.partial { color: var(--warn); border-color: #efd29b; background: var(--warn-bg); }

/* ---------------------------------------------------------------- Timeline today */
.tl-item { display: flex; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: center; }
.tl-item:last-child { border-bottom: 0; }
.tl-time { width: 78px; flex-shrink: 0; font-weight: 700; font-size: 13px; }
.tl-time small { display: block; color: var(--muted); font-weight: 500; }
.tl-bar { height: 6px; border-radius: 4px; background: #eceef7; overflow: hidden; margin-top: 6px; }
.tl-bar span { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.live { color: var(--good); font-weight: 700; font-size: 12px; }

/* ---------------------------------------------------------------- Charts (CSS) */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 180px; padding: 10px 0 0; border-bottom: 1.5px solid var(--line); position: relative; }
.bars .bar { flex: 1; min-width: 6px; background: var(--primary); border-radius: 4px 4px 0 0; position: relative; transition: opacity .15s; }
.bars .bar:hover { opacity: .8; }
.bars .bar[data-tip]:hover::after, .hbar [data-tip]:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: #1e1b3a; color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 8px; white-space: nowrap; z-index: 5; pointer-events: none; }
.bars-x { display: flex; gap: 4px; font-size: 10.5px; color: var(--muted); margin-top: 6px; }
.bars-x span { flex: 1; text-align: center; min-width: 6px; overflow: hidden; }
.hbar { display: flex; flex-direction: column; gap: 12px; }
.hbar .hb-row { display: grid; grid-template-columns: minmax(90px, 180px) 1fr auto; gap: 12px; align-items: center; font-size: 13px; }
.hbar .hb-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .hb-track { height: 12px; background: #eceef7; border-radius: 6px; overflow: visible; position: relative; display: flex; gap: 2px; }
.hbar .hb-fill { height: 100%; border-radius: 6px; background: var(--primary); position: relative; }
.hbar .hb-fill.good { background: var(--good); }
.hbar .hb-fill.bad { background: #e8837c; }
.hbar .hb-val { font-weight: 700; white-space: nowrap; }
.ring { --p: 0; width: 120px; height: 120px; border-radius: 50%; background: conic-gradient(var(--good) calc(var(--p) * 1%), #f3b9b4 0); display: grid; place-items: center; flex-shrink: 0; }
.ring::before { content: ""; grid-area: 1/1; width: 84px; height: 84px; border-radius: 50%; background: #fff; }
.ring b { grid-area: 1/1; font-size: 20px; z-index: 1; }
.progress { height: 8px; background: #eceef7; border-radius: 5px; overflow: hidden; min-width: 60px; }
.progress span { display: block; height: 100%; background: var(--good); border-radius: 5px; }
.heat { display: grid; gap: 3px; }
.heat .hc { width: 22px; height: 22px; border-radius: 6px; background: #eceef7; display: grid; place-items: center; font-size: 10px; color: #fff; font-weight: 700; }
.heat .hc.on { background: var(--good); }
.matrix th.rot { writing-mode: vertical-rl; transform: rotate(180deg); padding: 8px 4px; font-size: 11px; }
.matrix td.cell { padding: 4px; text-align: center; }

/* ---------------------------------------------------------------- Login */
body.bare { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(1200px 600px at 10% -10%, #c7d2fe 0, transparent 60%), radial-gradient(900px 500px at 110% 110%, #e9d5ff 0, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 24px; padding: 32px; box-shadow: var(--shadow-lg); }
.auth-card .brand-mark, .auth-card .auth-logo { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 14px; font-size: 22px; display: grid; place-items: center; }
.auth-card .auth-logo { object-fit: contain; }
.auth-card h1 { text-align: center; font-size: 22px; }
.auth-card p.sub { text-align: center; color: var(--muted); margin-top: -4px; margin-bottom: 22px; }

/* ---------------------------------------------------------------- Install banner */
.install-banner { position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 120; max-width: 480px; margin: 0 auto; background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg); padding: 12px; display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); animation: toastIn .3s; }
.install-banner .ib-ico img { width: 44px; height: 44px; border-radius: 12px; }
.install-banner .ib-text { flex: 1; min-width: 0; }
.install-banner .ib-text strong { display: block; font-size: 14px; }
.install-banner .ib-text small { color: var(--muted); font-size: 12px; }

/* ---------------------------------------------------------------- Select2 to match inputs */
.select2-container { width: 100% !important; }
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple { min-height: 44px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.select2-container--default .select2-selection--single .select2-selection__rendered { line-height: 41px; padding-left: 12px; padding-right: 34px; color: var(--text); }
.select2-container--default .select2-selection--single .select2-selection__arrow { height: 41px; right: 6px; }
.select2-container--default .select2-selection--single .select2-selection__placeholder { color: #9b9ab3; }
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--multiple { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79,70,229,.12); }
.select2-container--default .select2-selection--multiple .select2-selection__choice { background: var(--primary-50); border: 0; color: var(--primary); border-radius: 8px; padding: 2px 8px 2px 22px; font-weight: 600; margin-top: 7px; }
.select2-dropdown { border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-lg); z-index: 1060; }
.select2-search--dropdown .select2-search__field { border: 1.5px solid var(--line) !important; border-radius: 10px; padding: 8px 10px; min-height: 0; }
.select2-results__option { padding: 9px 12px; }
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable { background: var(--primary); }
.select2-container--default .select2-results__option--selected { background: var(--primary-50); color: var(--primary); }
.select2-container--default .select2-selection--single .select2-selection__clear { margin-right: 8px; height: 40px; }
.s2-new { color: var(--primary); font-weight: 700; }

/* ---------------------------------------------------------------- Responsive: tablet */
@media (max-width: 1200px) {
    .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .scan-layout { grid-template-columns: 340px 1fr; }
}

/* ---------------------------------------------------------------- Responsive: mobile app */
@media (max-width: 991px) {
    body.with-nav { padding-left: 0; padding-bottom: calc(var(--bottom) + var(--safe-b)); }
    body.with-nav .menu-toggle { display: inline-grid; }
    .sidebar { transform: translateX(-105%); transition: transform .25s ease; width: 84vw; max-width: 300px; box-shadow: var(--shadow-lg); padding-top: calc(18px + var(--safe-t)); }
    .sidebar.open { transform: none; }
    .scrim { position: fixed; inset: 0; background: rgba(20,18,40,.45); z-index: 55; opacity: 0; pointer-events: none; transition: opacity .2s; }
    .scrim.open { opacity: 1; pointer-events: auto; }
    .content { padding: 14px 14px 24px; }
    .page-head { margin-bottom: 12px; }
    .page-head h2 { font-size: 19px; }
    .page-head.m-hide-title h2, .page-head.m-hide-title > div > p { display: none; }
    .card { padding: 16px; border-radius: 18px; margin-bottom: 14px; }
    .g-2, .g-3, .form-grid, .form-grid.cols-3, .form-grid.cols-4, .comm-grid { grid-template-columns: minmax(0, 1fr); }
    .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .span-2 { grid-column: auto; }
    .kpi { padding: 14px; }
    .kpi .k-value { font-size: 21px; }
    .kpi .k-label { padding-right: 34px; font-size: 11.5px; }
    .g-3.kpi-row { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
    .kpi-row .kpi { padding: 12px; }
    .kpi-row .k-label { padding-right: 0; }
    .kpi-row .k-value { font-size: 16px; }
    .kpi .k-ico { width: 32px; height: 32px; right: 10px; top: 10px; }
    .kpi .k-ico .ico { width: 16px; height: 16px; }
    .row-grid, .row-grid.enroll { grid-template-columns: 1fr 1fr; padding-right: 0; padding-top: 26px; }
    .row-grid > .full-m { grid-column: 1 / -1; }
    .scan-layout { grid-template-columns: 1fr; }
    .scanner { aspect-ratio: 4 / 3; }
    .month-boxes { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); }
    .hbar .hb-row { grid-template-columns: 90px 1fr auto; }
    .toast-wrap { left: 14px; right: 14px; bottom: calc(var(--bottom) + var(--safe-b) + 12px); }
    .toast { max-width: none; }
    .install-banner { bottom: calc(var(--bottom) + var(--safe-b) + 10px); }
    .modal { align-items: flex-end; padding: 0; }
    .modal-box { border-radius: 22px 22px 0 0; max-height: 88vh; padding-bottom: calc(20px + var(--safe-b)); animation: sheet .25s ease; }
    @keyframes sheet { from { transform: translateY(100%); } }
    .btn { min-height: 44px; }
    .hide-m { display: none !important; }

    /* bottom navigation */
    .bottom-nav {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; height: calc(var(--bottom) + var(--safe-b)); padding-bottom: var(--safe-b);
        background: rgba(255,255,255,.94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line);
    }
    .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); }
    .bottom-nav a.active { color: var(--primary); }
    .bottom-nav a.active .bn-ico { background: var(--primary-50); }
    .bottom-nav .bn-ico { width: 48px; height: 30px; border-radius: 15px; display: grid; place-items: center; transition: background .2s; }
    .bottom-nav a.fab-nav .bn-ico { width: 54px; height: 54px; border-radius: 18px; background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; margin-top: -26px; box-shadow: 0 8px 20px rgba(79,70,229,.4); border: 4px solid var(--bg); }

    /* tables become cards */
    table.rtable, .rtable tbody, .rtable tr, .rtable td { display: block; width: 100%; }
    .rtable thead { display: none; }
    .rtable tr { background: #fff; border: 1.5px solid var(--line); border-radius: 16px; padding: 10px 14px; margin-bottom: 10px; }
    .rtable td { border: 0; padding: 5px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
    .rtable td::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: 12.5px; text-align: left; flex-shrink: 0; }
    .rtable td[data-label=""]::before, .rtable td:not([data-label])::before { display: none; }
    .rtable td.cell-main { justify-content: flex-start; text-align: left; padding-bottom: 8px; border-bottom: 1px dashed var(--line); margin-bottom: 4px; }
    .rtable td.actions { justify-content: flex-end; padding-top: 8px; border-top: 1px dashed var(--line); margin-top: 4px; }
    .rtable tbody tr:hover td { background: transparent; }
    .rtable tfoot, .rtable tfoot tr, .rtable tfoot td { display: block; }
    .card.p0 .rtable { padding: 10px; }
    .fab { position: fixed; right: 18px; bottom: calc(var(--bottom) + var(--safe-b) + 16px); z-index: 45; width: 56px; height: 56px; border-radius: 18px; padding: 0; box-shadow: 0 10px 24px rgba(79,70,229,.45); }
    .fab span { display: none; }
}
@media (min-width: 992px) {
    .hide-d { display: none !important; }
    .fab { position: static; }
}
@media (max-width: 420px) {
    .g-4 { gap: 8px; }
    .kpi .k-value { font-size: 19px; }
    .seg span { padding: 7px 9px; }
}

/* ---------------------------------------------------------------- Print */
@media print {
    .sidebar, .appbar, .bottom-nav, .no-print, .install-banner, .toast-wrap, .tabs, .btn { display: none !important; }
    body.with-nav { padding: 0; background: #fff; }
    .content { padding: 0; max-width: none; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
}

/* ==========================================================================
   ID card (single sided, CR80 85.6 x 54 mm). Sizes use container units so
   the same card works on screen, in previews and on the A4 print sheet.
   ========================================================================== */
.idc-box { container-type: inline-size; width: 100%; }
.idc {
    width: 100%; aspect-ratio: 85.6 / 54; position: relative; overflow: hidden; border-radius: 3.7cqw;
    font-family: "Plus Jakarta Sans", system-ui, sans-serif; line-height: 1.2; -webkit-print-color-adjust: exact; print-color-adjust: exact;
    background: #fff; color: #1e1b3a; border: .25cqw solid #e3e3ee;
}
.idc .idc-deco { position: absolute; inset: 0; pointer-events: none; }
.idc .idc-head { position: absolute; left: 5.5%; right: 5.5%; top: 6.5%; display: flex; align-items: center; gap: 2.6cqw; }
.idc .idc-logo { width: 11cqw; height: 11cqw; border-radius: 2.4cqw; object-fit: contain; background: #fff; flex-shrink: 0; }
.idc .idc-mono { display: grid; place-items: center; font-weight: 800; font-size: 4.2cqw; color: #fff; background: var(--ac); }
.idc .idc-inst strong { display: block; font-size: 4.3cqw; font-weight: 800; line-height: 1.1; }
.idc .idc-inst span { display: block; font-size: 2.3cqw; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--ac); margin-top: .5cqw; }
.idc .idc-body { position: absolute; left: 5.5%; top: 31%; width: 56%; }
.idc .idc-label { font-size: 2.3cqw; text-transform: uppercase; letter-spacing: .16em; font-weight: 700; opacity: .6; }
.idc .idc-code { font-size: 10.5cqw; font-weight: 800; line-height: 1; letter-spacing: -.02em; color: var(--ac); margin-top: .6cqw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.idc .idc-name { font-size: 4.4cqw; font-weight: 800; margin-top: 1.8cqw; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.idc .idc-sub { font-size: 2.5cqw; margin-top: .9cqw; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.idc .idc-line { font-size: 2.4cqw; opacity: .6; border-bottom: .25cqw dashed currentColor; padding-top: 3.2cqw; padding-bottom: .4cqw; }
.idc .idc-qr { position: absolute; right: 5.5%; top: 30%; width: 29%; aspect-ratio: 1; background: #fff; border-radius: 2.4cqw; padding: 1.6cqw; border: .6cqw solid var(--ac); }
.idc .idc-qr canvas, .idc .idc-qr img { width: 100% !important; height: 100% !important; display: block; image-rendering: pixelated; }
.idc .idc-foot { position: absolute; left: 0; right: 0; bottom: 0; height: 11%; display: flex; align-items: center; justify-content: space-between; gap: 2cqw; padding: 0 5.5%; font-size: 2.2cqw; font-weight: 600; background: var(--ac); color: #fff; }
.idc .idc-foot span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* White template (default) */
.idc.tpl-white .idc-deco { background: linear-gradient(90deg, var(--ac) 0 1.6cqw, transparent 1.6cqw); }
.idc.tpl-white .idc-deco::before, .idc.tpl-white .idc-deco::after { content: ""; position: absolute; border-radius: 50%; background: var(--ac); }
.idc.tpl-white .idc-deco::before { width: 72cqw; height: 72cqw; right: -36cqw; top: -36cqw; opacity: .08; }
.idc.tpl-white .idc-deco::after { width: 52cqw; height: 52cqw; right: -26cqw; top: -26cqw; opacity: .14; }
.idc.tpl-white .idc-logo { border: .25cqw solid #ececf4; }

/* Custom template */
.idc.tpl-custom { background: linear-gradient(135deg, var(--bg) 0%, var(--bg2) 100%); color: var(--tx); border: 0; }
.idc.tpl-custom .idc-deco { background: radial-gradient(circle at 105% -10%, rgba(255,255,255,.14) 0 30cqw, transparent 30.3cqw), radial-gradient(circle at -10% 120%, rgba(255,255,255,.08) 0 26cqw, transparent 26.3cqw); }
.idc.tpl-custom .idc-inst span, .idc.tpl-custom .idc-code { color: var(--tx); }
.idc.tpl-custom .idc-qr { border-color: rgba(255,255,255,.9); }
.idc.tpl-custom .idc-foot { background: rgba(0,0,0,.22); color: var(--tx); }

/* A4 print sheet: 2 x 5 cards = 10 per page */
.sheets { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.sheet-scale { width: 100%; display: flex; justify-content: center; }
.sheet {
    width: 210mm; height: 297mm; background: #fff; box-shadow: 0 10px 30px rgba(30,27,58,.15); position: relative;
    display: grid; grid-template-columns: repeat(2, 85.6mm); grid-auto-rows: 54mm; column-gap: 6mm; row-gap: 2mm;
    align-content: start; justify-content: center; padding-top: 9.5mm; transform-origin: top center; flex-shrink: 0;
}
.sheet .slot { container-type: inline-size; width: 85.6mm; height: 54mm; outline: .2mm dashed #cfcfe0; outline-offset: 1mm; border-radius: 3.18mm; }
.sheet .slot .idc { border-radius: 3.18mm; }
.sheet .page-no { position: absolute; bottom: 4mm; right: 8mm; font-size: 8pt; color: #9b9ab3; }
@media print {
    @page { size: A4 portrait; margin: 0; }
    body.print-sheet { background: #fff !important; padding: 0 !important; }
    body.print-sheet .content { padding: 0 !important; }
    body.print-sheet .sheets { gap: 0; display: block; }
    body.print-sheet .sheet-scale { display: block; height: auto !important; }
    body.print-sheet .sheet { box-shadow: none; transform: none !important; page-break-after: always; break-after: page; margin: 0; }
    body.print-sheet .card, body.print-sheet .alert { display: none !important; }
}

/* role permission grid */
.perm-group { border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; background: #fcfcff; break-inside: avoid; margin-bottom: 14px; }
.perm-group h4 { display: flex; justify-content: space-between; align-items: center; margin: 0 0 8px; font-size: 14px; }
.perm-cols { columns: 3 280px; column-gap: 14px; }
.perm-group .check { display: flex; padding: 4px 0; font-size: 13.5px; }
.audit-act { font-weight: 700; text-transform: uppercase; font-size: 10.5px; letter-spacing: .04em; }
.chg { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
.chg td, .chg th { padding: 5px 8px; border: 1px solid var(--line); text-align: left; }
.chg th { background: #fafafe; }
.chg .old { color: var(--bad); text-decoration: line-through; }
.chg .new { color: var(--good); font-weight: 600; }
details.audit-more summary { cursor: pointer; color: var(--primary); font-weight: 600; font-size: 12.5px; }
.super-bar { background: linear-gradient(90deg, #f59e0b, #f97316); color: #fff; padding: 8px 16px; display: flex; align-items: center; gap: 10px; justify-content: space-between; font-weight: 600; font-size: 13px; flex-wrap: wrap; }
.super-bar a { color: #fff; text-decoration: underline; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--good); }
.status-dot.off { background: #b8b7c9; }
