:root {
  --navy: #17345b;
  --navy-2: #254c7f;
  --sky: #eaf3fb;
  --blue: #287bc1;
  --teal: #0d8b7a;
  --pink: #e97a9d;
  --gold: #dba63b;
  --ink: #1d2939;
  --muted: #667085;
  --line: #dce4ec;
  --paper: #ffffff;
  --canvas: #f4f7fa;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(23, 52, 91, 0.08);
}

* { box-sizing: border-box; }
html { font-family: Inter, "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.app-shell[hidden] { display: none; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 18px; color: #fff; background: linear-gradient(165deg, var(--navy), #0e2747 75%); display: flex; flex-direction: column; z-index: 10; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 32px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px 13px 13px 3px; background: linear-gradient(145deg, #69b9e8, #3777b7); font: 800 24px/1 Georgia, serif; }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .02em; font-size: 17px; }
.brand small { color: #b9cee5; font-size: 11px; margin-top: 3px; }
nav { display: grid; gap: 24px; }
.nav-group { display: grid; gap: 6px; }
.nav-group[hidden] { display: none; }
.nav-section-label { padding: 0 12px 3px; color: #93aec9; font-size: 10px; font-weight: 700; letter-spacing: .04em; }
nav a { display: block; padding: 11px 12px; border-radius: 10px; color: #cbd8e7; text-decoration: none; }
nav a:hover, nav a.active { background: rgba(255,255,255,.11); color: #fff; }
nav a.active { box-shadow: inset 3px 0 0 #70bce8; }
.nav-copy, .nav-copy strong, .nav-copy small { display: block; }
.nav-copy strong { font-size: 13px; font-weight: 650; }
.nav-copy small { margin-top: 3px; color: #93aec9; font-size: 10px; line-height: 1.4; }
nav a.active .nav-copy small { color: #c8dbed; }
.menu-close { display: none; width: 40px; height: 40px; flex: 0 0 40px; border: 0; border-radius: 50%; background: rgba(255,255,255,.1); color: #fff; font-size: 25px; line-height: 1; cursor: pointer; }
.sidebar-backdrop { display: none; }
.sidebar-note { margin-top: auto; padding: 15px; border: 1px solid rgba(255,255,255,.14); border-radius: 11px; background: rgba(255,255,255,.06); }
.sidebar-note strong, .sidebar-note span { display: block; }
.sidebar-note strong { font-size: 12px; margin-bottom: 4px; }
.sidebar-note span { color: #b9cee5; font-size: 11px; line-height: 1.55; }

main { min-width: 0; }
.topbar { height: 76px; padding: 0 34px; display: flex; align-items: center; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.92); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 8; }
#page-heading strong, #page-heading span { display: block; }
#page-heading strong { font-size: 17px; }
#page-heading span { color: var(--muted); font-size: 12px; margin-top: 3px; }
.user-chip { margin-left: auto; display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 650; }
.avatar { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 50%; background: var(--sky); color: var(--navy); }
.sign-out { border: 0; border-left: 1px solid var(--line); padding: 3px 0 3px 10px; background: transparent; color: var(--muted); font-size: 11px; cursor: pointer; }
.sign-out:hover { color: var(--danger); }
.mobile-menu { display: none; border: 0; background: transparent; font-size: 21px; margin-right: 10px; }
.dev-switcher { padding: 8px 34px; background: #fff7d6; border-bottom: 1px solid #ecd678; color: #6b5312; font-size: 12px; text-align: right; }
.dev-switcher select { margin-left: 5px; padding: 4px 8px; border: 1px solid #d6bd55; border-radius: 6px; background: #fff; }
.content { max-width: 1280px; margin: 0 auto; padding: 32px 34px 60px; }

.loading-card, .empty, .error-card { min-height: 180px; display: grid; place-items: center; align-content: center; gap: 12px; text-align: center; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); color: var(--muted); }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid #d7e4ef; border-top-color: var(--blue); animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-card strong { color: var(--danger); }

.hero-row { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.hero-row h1 { margin: 0 0 5px; font-size: 25px; letter-spacing: -.02em; }
.hero-row p { margin: 0; color: var(--muted); font-size: 14px; }
.progress-wrap { min-width: 250px; text-align: right; }
.progress-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.progress-label strong { color: var(--navy); }
.progress-bar { height: 8px; background: #dde7ef; border-radius: 20px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: linear-gradient(90deg, #2e84c5, #3ea892); border-radius: inherit; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.segmented { display: flex; flex-wrap: wrap; padding: 3px; background: #e8eef4; border-radius: 10px; }
.segmented button { padding: 7px 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }
.segmented button.active { color: var(--navy); background: #fff; box-shadow: 0 1px 4px rgba(23,52,91,.12); font-weight: 700; }

.application-list { display: grid; gap: 9px; }
.application-row { width: 100%; display: grid; grid-template-columns: 72px minmax(180px, 1.3fr) minmax(130px, .8fr) 105px 26px; gap: 14px; align-items: center; padding: 15px 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); text-align: left; cursor: pointer; box-shadow: 0 2px 7px rgba(23,52,91,.03); transition: .15s ease; }
.application-row:hover { transform: translateY(-1px); border-color: #a9bfd4; box-shadow: var(--shadow); }
.code { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.applicant strong, .applicant span { display: block; }
.applicant strong { font-size: 14px; }
.applicant span, .group-label { color: var(--muted); font-size: 12px; margin-top: 3px; }
.chevron { color: #98a7b7; font-size: 20px; }
.badge { display: inline-flex; width: fit-content; align-items: center; padding: 4px 8px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge.todo { color: #526477; background: #edf1f5; }
.badge.draft { color: #8b6512; background: #fff3cb; }
.badge.submitted, .badge.Pass { color: #087460; background: #dff4ee; }
.badge.Grey { color: #536170; background: #e5e9ed; }
.badge.Fail { color: #9a2d2d; background: #fce5e5; }

.back { border: 0; background: transparent; color: var(--blue); padding: 0; margin-bottom: 15px; cursor: pointer; font-size: 13px; }
.detail-header { display: flex; justify-content: space-between; gap: 20px; align-items: start; margin-bottom: 18px; }
.detail-header h1 { margin: 0 0 5px; font-size: 23px; }
.detail-header p { color: var(--muted); margin: 0; font-size: 13px; }
.application-flags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.recommendation-badge { display: inline-flex; align-items: center; width: fit-content; padding: 6px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.recommendation-badge.has-letter { color: #176b5d; background: #dff4ee; border: 1px solid #9ed9ca; }
.recommendation-badge.no-letter { color: #667085; background: #edf1f5; border: 1px solid #dce4ec; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 355px; gap: 18px; align-items: start; }
.stack { display: grid; gap: 14px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 20px; box-shadow: 0 3px 10px rgba(23,52,91,.035); }
.card h2 { margin: 0 0 16px; font-size: 15px; color: var(--navy); }
.profile-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 13px 18px; }
.field small, .field strong { display: block; }
.field small { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.field strong { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.answer { padding: 15px 0; border-top: 1px solid #edf1f5; }
.answer:first-of-type { border-top: 0; padding-top: 0; }
.answer:last-child { padding-bottom: 0; }
.answer h3 { font-size: 13px; margin: 0 0 8px; }
.answer p { margin: 0; line-height: 1.72; font-size: 13px; white-space: pre-wrap; }
.info-list { display: grid; gap: 0; }
.info-row { padding: 13px 0; border-top: 1px solid #edf1f5; }
.info-row:first-child { border-top: 0; padding-top: 0; }
.info-row:last-child { padding-bottom: 0; }
.info-row small { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.info-row p { margin: 0; line-height: 1.68; font-size: 13px; white-space: pre-wrap; }
.activity { padding: 11px 13px; border-left: 3px solid #7bb7de; background: #f5f9fc; border-radius: 0 8px 8px 0; margin-bottom: 9px; }
.activity strong, .activity span { display: block; }
.activity strong { font-size: 13px; }
.activity span { color: var(--muted); margin-top: 4px; line-height: 1.55; font-size: 12px; }
.document-card { padding: 0; overflow: hidden; }
.document-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 17px 18px; border-bottom: 1px solid var(--line); }
.document-heading h2 { margin: 0 0 3px; }
.document-heading small { color: var(--muted); font-size: 10px; }
.document-actions { display: flex; gap: 7px; flex-shrink: 0; }
.document-actions .btn { padding: 7px 10px; text-decoration: none; white-space: nowrap; }
.document-tabs { display: grid; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); background: #f7f9fb; }
.document-tabs button { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; min-height: 50px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--muted); text-align: left; font-size: 11px; cursor: pointer; }
.document-tabs button.active { border-color: #bcd4e8; background: #fff; color: var(--navy); font-weight: 700; box-shadow: 0 1px 4px rgba(23,52,91,.08); }
.document-tabs button.recommendation-document { border-color: #87cbbb; color: #176b5d; background: #effaf6; font-weight: 700; }
.document-tabs button.recommendation-document.active { border-color: #176b5d; box-shadow: inset 0 0 0 1px #176b5d; }
.document-tab-copy { min-width: 0; }
.document-tab-copy strong, .document-tab-copy small { display: block; white-space: normal; }
.document-tab-copy small { margin-top: 4px; color: #527066; font-weight: 500; line-height: 1.45; }
.document-tab-open { flex: 0 0 auto; color: var(--blue); font-weight: 700; white-space: nowrap; }
.recommendation-document .document-tab-open { color: #176b5d; }
.document-missing { padding: 11px 12px; border: 1px solid #ead58e; border-radius: 9px; color: #8b6512; background: #fff3cb; font-size: 11px; font-weight: 700; }
.document-viewport { height: min(72vh, 760px); min-height: 520px; background: #eef2f6; }
.document-frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.document-notice { padding: 9px 12px; color: #735b1e; background: #fff3cb; border-bottom: 1px solid #ead58e; font-size: 10px; line-height: 1.5; }
.document-notice a { color: #62480b; font-weight: 800; }
.document-notice + .document-frame { height: calc(100% - 49px); }
.document-fallback { height: 100%; display: grid; place-items: center; align-content: center; gap: 7px; padding: 25px; text-align: center; color: var(--muted); }
.document-fallback strong { color: var(--navy); }
.document-fallback span { max-width: 390px; font-size: 12px; line-height: 1.55; }
.document-continue { display: none; }
.document-card.expanded { position: fixed; inset: 12px; z-index: 100; display: flex; flex-direction: column; box-shadow: 0 20px 70px rgba(7,22,42,.35); }
.document-card.expanded .document-viewport { height: auto; min-height: 0; flex: 1; }
body.viewer-open { overflow: hidden; }
.review-card { position: sticky; top: 94px; }
.review-card .privacy-note { padding: 10px 12px; background: var(--sky); border-radius: 8px; color: #355d80; font-size: 11px; line-height: 1.5; margin-bottom: 16px; }
.decision-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 16px; }
.decision-option input { position: absolute; opacity: 0; }
.decision-option span { display: grid; place-items: center; height: 42px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); font-size: 12px; cursor: pointer; }
.decision-option input:checked + span { border-color: var(--blue); background: #eaf5fd; color: var(--navy); box-shadow: inset 0 0 0 1px var(--blue); font-weight: 700; }
.form-label { display: block; color: var(--muted); font-size: 11px; margin: 14px 0 7px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.check input { position: absolute; opacity: 0; }
.check span { display: inline-block; padding: 6px 9px; border-radius: 8px; background: #f0f3f6; color: #526477; font-size: 11px; cursor: pointer; }
.check input:checked + span { color: #145b90; background: #dfeffc; font-weight: 700; }
textarea { width: 100%; min-height: 115px; resize: vertical; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; outline: none; font-size: 12px; line-height: 1.55; }
textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(40,123,193,.12); }
input, select { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); outline: none; font-size: 12px; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(40,123,193,.12); }
.autosave { min-height: 18px; color: var(--muted); font-size: 10px; padding-top: 5px; }
.actions { display: grid; grid-template-columns: .8fr 1.2fr; gap: 8px; margin-top: 12px; }
.btn { border: 1px solid var(--line); border-radius: 9px; padding: 10px 13px; background: #fff; color: var(--navy); font-weight: 700; font-size: 12px; cursor: pointer; }
.btn.primary { border-color: var(--navy); background: var(--navy); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.submitted-box { padding: 15px; background: #e9f6f2; color: #176b5d; border-radius: 9px; font-size: 12px; line-height: 1.6; }
.partner-box { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.partner-box h3 { font-size: 12px; margin: 0 0 7px; }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.metric { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.metric small, .metric strong { display: block; }
.metric small { color: var(--muted); font-size: 11px; }
.metric strong { color: var(--navy); font-size: 25px; margin-top: 5px; }
.table-card { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { color: var(--muted); font-weight: 650; text-align: left; background: #f7f9fb; }
th, td { padding: 11px 10px; border-bottom: 1px solid #edf1f5; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mini-progress { width: 90px; height: 6px; background: #e4eaf0; border-radius: 10px; overflow: hidden; }
.mini-progress span { display: block; height: 100%; background: var(--teal); }
.section-title { margin: 26px 0 11px; font-size: 16px; }

.user-admin-grid { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 18px; align-items: start; }
.invite-card { position: sticky; top: 94px; }
.form-help { margin: -7px 0 17px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.roster-selection { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; padding: 10px 11px; border: 1px solid #bcd4e8; border-radius: 9px; background: #f2f8fd; }
.roster-selection[hidden], .manual-invite-fields[hidden] { display: none; }
.roster-selection strong { color: var(--navy); font-size: 12px; }
.roster-selection span { color: #355d80; font-size: 10px; white-space: nowrap; }
.manual-invite-fields { margin-top: 4px; }
.form-columns { display: grid; grid-template-columns: .8fr 1.35fr 1fr; gap: 8px; }
.invite-note { margin: 14px 0 10px; padding: 10px 11px; border-radius: 8px; background: var(--sky); color: #355d80; font-size: 10px; line-height: 1.5; }
.btn.full { width: 100%; }
.table-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.table-heading h2 { margin-bottom: 3px; }
.table-heading small { color: var(--muted); }
.user-actions { text-align: right; }
.text-button { border: 0; padding: 4px 5px; background: transparent; color: var(--blue); font-size: 11px; cursor: pointer; }
.text-button.danger { color: var(--danger); }
.text-button:disabled { opacity: .45; }

.auth-root { min-height: 100vh; background: linear-gradient(160deg, #f6f9fc, #eaf1f7); }
.auth-root[hidden] { display: none; }
.auth-layout { min-height: 100vh; display: grid; place-items: center; padding: 32px 18px; }
.auth-panel { display: grid; place-items: center; width: 100%; }
.auth-panel > div { width: min(100%, 430px); }
.auth-brand { justify-content: center; margin-bottom: 14px; color: var(--navy); }
.auth-brand small { color: var(--muted); }
.auth-access-note { margin: 0 0 22px; color: var(--muted); font-size: 12px; text-align: center; }
#clerk-sign-in { min-height: 420px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; transform: translateY(20px); opacity: 0; pointer-events: none; transition: .2s; padding: 11px 15px; border-radius: 9px; background: #152b49; color: #fff; box-shadow: var(--shadow); font-size: 12px; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: min(-82vw, -300px); width: min(82vw, 300px); padding: 22px 18px; transition: left .2s ease; box-shadow: 15px 0 30px rgba(0,0,0,.18); }
  .sidebar.open { left: 0; }
  .menu-close { display: grid; place-items: center; }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 9; border: 0; background: rgba(7,22,42,.42); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  body.menu-open { overflow: hidden; }
  .mobile-menu { display: block; }
  .content { padding: 23px 18px 45px; }
  .topbar { padding: 0 18px; }
  .detail-grid { display: flex; flex-direction: column; }
  .review-card { position: static; width: 100%; }
  .document-card:not(.expanded) .document-actions { display: none; }
  .document-card:not(.expanded) .document-viewport { display: none; }
  .document-card.expanded .document-viewport { display: block; height: auto; min-height: 0; flex: 1; }
  .document-continue { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; color: #355d80; background: var(--sky); border-top: 1px solid #cfe1f0; font-size: 11px; }
  .document-continue strong { color: var(--navy); font-size: 12px; white-space: nowrap; }
  .document-card.expanded .document-continue { display: none; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .user-admin-grid { grid-template-columns: 1fr; }
  .invite-card { position: static; }
}

@media (max-width: 620px) {
  .topbar { height: 66px; }
  #page-heading span { display: none; }
  .user-chip > span:nth-child(2) { display: none; }
  .sign-out { padding-left: 8px; }
  .hero-row { display: block; }
  .progress-wrap { margin-top: 18px; min-width: 0; text-align: left; }
  .application-row { grid-template-columns: 60px 1fr 24px; gap: 8px; padding: 13px; }
  .application-row .group-label { display: none; }
  .application-row .badge { grid-column: 2; }
  .application-row .chevron { grid-column: 3; grid-row: 1 / span 2; }
  .profile-grid { grid-template-columns: 1fr; }
  .document-heading { align-items: flex-start; flex-direction: column; }
  .document-actions { width: 100%; }
  .document-actions .btn { flex: 1; text-align: center; }
  .document-card.expanded { inset: 0; border: 0; border-radius: 0; }
  .document-card.expanded .document-heading { padding: 10px 12px; }
  .document-card.expanded .document-heading > div:first-child { display: none; }
  .document-card.expanded .document-tabs { display: flex; overflow-x: auto; gap: 6px; }
  .document-card.expanded .document-tabs button { min-height: 38px; text-align: center; }
  .document-card.expanded .document-tab-copy small, .document-card.expanded .document-tab-open { display: none; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric strong { font-size: 21px; }
  .form-columns { grid-template-columns: 1fr; }
  .auth-layout { padding: 24px 14px; }
}
