/* ===================================================================
   EMS ACADEMY — INVOICE STUDIO
   Design tokens: navy ledger + gold seal, set in Fraunces / Inter / IBM Plex Mono
   =================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
    --navy: #0B1F3A;
    --navy-2: #142B4F;
    --navy-3: #1D3A66;
    --gold: #C9A227;
    --gold-light: #E8D9A0;
    --cream: #FAF7F0;
    --paper: #FFFFFF;
    --ink: #1C1C1C;
    --slate: #5B6472;
    --success: #1F7A3D;
    --success-bg: #E7F3EA;
    --alert: #B23A2E;
    --alert-bg: #FBEAE7;
    --amber: #9A6B00;
    --amber-bg: #FBF1DA;
    --line: #E4DFD3;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(11,31,58,.06), 0 8px 24px -12px rgba(11,31,58,.15);
    font-size: 15px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--cream);
    color: var(--ink);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }

h1, h2, h3, .display {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--navy);
    margin: 0;
}

a { color: inherit; }
button { font-family: inherit; cursor: pointer; }

::selection { background: var(--gold-light); }

:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------
   PIN LOCK SCREEN
   --------------------------------------------------------------- */
#lock-screen {
    position: fixed; inset: 0;
    background: var(--navy);
    background-image:
        radial-gradient(circle at 15% 20%, rgba(201,162,39,.08), transparent 40%),
        radial-gradient(circle at 85% 80%, rgba(201,162,39,.06), transparent 40%);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.lock-card {
    background: var(--paper);
    border-radius: 14px;
    padding: 40px 36px 32px;
    width: 340px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.lock-seal {
    width: 56px; height: 56px; margin: 0 auto 18px;
    border: 2px solid var(--gold);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-family: 'Fraunces', serif; font-weight: 700; font-size: 20px;
    color: var(--navy);
}
.lock-card h1 { font-size: 21px; margin-bottom: 4px; }
.lock-card p.sub { color: var(--slate); font-size: 13px; margin: 0 0 22px; }
#pin-input {
    width: 100%; text-align: center; letter-spacing: .5em;
    font-size: 22px; padding: 12px 10px 12px 16px;
    border: 1.5px solid var(--line); border-radius: 8px;
    margin-bottom: 14px; font-family: 'IBM Plex Mono', monospace;
}
#pin-input:focus { border-color: var(--gold); }
.lock-error { color: var(--alert); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.btn-primary {
    width: 100%; background: var(--navy); color: #fff; border: none;
    padding: 12px; border-radius: 8px; font-weight: 600; font-size: 14.5px;
    transition: background .15s;
}
.btn-primary:hover { background: var(--navy-2); }
.lock-default-note {
    margin-top: 16px; font-size: 11.5px; color: var(--slate); line-height: 1.5;
}

/* ---------------------------------------------------------------
   APP SHELL
   --------------------------------------------------------------- */
#app { display: none; min-height: 100vh; }
#app.active { display: flex; }

.sidebar {
    width: 232px; flex-shrink: 0;
    background: var(--navy);
    color: #fff;
    display: flex; flex-direction: column;
    padding: 26px 18px;
    position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 8px 22px; border-bottom: 1px solid rgba(255,255,255,.12); margin-bottom: 18px; }
.brand .mark {
    font-family: 'Fraunces', serif; font-weight: 700; font-size: 19px; color: #fff;
    line-height: 1.15;
}
.brand .mark span { color: var(--gold); }
.brand .tag { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: rgba(255,255,255,.55); margin-top: 4px; }

.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: 8px; margin-bottom: 3px;
    color: rgba(255,255,255,.72); font-size: 13.5px; font-weight: 500;
    background: transparent; border: none; width: 100%; text-align: left;
    transition: background .15s, color .15s;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(201,162,39,.16); color: #fff; }
.nav-item.active svg { opacity: 1; color: var(--gold); }

.sidebar-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-footer .next-no { font-size: 10.5px; color: rgba(255,255,255,.5); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 3px; }
.sidebar-footer .next-no-val { font-family: 'IBM Plex Mono', monospace; font-size: 13px; color: var(--gold-light); margin-bottom: 14px; }
.lock-btn {
    display: flex; align-items: center; gap: 8px;
    background: transparent; border: 1px solid rgba(255,255,255,.18); color: rgba(255,255,255,.75);
    padding: 8px 12px; border-radius: 8px; font-size: 12.5px; width: 100%;
}
.lock-btn:hover { border-color: var(--gold); color: #fff; }

.main { flex: 1; padding: 34px 42px 60px; max-width: 1180px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 26px; flex-wrap: wrap; gap: 12px; }
.page-head h1 { font-size: 27px; }
.page-head .sub { color: var(--slate); font-size: 13.5px; margin-top: 4px; }

.card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px 26px;
    margin-bottom: 22px;
}
.card h2 { font-size: 15.5px; margin-bottom: 4px; }
.card .card-sub { color: var(--slate); font-size: 12.5px; margin-bottom: 18px; }

/* ---------------------------------------------------------------
   DASHBOARD
   --------------------------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 26px; }
.stat-card {
    background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat-card::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--gold);
}
.stat-card .label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--slate); margin-bottom: 8px; }
.stat-card .value { font-family: 'Fraunces', serif; font-size: 25px; font-weight: 600; color: var(--navy); }
.stat-card .value.mono { font-family: 'IBM Plex Mono', monospace; font-weight: 600; }

.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-list li {
    display: flex; align-items: center; justify-content: space-between;
    padding: 11px 0; border-bottom: 1px solid var(--line);
    font-size: 13.5px;
}
.recent-list li:last-child { border-bottom: none; }
.recent-list .who { font-weight: 600; color: var(--ink); }
.recent-list .meta { color: var(--slate); font-size: 12px; }
.recent-list .amt { font-family: 'IBM Plex Mono', monospace; font-weight: 600; }

.empty-state { text-align: center; padding: 34px 20px; color: var(--slate); font-size: 13.5px; }

/* ---------------------------------------------------------------
   FORMS
   --------------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.span-2 { grid-column: span 2; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--navy); }
.field .hint { font-size: 11px; color: var(--slate); font-weight: 400; margin-top: -2px; }
input, select, textarea {
    font-family: 'Inter', sans-serif; font-size: 13.5px; color: var(--ink);
    border: 1.5px solid var(--line); border-radius: 7px;
    padding: 9px 11px; background: var(--paper); width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); }
input:disabled, select:disabled { background: #F4F2EC; color: var(--slate); }
textarea { resize: vertical; min-height: 60px; }

.btn { border: none; border-radius: 8px; padding: 10px 18px; font-size: 13.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 7px; line-height: 1; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover { background: #B8931F; }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-2); }
.btn-ghost { background: transparent; color: var(--navy); border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: var(--gold); }
.btn-danger { background: transparent; color: var(--alert); border: 1.5px solid var(--alert-bg); }
.btn-danger:hover { background: var(--alert-bg); }
.btn-row { display: flex; gap: 10px; margin-top: 20px; align-items: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.calc-strip {
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px;
    margin-top: 20px; padding: 16px 18px; background: var(--cream);
    border: 1px dashed var(--gold-light); border-radius: 8px;
}
.calc-strip .item { text-align: left; }
.calc-strip .item .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--slate); }
.calc-strip .item .v { font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 15px; color: var(--navy); }
.calc-strip .item.total .v { color: var(--success); font-size: 17px; }

.checkbox-label { display: flex !important; flex-direction: row !important; align-items: center; gap: 8px; font-size: 13px !important; cursor: pointer; }
.checkbox-label input[type=checkbox] { width: auto; }

.plan-toggle { display: flex; gap: 18px; padding: 9px 0; }
.plan-toggle label { display: flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 500; color: var(--ink); cursor: pointer; }
.plan-toggle input[type=radio] { width: auto; }

#ni-installment-section { margin-top: 18px; padding: 16px 18px; background: #FBFAF6; border: 1px solid var(--line); border-radius: 8px; }
.inst-row { display: grid; grid-template-columns: 110px 1fr 160px; gap: 10px; align-items: center; margin-bottom: 8px; }
.inst-label { font-size: 12.5px; font-weight: 600; color: var(--navy); }

.inst-badge {
    display: inline-block; margin-top: 3px; font-size: 10px; font-weight: 600;
    color: var(--gold); background: var(--navy); padding: 1px 7px; border-radius: 4px; letter-spacing: .02em;
}

.msg { padding: 10px 14px; border-radius: 7px; font-size: 13px; margin-bottom: 16px; }
.msg.success { background: var(--success-bg); color: var(--success); }
.msg.error { background: var(--alert-bg); color: var(--alert); }

/* ---------------------------------------------------------------
   TABLES / REGISTER
   --------------------------------------------------------------- */
.toolbar { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { max-width: 240px; }
.toolbar select { max-width: 160px; }

table.register { width: 100%; border-collapse: collapse; font-size: 13px; }
#reg-table-wrap, #fee-table-wrap, .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.register th {
    text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--slate); border-bottom: 1.5px solid var(--line); padding: 8px 10px; white-space: nowrap;
}
table.register td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.register tr:hover td { background: #FBFAF6; }
table.register .amt { font-family: 'IBM Plex Mono', monospace; font-weight: 600; text-align: right; }
table.register .num { font-family: 'IBM Plex Mono', monospace; }

.stamp {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 700;
    letter-spacing: .04em; text-transform: uppercase;
    border: 1.5px solid currentColor;
}
.stamp::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.stamp.paid { color: var(--success); background: var(--success-bg); }
.stamp.pending { color: var(--alert); background: var(--alert-bg); }
.stamp.partial { color: var(--amber); background: var(--amber-bg); }

.icon-btn {
    background: transparent; border: 1px solid var(--line); border-radius: 6px;
    width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
    color: var(--slate); margin-right: 4px;
}
.icon-btn:hover { border-color: var(--gold); color: var(--navy); }
.icon-btn svg { width: 15px; height: 15px; }

/* ---------------------------------------------------------------
   FEE STRUCTURE TABLE
   --------------------------------------------------------------- */
table.fee-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.fee-table th {
    text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--slate); border-bottom: 1.5px solid var(--line); padding: 8px 10px;
}
table.fee-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
table.fee-table input { padding: 6px 8px; font-size: 13px; }

/* ---------------------------------------------------------------
   MODAL (confirm / invoice preview)
   --------------------------------------------------------------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(11,31,58,.55);
    display: flex; align-items: center; justify-content: center; z-index: 500; padding: 24px;
}
.modal { background: var(--paper); border-radius: 12px; max-width: 560px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--slate); line-height: 1; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------------------------------------------------------------
   PRINTABLE INVOICE
   --------------------------------------------------------------- */
#invoice-preview-overlay {
    display: none; position: fixed; inset: 0; z-index: 600;
    background: rgba(11,31,58,.6);
    align-items: flex-start; justify-content: center;
    padding: 34px 20px; overflow-y: auto;
}
.invoice-preview-shell {
    background: #fff; border-radius: 10px; max-width: 780px; width: 100%;
    box-shadow: 0 30px 80px rgba(0,0,0,.4);
}
.invoice-preview-toolbar {
    display: flex; justify-content: flex-end; align-items: center; gap: 10px;
    padding: 14px 20px; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; background: #fff; border-radius: 10px 10px 0 0;
}
#invoice-print {
    width: 720px; max-width: 100%; margin: 0 auto; background: #fff; color: var(--ink);
    font-family: 'Inter', sans-serif; padding: 30px 34px 26px;
}

.inv-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid var(--navy); padding-bottom: 16px; margin-bottom: 20px; }
.inv-header .brandblock .name { font-family: 'Fraunces', serif; font-size: 22px; font-weight: 700; color: var(--navy); }
.inv-header .brandblock .addr { font-size: 11.5px; color: var(--slate); margin-top: 3px; max-width: 320px; }
.inv-header .brandblock .ids { font-size: 10.5px; color: var(--slate); margin-top: 6px; }
.inv-seal {
    width: 78px; height: 78px; border: 2.5px solid var(--gold); border-radius: 50%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transform: rotate(-8deg); text-align: center;
}
.inv-seal .t1 { font-family: 'Fraunces', serif; font-weight: 700; font-size: 11px; color: var(--navy); letter-spacing: .03em; }
.inv-seal .t2 { font-size: 8px; letter-spacing: .12em; color: var(--gold); margin-top: 2px; }
.inv-seal.paid { border-color: var(--success); }
.inv-seal.paid .t2 { color: var(--success); }
.inv-seal.pending { border-color: var(--alert); }
.inv-seal.pending .t2 { color: var(--alert); }

.inv-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.inv-meta .block .k { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--slate); margin-bottom: 3px; }
.inv-meta .block .v { font-size: 14px; font-weight: 600; }
.inv-meta .block .v.mono { font-family: 'IBM Plex Mono', monospace; }

table.inv-items { width: 100%; border-collapse: collapse; margin-bottom: 4px; }
table.inv-items th { background: var(--navy); color: #fff; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 9px 12px; }
table.inv-items th:last-child, table.inv-items td:last-child { text-align: right; }
table.inv-items td { padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
table.inv-items tr.total-row td { border-top: 2px solid var(--navy); border-bottom: none; font-weight: 700; font-size: 15px; color: var(--navy); padding-top: 13px; }

.inv-footer { display: flex; justify-content: space-between; margin-top: 26px; gap: 20px; }
.inv-footer .bank .k { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--slate); margin-bottom: 6px; }
.inv-footer .bank .row { font-size: 11.5px; margin-bottom: 2px; }
.inv-footer .bank .row b { color: var(--ink); }
.inv-note { margin-top: 22px; font-size: 10.5px; color: var(--slate); border-top: 1px solid var(--line); padding-top: 12px; text-align: center; }

@media print {
    body { background: #fff; }
    body * { visibility: hidden; }
    #invoice-print, #invoice-print * { visibility: visible; }
    #invoice-print { position: absolute; left: 0; top: 0; width: 100%; padding: 0; }
    @page { margin: 14mm; }
}

/* ---------------------------------------------------------------
   RESPONSIVE
   --------------------------------------------------------------- */
@media (max-width: 980px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
    .field.span-2 { grid-column: span 1; }
    .calc-strip { grid-template-columns: repeat(2, 1fr); }
    .inst-row { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    #app.active { flex-direction: column; }
    .sidebar {
        width: 100%; height: auto; position: sticky; top: 0; z-index: 50;
        flex-direction: row; align-items: center; justify-content: space-between;
        padding: 12px 14px; gap: 10px;
    }
    .brand { border: none; margin: 0; padding: 0; }
    .brand .tag { display: none; }
    #sidebar-nav { display: flex; flex-direction: row; gap: 4px; flex: 1; justify-content: center; }
    .nav-item { width: auto; padding: 9px; margin-bottom: 0; justify-content: center; }
    .nav-item span.label { display: none; }
    .sidebar-footer { display: flex; margin: 0; padding: 0; border: none; }
    .sidebar-footer .next-no, .sidebar-footer .next-no-val { display: none; }
    .lock-btn { width: auto; padding: 9px; border-radius: 8px; }
    .lock-btn span { display: none; }
    .main { padding: 22px 18px 50px; }
    .page-head { flex-direction: column; align-items: flex-start; }
}
