/* ============================================================
   SMU Student Portal — Components
   Tokens-only. Buttons, fields, cards, tables, badges, tabs,
   steppers, timeline, modal, toast, alert, dropzone, qr, etc.
   ============================================================ */

/* ---- Buttons ---- */
.btn { display:inline-flex; align-items:center; justify-content:center; gap:.45rem; font-weight:600; font-size:.86rem; line-height:1; padding:.6rem 1rem; border-radius:var(--r-sm); border:1px solid transparent; cursor:pointer; transition:background .15s,border-color .15s,opacity .15s; white-space:nowrap; text-decoration:none; }
.btn:hover { text-decoration:none; }
.btn--primary { background:var(--primary); color:var(--on-primary); }
.btn--primary:hover { background:var(--primary-hover); }
.btn--ghost { background:transparent; border-color:var(--border-strong); color:var(--text); }
.btn--ghost:hover { background:var(--surface-2); }
.btn--subtle { background:var(--surface-2); color:var(--text); }
.btn--subtle:hover { background:var(--surface-3); }
.btn--danger { background:var(--danger); color:#fff; }
.btn--sm { padding:.4rem .7rem; font-size:.78rem; }
.btn--lg { padding:.75rem 1.3rem; font-size:.95rem; }
.btn--icon { padding:.5rem; }
.btn--block { width:100%; }
.btn:disabled { opacity:.5; cursor:not-allowed; }

/* ---- Fields ---- */
.field { display:flex; flex-direction:column; gap:.35rem; margin-bottom:var(--s4); }
.field > label { font-size:.8rem; font-weight:600; }
.field .req { color:var(--danger); }
.input,.select,.textarea { width:100%; background:var(--surface); border:1px solid var(--border-strong); border-radius:var(--r-sm); padding:.55rem .7rem; font-size:.88rem; color:var(--text); transition:border-color .15s,box-shadow .15s; }
.input::placeholder,.textarea::placeholder { color:var(--text-subtle); }
.input:focus,.select:focus,.textarea:focus { outline:none; border-color:var(--primary); box-shadow:0 0 0 3px var(--ring); }
.textarea { min-height:92px; resize:vertical; }
.field .help { font-size:.74rem; color:var(--text-subtle); }
.field--error .input,.field--error .select,.field--error .textarea { border-color:var(--danger); }
.field--error .help { color:var(--danger); }
.form-grid { display:grid; grid-template-columns:1fr 1fr; gap:0 var(--s4); }
@media (max-width:640px){ .form-grid { grid-template-columns:1fr; } }
.checkbox,.radio { display:inline-flex; align-items:center; gap:.5rem; font-size:.86rem; cursor:pointer; }
.switch { position:relative; width:40px; height:22px; background:var(--border-strong); border-radius:var(--r-pill); cursor:pointer; transition:background .15s; flex:none; }
.switch::after { content:''; position:absolute; top:2px; left:2px; width:18px; height:18px; border-radius:50%; background:#fff; transition:left .15s; }
.switch.is-on { background:var(--primary); }
.switch.is-on::after { left:20px; }

/* ---- Card ---- */
.card { background:var(--surface); border:1px solid var(--border); border-radius:var(--r); box-shadow:var(--shadow-sm); }
.card__head { padding:var(--s4) var(--s5); border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; gap:var(--s3); }
.card__head h3 { font-size:.98rem; }
.card__body { padding:var(--s5); }
.card__foot { padding:var(--s4) var(--s5); border-top:1px solid var(--border); }

/* ---- Stat tile ---- */
.stat { background:var(--surface); border:1px solid var(--border); border-radius:var(--r); padding:var(--s4) var(--s5); display:flex; flex-direction:column; gap:.2rem; }
.stat__label { font-size:.72rem; color:var(--text-muted); text-transform:uppercase; letter-spacing:.04em; }
.stat__value { font-size:1.55rem; font-weight:700; line-height:1.1; }
.stat__delta { font-size:.74rem; color:var(--text-muted); }
.stat__delta.up { color:var(--success); } .stat__delta.down { color:var(--danger); }

/* ---- Badge / status ---- */
.badge { display:inline-flex; align-items:center; gap:.35rem; font-size:.72rem; font-weight:600; padding:.2rem .55rem; border-radius:var(--r-pill); }
.badge::before { content:''; width:6px; height:6px; border-radius:50%; background:currentColor; }
.badge--neutral { color:var(--text-muted); background:var(--surface-2); }
.badge--pending,.badge--missing { color:var(--warning); background:var(--warning-bg); }
.badge--approved,.badge--paid,.badge--ready,.badge--valid,.badge--published,.badge--success,.badge--pass { color:var(--success); background:var(--success-bg); }
.badge--rejected,.badge--failed,.badge--revoked,.badge--fail { color:var(--danger); background:var(--danger-bg); }
.badge--urgent { color:var(--danger); background:var(--danger-bg); }
.badge--info { color:var(--info); background:var(--info-bg); }
.badge--no-dot::before { display:none; }

/* ---- Tag / avatar ---- */
.tag { font-size:.72rem; background:var(--surface-2); color:var(--text-muted); border-radius:var(--r-sm); padding:.15rem .5rem; }
.avatar { width:32px; height:32px; border-radius:50%; background:var(--surface-3); display:inline-flex; align-items:center; justify-content:center; font-size:.78rem; font-weight:700; color:var(--text-muted); overflow:hidden; flex:none; }

/* ---- Key-value (profile / document fields) ---- */
.kv { display:grid; grid-template-columns:minmax(130px,190px) 1fr; gap:.45rem .9rem; font-size:.86rem; }
.kv dt { color:var(--text-muted); } .kv dd { color:var(--text); }
/* Phones: stack label over value so long values (reg no, names, issuer) don't cram into a narrow column */
@media (max-width:560px){
  .kv { grid-template-columns:1fr; gap:0; }
  .kv dt { color:var(--text-subtle); font-size:.76rem; margin-top:.7rem; }
  .kv dt:first-of-type { margin-top:0; }
  .kv dd { font-size:.92rem; line-height:1.35; font-weight:500; }
}

/* ---- Table ---- */
.table-wrap { overflow:auto; border:1px solid var(--border); border-radius:var(--r); background:var(--surface); }
.table { width:100%; border-collapse:collapse; font-size:.84rem; }
.table th { text-align:left; font-size:.68rem; text-transform:uppercase; letter-spacing:.04em; color:var(--text-muted); font-weight:600; padding:.6rem .85rem; border-bottom:1px solid var(--border); background:var(--surface-2); white-space:nowrap; }
.table td { padding:.6rem .85rem; border-bottom:1px solid var(--border); }
.table tbody tr:last-child td { border-bottom:0; }
.table tbody tr:hover { background:var(--surface-2); }
.table tbody tr.is-rowlink { cursor:pointer; }
.table__actions { display:flex; gap:.35rem; }
.table .num { text-align:right; font-variant-numeric:tabular-nums; }
.empty-state { text-align:center; padding:var(--s8) var(--s5); color:var(--text-muted); }
.empty-state .ico { font-size:2rem; opacity:.5; margin-bottom:var(--s2); }
.pagination { display:flex; align-items:center; gap:.3rem; justify-content:flex-end; padding:var(--s3) var(--s4); font-size:.8rem; }
.pagination button { border:1px solid var(--border); background:var(--surface); border-radius:6px; padding:.3rem .6rem; cursor:pointer; color:var(--text); }
.pagination button.is-active { background:var(--primary); color:var(--on-primary); border-color:var(--primary); }

/* ---- Tabs / breadcrumb ---- */
.tabs { display:flex; gap:.25rem; border-bottom:1px solid var(--border); overflow:auto; }
.tab { padding:.6rem .9rem; font-size:.85rem; font-weight:600; color:var(--text-muted); border-bottom:2px solid transparent; cursor:pointer; white-space:nowrap; background:none; border-top:0; border-left:0; border-right:0; }
.tab.is-active { color:var(--primary); border-bottom-color:var(--primary); }
.breadcrumb { display:flex; flex-wrap:wrap; gap:.4rem; font-size:.78rem; color:var(--text-muted); }
.breadcrumb a { color:var(--text-muted); }
.breadcrumb .sep { color:var(--text-subtle); }

/* ---- Stepper (horizontal desk timeline) ---- */
.stepper { display:flex; }
.step { flex:1; display:flex; flex-direction:column; align-items:center; gap:.4rem; text-align:center; position:relative; font-size:.72rem; color:var(--text-muted); }
.step::before { content:''; position:absolute; top:15px; left:-50%; width:100%; height:2px; background:var(--border); z-index:0; }
.step:first-child::before { display:none; }
.step__dot { width:32px; height:32px; border-radius:50%; background:var(--surface-2); border:2px solid var(--border); display:flex; align-items:center; justify-content:center; font-weight:700; font-size:.8rem; z-index:1; }
.step.is-done .step__dot { background:var(--primary); border-color:var(--primary); color:var(--on-primary); }
.step.is-done::before { background:var(--primary); }
.step.is-active .step__dot { border-color:var(--primary); color:var(--primary); }
.step.is-active::before { background:var(--primary); }
.step.is-reject .step__dot { border-color:var(--danger); color:var(--danger); }

/* ---- Timeline (vertical, audit/activity) ---- */
.timeline { position:relative; padding-left:1.5rem; }
.timeline__item { position:relative; padding-bottom:var(--s4); }
.timeline__item:last-child { padding-bottom:0; }
.timeline__item::before { content:''; position:absolute; left:-1.5rem; top:3px; width:11px; height:11px; border-radius:50%; background:var(--primary); border:2px solid var(--surface); z-index:1; }
.timeline__item::after { content:''; position:absolute; left:calc(-1.5rem + 5px); top:14px; bottom:-3px; width:2px; background:var(--border); }
.timeline__item:last-child::after { display:none; }
.timeline__meta { font-size:.74rem; color:var(--text-subtle); }

/* ---- Alert ---- */
.alert { display:flex; gap:.6rem; padding:.8rem 1rem; border-radius:var(--r-sm); font-size:.84rem; border:1px solid var(--border); }
.alert--info { background:var(--info-bg); border-color:transparent; }
.alert--success { background:var(--success-bg); border-color:transparent; }
.alert--warning { background:var(--warning-bg); border-color:transparent; }
.alert--danger { background:var(--danger-bg); border-color:transparent; }

/* ---- Modal ---- */
.modal-backdrop { position:fixed; inset:0; background:rgba(8,16,20,.5); display:none; align-items:center; justify-content:center; padding:var(--s4); z-index:100; }
.modal-backdrop.is-open { display:flex; }
.modal { background:var(--surface); border:1px solid var(--border); border-radius:var(--r-lg); box-shadow:var(--shadow-lg); width:100%; max-width:480px; max-height:90vh; overflow:auto; }
.modal__head { padding:var(--s4) var(--s5); border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; }
.modal__body { padding:var(--s5); }
.modal__foot { padding:var(--s4) var(--s5); border-top:1px solid var(--border); display:flex; justify-content:flex-end; gap:.5rem; }

/* ---- Toast ---- */
.toast-host { position:fixed; right:var(--s4); bottom:var(--s4); display:flex; flex-direction:column; gap:.5rem; z-index:200; }
.toast { background:var(--surface); border:1px solid var(--border); border-left:4px solid var(--primary); border-radius:var(--r-sm); box-shadow:var(--shadow); padding:.7rem .9rem; font-size:.84rem; min-width:240px; max-width:340px; }
.toast--danger { border-left-color:var(--danger); }
.toast--warning { border-left-color:var(--warning); }

/* ---- Dropzone ---- */
.dropzone { border:2px dashed var(--border-strong); border-radius:var(--r); padding:var(--s6); text-align:center; color:var(--text-muted); background:var(--surface-2); cursor:pointer; transition:border-color .15s,color .15s; }
.dropzone:hover { border-color:var(--primary); color:var(--primary); }
.dropzone .ico { font-size:1.6rem; margin-bottom:.3rem; }

/* ---- QR (always on white for scannability) ---- */
.qr { display:inline-flex; padding:.4rem; background:#fff; border-radius:8px; border:1px solid #e5e5e5; }
.qr canvas,.qr img { display:block; }

/* ---- Skeleton ---- */
.skeleton { background:linear-gradient(90deg,var(--surface-2),var(--surface-3),var(--surface-2)); background-size:200% 100%; animation:sk 1.2s ease-in-out infinite; border-radius:6px; height:1rem; }
@keyframes sk { to { background-position:-200% 0; } }

/* ---- Chart wrappers (charts.js draws SVG inside) ---- */
.chart { width:100%; }
/* clip to the SVG box — a miscalculated chart must never bleed over other UI */
.chart svg { display:block; width:100%; height:auto; overflow:hidden; }
.legend { display:flex; gap:1rem; flex-wrap:wrap; font-size:.74rem; color:var(--text-muted); }
.legend span { display:inline-flex; align-items:center; gap:.35rem; }
.legend i { width:10px; height:10px; border-radius:3px; display:inline-block; }

/* ---- Section header ---- */
.sec-title { font-size:.72rem; text-transform:uppercase; letter-spacing:.05em; color:var(--text-subtle); margin-bottom:var(--s3); }
