:root {
  --primary: #087a61;
  --primary-dark: #075443;
  --primary-soft: #e8f7f2;
  --accent: #ff8a3d;
  --accent-soft: #fff0e6;
  --navy: #173b57;
  --ink: #102722;
  --muted: #667873;
  --line: #dce8e4;
  --surface: #ffffff;
  --surface-alt: #f5faf8;
  --danger: #c4322b;
  --danger-soft: #fff0ef;
  --shadow-sm: 0 10px 28px rgba(9,72,58,.08);
  --shadow-lg: 0 28px 75px rgba(9,72,58,.14);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f4f9f7;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: #f4f9f7; }
body { min-width: 320px; min-height: 100vh; margin: 0; color: var(--ink); background: radial-gradient(circle at 10% 5%, rgba(183,222,87,.13), transparent 24%), radial-gradient(circle at 93% 3%, rgba(255,138,61,.1), transparent 22%), #f4f9f7; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
svg { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
.noscript { padding: 15px; background: #b42318; color: #fff; text-align: center; font-weight: 800; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.admin-header { position: sticky; top: 0; z-index: 50; min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 13px clamp(18px,5vw,72px); border-bottom: 1px solid rgba(220,232,228,.88); background: rgba(247,251,249,.88); backdrop-filter: blur(18px); }
.admin-brand { min-width: 0; display: inline-flex; align-items: center; gap: 12px; }
.brand-mark { flex: 0 0 auto; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; color: #fff; background: linear-gradient(145deg,var(--primary),var(--primary-dark)); box-shadow: 0 8px 20px rgba(8,122,97,.24); font-weight: 950; letter-spacing: -.05em; }
.admin-brand > span:last-child { min-width: 0; display: flex; flex-direction: column; line-height: 1.12; }
.admin-brand strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .96rem; }
.admin-brand small { margin-top: 4px; color: var(--muted); font-size: .72rem; }
.back-link { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; color: #405c55; background: #fff; box-shadow: var(--shadow-sm); font-size: .8rem; font-weight: 800; transition: transform .2s ease, color .2s ease, border-color .2s ease; }
.back-link:hover { transform: translateY(-2px); color: var(--primary); border-color: rgba(8,122,97,.3); }

.admin-main { width: min(1380px,100%); margin: 0 auto; padding: clamp(34px,5vw,72px) clamp(16px,4vw,56px) 90px; }
.login-shell { min-height: calc(100vh - 230px); display: grid; grid-template-columns: minmax(340px,.92fr) minmax(370px,.78fr); gap: clamp(36px,7vw,100px); align-items: center; }
.login-visual { position: relative; min-height: 520px; overflow: hidden; border-radius: 40px; background: linear-gradient(145deg,var(--primary-dark),#0b7b62 58%,#269578); box-shadow: var(--shadow-lg); }
.login-visual::before { content: ""; position: absolute; inset: 10%; border: 1px solid rgba(255,255,255,.14); border-radius: 50%; }
.login-visual::after { content: "BI"; position: absolute; left: 50%; top: 45%; transform: translate(-50%,-50%); color: rgba(255,255,255,.08); font-size: clamp(11rem,25vw,22rem); font-weight: 950; letter-spacing: -.12em; }
.login-orb { position: absolute; border-radius: 50%; }
.login-orb.one { width: 190px; height: 190px; right: -40px; top: -35px; background: rgba(255,138,61,.44); }
.login-orb.two { width: 140px; height: 140px; left: -30px; bottom: -35px; background: rgba(183,222,87,.34); }
.shield-card { position: absolute; z-index: 2; left: 9%; right: 9%; bottom: 9%; display: grid; grid-template-columns: auto 1fr; column-gap: 16px; align-items: center; padding: 22px; border: 1px solid rgba(255,255,255,.22); border-radius: 22px; color: #fff; background: rgba(255,255,255,.12); backdrop-filter: blur(18px); box-shadow: 0 20px 55px rgba(2,43,34,.24); }
.shield-icon { grid-row: 1 / 3; width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; color: var(--primary-dark); background: #fff; }
.shield-icon svg { width: 27px; height: 27px; }
.shield-card strong { font-size: 1rem; }
.shield-card small { margin-top: 5px; color: rgba(255,255,255,.76); line-height: 1.45; }
.login-card { max-width: 520px; width: 100%; justify-self: center; padding: clamp(28px,5vw,48px); border: 1px solid var(--line); border-radius: 30px; background: rgba(255,255,255,.94); box-shadow: var(--shadow-lg); }
.section-label, .card-kicker { color: var(--primary); font-size: .72rem; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.login-card h1, .dashboard-heading h1 { margin: 12px 0 12px; letter-spacing: -.045em; }
.login-card h1 { font-size: clamp(2.2rem,4.5vw,3.55rem); line-height: 1; }
.login-card > p { margin: 0 0 28px; color: var(--muted); line-height: 1.7; }
.setup-alert { margin: -8px 0 22px; padding: 15px 16px; border: 1px solid #f2c9a7; border-radius: 14px; color: #7d4017; background: #fff6ed; }
.setup-alert strong, .setup-alert span { display: block; }
.setup-alert strong { margin-bottom: 5px; font-size: .83rem; }
.setup-alert span { font-size: .76rem; line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field + .field { margin-top: 17px; }
.field > span:first-child { color: #314d46; font-size: .76rem; font-weight: 850; }
.field input, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 13px; outline: none; background: #fbfdfc; color: var(--ink); transition: border-color .2s ease, box-shadow .2s ease, background .2s ease; }
.field input { min-height: 50px; padding: 0 14px; }
.field textarea { padding: 16px; line-height: 1.65; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: rgba(8,122,97,.58); box-shadow: 0 0 0 4px rgba(8,122,97,.1); background: #fff; }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 50px; }
.password-field button { position: absolute; right: 7px; top: 50%; width: 38px; height: 38px; transform: translateY(-50%); display: grid; place-items: center; border: 0; border-radius: 10px; color: var(--muted); background: transparent; cursor: pointer; }
.password-field button:hover { color: var(--primary); background: var(--primary-soft); }
.primary-button, .secondary-button, .ghost-button, .danger-button { border: 0; display: inline-flex; align-items: center; justify-content: center; gap: 9px; border-radius: 13px; padding: 12px 16px; cursor: pointer; font-weight: 850; transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease, background .2s ease; }
.primary-button { color: #fff; background: linear-gradient(135deg,var(--primary),var(--primary-dark)); box-shadow: 0 12px 28px rgba(8,122,97,.2); }
.secondary-button { color: var(--primary-dark); background: var(--primary-soft); border: 1px solid rgba(8,122,97,.15); }
.ghost-button { color: #405b55; background: #fff; border: 1px solid var(--line); }
.danger-button { color: #fff; background: var(--danger); }
.primary-button:hover:not(:disabled), .secondary-button:hover:not(:disabled), .ghost-button:hover:not(:disabled), .danger-button:hover:not(:disabled) { transform: translateY(-2px); }
.primary-button:disabled, .secondary-button:disabled, .ghost-button:disabled, .danger-button:disabled { opacity: .52; cursor: not-allowed; }
.login-button { width: 100%; min-height: 54px; margin-top: 24px; }
.login-button svg { margin-left: auto; }
.form-message, .validation-message { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: .76rem; line-height: 1.45; }

.dashboard { width: 100%; }
.dashboard-heading { display: flex; align-items: end; justify-content: space-between; gap: 28px; margin-bottom: 28px; }
.dashboard-heading h1 { font-size: clamp(2.35rem,4vw,4rem); line-height: 1; }
.dashboard-heading p { margin: 0; color: var(--muted); line-height: 1.65; }
.account-actions { display: flex; align-items: center; gap: 10px; }
.account-chip { display: inline-flex; align-items: center; gap: 8px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: .77rem; font-weight: 800; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #2caf72; box-shadow: 0 0 0 4px rgba(44,175,114,.12); }
.stats-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 15px; margin-bottom: 18px; }
.stat-card { display: flex; align-items: center; gap: 15px; padding: 18px; border: 1px solid var(--line); border-radius: 19px; background: rgba(255,255,255,.92); box-shadow: var(--shadow-sm); }
.stat-icon { flex: 0 0 auto; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 15px; }
.stat-icon.green { color: var(--primary); background: var(--primary-soft); }
.stat-icon.orange { color: #c56523; background: var(--accent-soft); }
.stat-icon.navy { color: var(--navy); background: #eaf1f6; }
.stat-icon svg { width: 23px; height: 23px; }
.stat-card div { display: flex; flex-direction: column; }
.stat-card strong { font-size: 1.55rem; letter-spacing: -.04em; }
.stat-card small { margin-top: 3px; color: var(--muted); font-size: .72rem; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0,1.1fr) minmax(360px,.9fr); gap: 18px; align-items: start; }
.admin-card { border: 1px solid var(--line); border-radius: 24px; background: rgba(255,255,255,.94); box-shadow: var(--shadow-sm); }
.caption-admin-card, .upload-admin-card, .templates-admin-card { padding: clamp(20px,3vw,28px); }
.card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.card-heading h2 { margin: 7px 0 7px; font-size: 1.3rem; letter-spacing: -.025em; }
.card-heading p { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.55; }
.protected-badge { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 999px; color: var(--primary-dark); background: var(--primary-soft); font-size: .66rem; font-weight: 850; }
.caption-field textarea { min-height: 292px; background: #f8fbfa; }
.card-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 14px; color: var(--muted); font-size: .72rem; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two-fields .field + .field { margin-top: 0; }
.template-dropzone { width: 100%; min-height: 122px; margin-top: 17px; display: flex; align-items: center; gap: 14px; padding: 15px; border: 1.5px dashed rgba(8,122,97,.35); border-radius: 17px; color: var(--primary-dark); background: var(--primary-soft); text-align: left; cursor: pointer; transition: transform .2s ease, border-color .2s ease, background .2s ease; }
.template-dropzone:hover, .template-dropzone.dragover { transform: translateY(-2px); border-color: var(--primary); background: #def4ed; }
.upload-symbol { flex: 0 0 auto; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 15px; background: #fff; box-shadow: var(--shadow-sm); }
.template-dropzone > span:nth-child(2) { min-width: 0; display: flex; flex: 1; flex-direction: column; }
.template-dropzone strong { font-size: .86rem; }
.template-dropzone small { margin-top: 5px; color: #5d7770; font-size: .69rem; line-height: 1.4; }
.file-preview { flex: 0 0 auto; width: 82px; height: 82px; padding: 4px; overflow: hidden; border: 1px solid rgba(8,122,97,.17); border-radius: 12px; background-color: #e4ece9; background-image: linear-gradient(45deg,#d5e1dd 25%,transparent 25%),linear-gradient(-45deg,#d5e1dd 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#d5e1dd 75%),linear-gradient(-45deg,transparent 75%,#d5e1dd 75%); background-size: 12px 12px; background-position: 0 0,0 6px,6px -6px,-6px 0; }
.file-preview img { width: 100%; height: 100%; object-fit: contain; }
.upload-submit { width: 100%; min-height: 50px; }
.templates-admin-card { margin-top: 18px; }
.template-heading { align-items: center; }
.template-management-list { display: grid; gap: 12px; }
.template-manage-item { display: grid; grid-template-columns: 118px minmax(0,1fr) auto; gap: 16px; align-items: center; padding: 13px; border: 1px solid var(--line); border-radius: 18px; background: #fbfdfc; }
.template-thumb { width: 118px; aspect-ratio: 1; overflow: hidden; border-radius: 13px; background-color: #e3ebe8; background-image: linear-gradient(45deg,#d6e1dd 25%,transparent 25%),linear-gradient(-45deg,#d6e1dd 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#d6e1dd 75%),linear-gradient(-45deg,transparent 75%,#d6e1dd 75%); background-size: 14px 14px; background-position: 0 0,0 7px,7px -7px,-7px 0; }
.template-thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.template-fields { display: grid; grid-template-columns: minmax(170px,1fr) minmax(120px,.55fr) auto; gap: 11px; align-items: end; }
.template-fields .field + .field { margin-top: 0; }
.switch-wrap { display: flex; flex-direction: column; gap: 9px; color: #314d46; font-size: .76rem; font-weight: 850; }
.switch { position: relative; width: 50px; height: 29px; display: inline-block; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #cbd8d4; cursor: pointer; transition: background .2s ease; }
.switch span::after { content: ""; position: absolute; width: 23px; height: 23px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.14); transition: transform .2s ease; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(21px); }
.template-actions { display: flex; flex-direction: column; gap: 7px; }
.icon-action { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 11px; color: #4c645e; background: #fff; cursor: pointer; transition: color .2s ease, background .2s ease, border-color .2s ease; }
.icon-action:hover:not(:disabled) { color: var(--primary); border-color: rgba(8,122,97,.3); background: var(--primary-soft); }
.icon-action.delete:hover { color: var(--danger); border-color: rgba(196,50,43,.28); background: var(--danger-soft); }
.icon-action:disabled { opacity: .35; cursor: not-allowed; }
.empty-admin-state { padding: 40px 20px; border: 1px dashed var(--line); border-radius: 17px; color: var(--muted); text-align: center; line-height: 1.6; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: max(24px,env(safe-area-inset-bottom)); transform: translate(-50%,30px); opacity: 0; pointer-events: none; max-width: min(92vw,620px); padding: 12px 17px; border-radius: 12px; color: #fff; background: #102722; box-shadow: var(--shadow-lg); text-align: center; font-size: .8rem; font-weight: 800; transition: opacity .24s ease, transform .24s ease; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.confirm-dialog { width: min(92vw,430px); padding: 28px; border: 0; border-radius: 24px; color: var(--ink); background: #fff; box-shadow: 0 30px 100px rgba(0,0,0,.3); }
.confirm-dialog::backdrop { background: rgba(5,31,25,.68); backdrop-filter: blur(5px); }
.dialog-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 17px; color: var(--danger); background: var(--danger-soft); }
.dialog-icon svg { width: 25px; height: 25px; }
.confirm-dialog h2 { margin: 18px 0 8px; }
.confirm-dialog p { margin: 0; color: var(--muted); line-height: 1.65; font-size: .86rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

@media (max-width: 1020px) {
  .login-shell { grid-template-columns: 1fr; min-height: auto; }
  .login-visual { min-height: 330px; }
  .login-card { margin-top: -100px; position: relative; z-index: 3; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .template-fields { grid-template-columns: 1fr 1fr; }
  .switch-wrap { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; padding-top: 5px; }
}

@media (max-width: 760px) {
  .admin-header { min-height: 68px; padding: 11px 15px; }
  .brand-mark { width: 40px; height: 40px; border-radius: 12px; }
  .admin-brand small { display: none; }
  .back-link { padding: 9px 11px; font-size: .72rem; }
  .admin-main { padding-top: 28px; padding-inline: 14px; }
  .login-visual { min-height: 280px; border-radius: 28px; }
  .shield-card { left: 6%; right: 6%; bottom: 7%; padding: 17px; }
  .login-card { margin-top: -65px; padding: 25px 20px; border-radius: 24px; }
  .dashboard-heading { align-items: flex-start; flex-direction: column; }
  .account-actions { width: 100%; justify-content: space-between; }
  .stats-grid { grid-template-columns: 1fr; }
  .card-heading, .template-heading { align-items: flex-start; flex-direction: column; }
  .protected-badge { order: -1; }
  .two-fields { grid-template-columns: 1fr; }
  .two-fields .field + .field { margin-top: 0; }
  .card-footer { align-items: flex-start; flex-direction: column; }
  .card-footer .primary-button, .template-heading .primary-button { width: 100%; }
  .template-manage-item { grid-template-columns: 88px minmax(0,1fr); gap: 12px; align-items: start; }
  .template-thumb { width: 88px; }
  .template-actions { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; }
  .template-fields { grid-template-columns: 1fr; }
  .switch-wrap { grid-column: auto; }
}

@media (max-width: 430px) {
  .back-link svg { display: none; }
  .admin-brand { max-width: calc(100% - 112px); }
  .admin-brand strong { font-size: .82rem; }
  .shield-card small { font-size: .68rem; }
  .account-chip { max-width: 52%; overflow: hidden; }
  .account-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .template-manage-item { grid-template-columns: 1fr; }
  .template-thumb { width: 100%; max-width: 170px; justify-self: center; }
  .template-actions { grid-column: auto; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}


/* Caption personalization tokens */
.caption-token-note { margin: -4px 0 17px; padding: 11px 13px; border: 1px solid rgba(8,122,97,.16); border-radius: 11px; background: rgba(8,122,97,.06); color: #537069; font-size: .72rem; line-height: 1.55; }
.caption-token-note code { padding: 2px 5px; border-radius: 5px; background: white; color: #087a61; font-family: ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size: .68rem; font-weight: 800; }
