:root {
  --bg: #f1f5f9; --card: #ffffff; --card-alt: #f8fafc; --border: #e2e8f0; --border2: #cbd5e1;
  --text: #0f172a; --muted: #64748b;
  --accent: #0f294d; --accent-fg: #0f294d; --accent-soft: #dbeafe;
  --topbar-bg: #08172e; --topbar-border: #d97706;
  --green: #bbf7d0; --yellow: #fef08a; --orange: #fed7aa; --white: #f8fafc;
}
body[data-element="sea"] {
  --accent: #0f294d; --accent-fg: #0f294d; --accent-soft: #dbeafe;
  --topbar-bg: #08172e; --topbar-border: #d97706;
}
body[data-element="air"] {
  --accent: #0284c7; --accent-fg: #0369a1; --accent-soft: #e0f2fe;
  --topbar-bg: #0c2d48; --topbar-border: #38bdf8;
}
body[data-element="army"] {
  --accent: #3f6212; --accent-fg: #365314; --accent-soft: #ecfccb;
  --topbar-bg: #1c2614; --topbar-border: #84cc16;
}
body[data-theme="dark"] {
  --bg: #0b1120; --card: #111827; --card-alt: #1e293b; --border: #1f2937; --border2: #374151;
  --text: #f1f5f9; --muted: #94a3b8;
  --green: #14532d; --yellow: #713f12; --orange: #7c2d12; --white: #1e293b;
}
body[data-theme="dark"][data-element="sea"] { --accent-fg: #93c5fd; --accent-soft: #172554; }
body[data-theme="dark"][data-element="air"] { --accent-fg: #7dd3fc; --accent-soft: #0c4a6e; }
body[data-theme="dark"][data-element="army"] { --accent-fg: #bef264; --accent-soft: #1a2e05; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 14px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }

.topbar { height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; background: var(--topbar-bg); color: #f8fafc; border-bottom: 3px solid var(--topbar-border); }
.brand { display: flex; gap: 10px; align-items: center; }
.crest { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; font-size: 18px; border: 1px solid rgba(255,255,255,.18); }
.brand-title { font-weight: 700; }
.brand-sub { font-size: 11px; color: #cbd5e1; }
.top-center { display: flex; gap: 8px; align-items: center; }
.top-center select { background: rgba(15,23,42,.65); color: #fff; border: 1px solid rgba(255,255,255,.22); border-radius: 6px; padding: 6px 8px; min-width: 260px; }
.pill { background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--topbar-border); }
.top-actions { display: flex; gap: 6px; }

.layout { display: flex; height: calc(100vh - 58px); }
.sidebar { width: 236px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border); padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav { text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text); }
.nav:hover { background: var(--bg); }
.nav.active { background: var(--accent-soft); color: var(--accent-fg); font-weight: 700; }
.nav-div { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); padding: 12px 10px 4px; }
.legend { margin-top: auto; border-top: 1px solid var(--border); padding-top: 10px; font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
.legend-title { font-weight: 700; color: var(--text); font-size: 11px; }
.sw { display: inline-block; width: 11px; height: 11px; border-radius: 3px; border: 1px solid #94a3b8; margin-right: 6px; vertical-align: middle; }
.sw.green, .st-green { background: var(--green); } .sw.yellow, .st-yellow { background: var(--yellow); }
.sw.orange, .st-orange { background: var(--orange); } .sw.white, .st-white { background: var(--white); }

main { flex: 1; min-width: 0; overflow: auto; padding: 18px 22px; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.head h1 { font-size: 20px; margin: 0 0 4px; }
.head p { margin: 0; color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.btn { border: 1px solid var(--border2); background: var(--card); color: var(--text); border-radius: 7px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(.95); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-dark { background: rgba(15,23,42,.55); border-color: rgba(255,255,255,.22); color: #f8fafc; }
.btn-danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
input, select, textarea { font: inherit; border: 1px solid var(--border2); border-radius: 6px; padding: 6px 8px; background: var(--card); color: var(--text); }
.w100 { width: 100%; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 14px; }
.bar { height: 8px; background: #e2e8f0; border-radius: 99px; overflow: hidden; margin: 6px 0; }
.bar > div { height: 100%; background: var(--accent); }
.kv { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.kv b { color: var(--text); }
.big { font-size: 22px; font-weight: 800; }

.tbl-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--card); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { background: var(--card-alt); text-align: left; padding: 8px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border2); white-space: nowrap; position: sticky; top: 0; }
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 700; border: 1px solid rgba(0,0,0,.08); }
.mand { color: #ef4444; font-weight: 800; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; flex-wrap: wrap; }
.tab { border: 0; background: none; padding: 8px 12px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent-fg); border-bottom-color: var(--accent); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; }

/* Session matrix */
.matrix-wrap { overflow: auto; max-height: calc(100vh - 200px); border: 1px solid var(--border2); border-radius: 8px; background: var(--card); }
table.matrix { border-collapse: separate; border-spacing: 0; font-size: 11.5px; }
.matrix th, .matrix td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px 6px; min-width: 132px; max-width: 150px; vertical-align: top; }
.matrix thead th { position: sticky; top: 0; z-index: 3; background: var(--topbar-bg); color: #f8fafc; text-align: center; }
.matrix thead tr.notes th { top: 40px; background: #1e293b; color: #fde68a; font-weight: 500; cursor: pointer; }
.matrix .sticky { position: sticky; left: 0; z-index: 2; background: var(--card-alt); min-width: 110px; font-weight: 700; }
.matrix thead .sticky { z-index: 4; background: var(--topbar-bg); }
.matrix tr.lvl td { background: var(--accent); color: #fff; font-weight: 700; }
.matrix tr.lvl td.sticky { background: var(--accent); }
.cell { cursor: pointer; height: 52px; }
.cell:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.cell.empty { color: var(--muted); opacity: .4; text-align: center; vertical-align: middle; }
.cell.na { background: rgba(220,38,38,.18); }
.cell.special { background: var(--card-alt); }
.eo { font-weight: 700; }
.ttl { color: var(--text); opacity: .85; margin-top: 1px; line-height: 1.2; }
.meta { color: var(--muted); font-size: 10px; margin-top: 2px; }
th.special-col { background: #7c2d12 !important; }

/* Printable */
.sheet { background: #fff; color: #0f172a; border: 1px solid var(--border2); border-radius: 8px; padding: 26px 32px; max-width: 920px; margin: 0 auto; }
.sheet table.tbl th { background: #f8fafc; color: #475569; }
.sheet table.tbl td, .sheet input, .sheet textarea { background: #fff; color: #0f172a; }
.sheet .muted { color: #64748b; }
.sheet-head { display: flex; justify-content: space-between; border-bottom: 2px solid #0f172a; padding-bottom: 8px; margin-bottom: 10px; }
.sheet-unit { font-size: 20px; font-weight: 800; text-transform: uppercase; }
.sec { background: #0f172a; color: #fff; font-size: 12px; font-weight: 700; text-transform: uppercase; padding: 4px 8px; margin: 12px 0 6px; }

/* Modal & toast */
.backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.hidden { display: none !important; }
.modal { background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 10px; width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.fg { margin-bottom: 10px; }
.fg label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 3px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mfoot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 6px; z-index: 60; }
.toast { background: #0f172a; color: #fff; padding: 9px 13px; border-radius: 8px; font-size: 13px; max-width: 420px; }
.toast.err { background: #b91c1c; }
.muted { color: var(--muted); }

.print-only { display: none; }
/* Certificates */
.cert-paper {
  background: #fff; width: 100%; max-width: 980px; aspect-ratio: 11 / 8.5;
  margin: 0 auto; padding: 62px; box-shadow: 0 4px 18px rgba(15,23,42,.12);
}
.cert-page {
  background: #fff; color: #000; width: 100%; height: 100%;
  padding: 28px 36px; border: 5px solid #000;
  display: flex; flex-direction: column; justify-content: space-between;
  font-family: "Trebuchet MS", "Gill Sans", "Segoe UI", sans-serif;
}
.cert-page.border-solid-thin { border: 2px solid #000; }
.cert-page.border-solid-thick { border: 5px solid #000; }
.cert-page.border-double { border: 7px double #000; }
.cert-page.border-corners { border: 5px solid #000; outline: 2px solid #000; outline-offset: -12px; }
.cert-page.border-filigree { position: relative; border: 2px solid #0f172a; outline: 1px solid #0f172a; outline-offset: -7px; }
.cert-filigree-c { position: absolute; width: 48px; height: 48px; pointer-events: none; }
.cert-filigree-c.tl { top: 4px; left: 4px; }
.cert-filigree-c.tr { top: 4px; right: 4px; transform: scaleX(-1); }
.cert-filigree-c.bl { bottom: 4px; left: 4px; transform: scaleY(-1); }
.cert-filigree-c.br { bottom: 4px; right: 4px; transform: scale(-1, -1); }
.cert-page.border-none { border: 1px dashed #cbd5e1; }
.cert-service { font-family: Georgia, "Times New Roman", serif; text-align: center; color: #1e293b; }
.cert-svc-h1 { font-size: 34px; font-weight: 700; letter-spacing: 5px; line-height: 1.05; }
.cert-svc-h2 { font-size: 21px; font-style: italic; letter-spacing: 4px; margin-top: 2px; }
.cert-svc-pres { font-size: 13px; font-weight: 700; color: #0f294d; margin: 8px 0 2px; }
.cert-svc-script { font-family: "Snell Roundhand", "Apple Chancery", "Brush Script MT", cursive; line-height: 1.12; color: #0f172a; }
.cert-svc-unit { font-size: 24px; font-style: italic; letter-spacing: 3px; margin: 4px 0 10px; }
.cert-svc-quote { font-size: 13.5px; font-weight: 600; max-width: 660px; margin: 0 auto 8px; line-height: 1.4; }
.cert-svc-farewell { font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.cert-svc-bottom { display: grid; grid-template-columns: 1fr auto 1fr; gap: 24px; align-items: end; margin-top: 6px; }
.cert-svc-crest { max-height: 82px; max-width: 90px; object-fit: contain; }
.cert-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; }
.cert-title-l, .cert-title-r { font-size: 20px; font-weight: 800; line-height: 1.25; text-align: center; letter-spacing: .3px; }
.cert-crests { height: 116px; width: auto; object-fit: contain; display: block; }
.cert-sub { text-align: center; font-size: 15px; font-weight: 700; line-height: 1.3; margin-top: 4px; }
.cert-sub-split { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; text-align: center; font-size: 15px; font-weight: 700; }
.cert-name { text-align: center; font-size: 40px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; margin: 6px 0; }
.cert-bilingual { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; text-align: center; font-size: 14.5px; font-weight: 700; line-height: 1.35; }
.cert-award { text-align: center; font-size: 32px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; margin: 4px 0 8px; }
.cert-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 90px; align-items: end; margin-top: 10px; }
.cert-sig-col { text-align: center; }
.cert-sig-slot { height: 54px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px; }
.cert-sig-slot img { max-height: 54px; max-width: 220px; object-fit: contain; }
.cert-date-val { font-size: 16px; font-weight: 700; }
.cert-line { border-top: 2px solid #000; padding-top: 5px; font-size: 14px; font-weight: 700; }

@media print {
  .no-print { display: none !important; }
  .print-only { display: inline !important; }
  .layout, main { height: auto; overflow: visible; padding: 0; display: block; }
  body { background: #fff; }
  .sheet { border: 0; padding: 0; max-width: none; }
  .cert-page { box-shadow: none; width: 10in; height: 7.5in; max-width: none; margin: 0 auto; page-break-after: avoid; }
}
