:root {
  --navy: #0a1128;
  --navy-2: #141d3a;
  --gold: #e5a812;
  --gold-dark: #9c7003;
  --gold-soft: #fdf6e3;
  --ink: #1c2233;
  --muted: #667085;
  --line: #e4e7ec;
  --bg: #f6f5f1;
  --card: #ffffff;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --ok: #067647;
  --ok-soft: #ecfdf3;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 Poppins, system-ui, sans-serif; color: var(--ink); background: var(--bg); }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--gold-dark); outline-offset: 2px; }

/* Shell */
.shell { display: flex; min-height: 100%; }
.sidebar { position: sticky; top: 0; width: 260px; height: 100vh; flex-shrink: 0; overflow-y: auto; background: var(--navy); color: #cfd4e2; padding: 16px 12px 24px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; margin-bottom: 8px; border-bottom: 1px solid rgb(255 255 255 / 10%); color: #fff; }
.brand img { width: 40px; height: 40px; object-fit: contain; }
.brand strong { display: block; font: 600 16px "Playfair Display", serif; }
.brand small { display: block; font-size: 11px; color: #98a2b3; line-height: 1.3; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-weight: 500; list-style: none; transition: background .15s, color .15s; }
.nav-link::-webkit-details-marker { display: none; }
.nav-link:hover { background: var(--navy-2); color: #fff; }
.nav-link.active { background: var(--gold); color: #17110c; }
.nav-link.active-parent { color: #fff; }
.nav-link .chevron { margin-left: auto; width: 16px; height: 16px; transition: transform .2s; }
.nav-group[open] .chevron { transform: rotate(180deg); }
.nav-sub { display: flex; flex-direction: column; gap: 1px; margin: 2px 0 6px 18px; padding-left: 10px; border-left: 1px solid rgb(255 255 255 / 12%); }
.nav-sub a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 6px; font-size: 13px; transition: background .15s, color .15s; }
.nav-badge { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--gold); color: var(--navy); font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums; }
.nav-sub a:hover { background: var(--navy-2); color: #fff; }
.nav-sub a.active { background: rgb(229 168 18 / 16%); color: var(--gold); font-weight: 500; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; height: 60px; padding: 0 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar h1 { font: 600 20px "Playfair Display", serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar .menu-btn { display: none; }
.content { padding: 24px; max-width: 1280px; width: 100%; }
.scrim { display: none; }

/* User menu */
.user-menu { position: relative; }
.user-menu summary { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 8px; cursor: pointer; list-style: none; font-weight: 500; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--bg); }
.user-menu .chevron { width: 15px; height: 15px; }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--navy); color: var(--gold); font-weight: 600; font-size: 13px; }
.user-pop { position: absolute; right: 0; top: calc(100% + 6px); width: 230px; padding: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 24px rgb(16 24 40 / 14%); }
.user-pop p { padding: 6px 8px 8px; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.user-pop button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px; border: 0; border-radius: 6px; background: none; cursor: pointer; }
.user-pop button:hover { background: var(--danger-soft); color: var(--danger); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 14px; border: 1px solid transparent; border-radius: 8px; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: #17110c; }
.btn-primary:hover:not(:disabled) { background: #d59807; }
.btn-ghost { background: var(--card); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #912018; }
.btn-danger-ghost { background: var(--card); border-color: #fda29b; color: var(--danger); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 8px; background: none; cursor: pointer; color: var(--muted); }
.icon-btn:hover:not(:disabled) { background: var(--bg); color: var(--ink); }
.icon-btn.danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 20px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 15px; font-weight: 600; }
.card-head p { font-size: 13px; color: var(--muted); }
.card-body { padding: 20px; }
.card-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { display: flex; align-items: center; gap: 14px; padding: 16px 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); transition: border-color .15s; }
.stat:hover { border-color: var(--gold); }
.stat-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; background: var(--gold-soft); color: var(--gold-dark); }
.stat-value { font-size: 24px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 13px; color: var(--muted); }
.dash-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 20px; align-items: start; }
.dash-grid .card + .card { margin-top: 0; }
.dash-col { display: flex; flex-direction: column; gap: 20px; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li + li { border-top: 1px solid var(--line); }
.rows a, .rows .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; }
.rows a:hover { background: var(--bg); }
.rows .count { font-weight: 600; font-variant-numeric: tabular-nums; }
.rows small { display: block; color: var(--muted); font-size: 12px; }

/* Toolbar + table */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 1 1 260px; max-width: 420px; }
.search svg { position: absolute; left: 10px; top: 10px; color: var(--muted); }
.search input[type="search"] { width: 100%; padding-left: 36px; }
.toolbar .spacer { flex: 1; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  min-height: 38px; padding: 8px 11px; background: #fff; border: 1px solid #d0d5dd; border-radius: 8px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--gold-dark); box-shadow: 0 0 0 3px rgb(229 168 18 / 20%); }
textarea { resize: vertical; min-height: 96px; }
.toolbar select { width: auto; max-width: 240px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 16px; font-size: 12px; font-weight: 600; color: var(--muted); background: #fafafa; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfbf8; }
.cell-sub { display: block; font-size: 12px; color: var(--muted); }
.cell-clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 420px; }
.thumb { display: block; width: 72px; height: 44px; object-fit: cover; border-radius: 6px; background: #eef0f4; border: 1px solid var(--line); }
.thumb-empty { display: grid; place-items: center; color: #98a2b3; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--gold-soft); color: var(--gold-dark); font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.status-new { background: var(--navy); color: var(--card); }
.badge.status-accepted, .badge.status-replied { background: var(--ok-soft); color: var(--ok); }
.badge.status-rejected { background: var(--danger-soft); color: var(--danger); }
.badge.status-read { background: var(--bg); color: var(--muted); }
.cell-nowrap { white-space: nowrap; }
.count-link { color: var(--gold-dark); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.actions { display: flex; justify-content: flex-end; gap: 2px; }
.table-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.pager { display: flex; align-items: center; gap: 8px; }
.state { padding: 48px 20px; text-align: center; color: var(--muted); }
.state svg { width: 28px; height: 28px; margin-bottom: 8px; color: #98a2b3; }
.state strong { display: block; color: var(--ink); font-weight: 600; margin-bottom: 2px; }
.state .btn { margin-top: 12px; }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 36px; height: 20px; margin: 0; cursor: pointer; }
.switch i { width: 36px; height: 20px; border-radius: 999px; background: #d0d5dd; transition: background .15s; position: relative; flex-shrink: 0; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 25%); transition: transform .15s; }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 2px solid var(--gold-dark); outline-offset: 2px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field.wide { grid-column: 1 / -1; }
.field label, .field-label { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 500; }
.req { color: var(--danger); }
.help { margin-top: 4px; font-size: 12px; color: var(--muted); }
.field-error { margin-top: 4px; font-size: 12px; color: var(--danger); }
.field.has-error input, .field.has-error select, .field.has-error textarea, .field.has-error .dropzone { border-color: var(--danger); }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 16px; cursor: pointer; }
.icon-select { display: flex; align-items: center; gap: 8px; }
.icon-preview { display: grid; place-items: center; width: 38px; height: 38px; flex-shrink: 0; border-radius: 8px; background: var(--gold-soft); color: var(--gold-dark); }

/* Image upload */
.dropzone { display: flex; align-items: center; gap: 14px; padding: 12px; border: 1px dashed #b9c0cc; border-radius: 10px; background: #fcfcfb; transition: border-color .15s, background .15s; }
.dropzone.drag { border-color: var(--gold-dark); background: var(--gold-soft); }
.dropzone-preview { position: relative; display: grid; place-items: center; width: 132px; height: 88px; flex-shrink: 0; overflow: hidden; border-radius: 8px; background: repeating-conic-gradient(#eef0f4 0 25%, #fff 0 50%) 0 0 / 16px 16px; border: 1px solid var(--line); color: #98a2b3; }
.dropzone-preview img, .dropzone-preview video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.dropzone-preview:hover { opacity: 0.92; }
.dropzone-body { min-width: 0; flex: 1; }
.dropzone-name { font-size: 13px; font-weight: 500; overflow-wrap: anywhere; }
.dropzone-hint { font-size: 12px; color: var(--muted); }
.dropzone-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* Repeater */
.repeater { display: flex; flex-direction: column; gap: 8px; }
.repeater-row { display: flex; align-items: flex-end; gap: 8px; }
.repeater-row > div { flex: 1; min-width: 0; }
.repeater-row label { font-size: 12px; color: var(--muted); font-weight: 400; margin-bottom: 2px; display: block; }

/* Tabs */
.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 12px; border-bottom: 1px solid var(--line); }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 12px 12px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-weight: 500; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--gold-dark); border-bottom-color: var(--gold); }
.tab svg { width: 16px; height: 16px; }
.tab.has-error { color: var(--danger); }

/* Modal */
.modal-back { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 32px 16px; overflow-y: auto; background: rgb(10 17 40 / 55%); }
.modal { width: 100%; max-width: 720px; background: var(--card); border-radius: 12px; box-shadow: 0 24px 48px rgb(16 24 40 / 28%); animation: pop .15s ease-out; }
.modal.small { max-width: 420px; margin-top: 12vh; }
.modal.wide { max-width: 1000px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { min-width: 0; overflow-wrap: anywhere; font: 600 18px "Playfair Display", serif; }
.modal-head .icon-btn { flex-shrink: 0; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.form-alert { margin-bottom: 14px; padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

/* Application and message details */
.detail-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px 12px; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.detail-head > div { min-width: 0; overflow-wrap: anywhere; }
.detail-head strong { font-size: 15px; font-weight: 600; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.detail-main { grid-column: 1; grid-row: 1; min-width: 0; }
.detail-side { grid-column: 2; grid-row: 1; min-width: 0; }
.detail-section + .detail-section { margin-top: 20px; }
.detail-section h3 { margin-bottom: 8px; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.detail-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 16px; margin: 0; }
.detail-list dt { font-size: 12px; color: var(--muted); }
.detail-list dd { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.contact-links { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.detail-side .contact-links { flex-direction: column; }
.contact-link { display: inline-flex; align-items: center; gap: 6px; min-width: 0; color: var(--gold-dark); font-weight: 500; }
.contact-link span { overflow-wrap: anywhere; text-decoration: underline; text-underline-offset: 2px; }
.contact-link svg { width: 16px; height: 16px; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.status-form .form-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
.status-form-foot { display: flex; justify-content: flex-end; margin-top: 12px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.doc-card { display: block; min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; transition: border-color .15s; }
.doc-card:hover { border-color: var(--gold); }
.doc-preview { display: grid; place-items: center; height: 100px; background: var(--bg); color: var(--muted); }
.doc-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.doc-preview svg { width: 28px; height: 28px; }
.doc-label { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 8px 10px; font-size: 13px; font-weight: 500; }
.doc-label span { min-width: 0; overflow-wrap: anywhere; }
.doc-label svg { width: 14px; height: 14px; color: var(--muted); }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 8px; padding: 10px 14px; border-radius: 8px; background: var(--navy); color: #fff; box-shadow: 0 8px 20px rgb(16 24 40 / 25%); animation: pop .15s ease-out; }
.toast.error { background: var(--danger); }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100%; padding: 24px 16px; background: var(--navy) radial-gradient(circle at 50% 0, #1d2a55, transparent 60%); }
.login-card { width: 100%; max-width: 400px; padding: 32px; background: var(--card); border-radius: 14px; box-shadow: 0 24px 60px rgb(0 0 0 / 35%); }
.login-seal { display: block; width: 72px; height: 72px; margin: 0 auto 12px; object-fit: contain; }
.login-card h1 { font: 600 24px "Playfair Display", serif; text-align: center; }
.login-sub { margin: 4px 0 22px; text-align: center; color: var(--muted); font-size: 13px; }
.login-card .field { margin-bottom: 14px; }

@media (max-width: 960px) {
  .dash-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .sidebar { position: fixed; z-index: 40; left: 0; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; z-index: 30; background: rgb(10 17 40 / 45%); }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: 0 12px; }
  .content { padding: 16px; }
  .hide-sm { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar select { flex: 1 1 140px; min-width: 0; max-width: 100%; }
  .search { max-width: none; }
  .dropzone { flex-direction: column; align-items: stretch; }
  .dropzone-preview { width: 100%; height: 140px; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .detail-main, .detail-side { grid-column: auto; grid-row: auto; }
  .modal-foot { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
