/* Look and feel mirrors the Shofar WhatsApp Manager (its admin-theme.css plus the Tailwind slate
   palette its templates use), hand-written so Tertius needs no Tailwind build or CDN.
   Dark mode is the .dark class on <html>, set by the inline script in base.html / login.html. */
:root {
  --brand: #ff571f; --brand-rgb: 255, 87, 31; --brand-hover: #e04815;
  --white: #ffffff;
  --slate-50: #f8fafc; --slate-100: #f1f5f9; --slate-200: #e2e8f0; --slate-300: #cbd5e1; --slate-400: #94a3b8;
  --slate-400-rgb: 148, 163, 184;
  --slate-500: #64748b; --slate-600: #475569; --slate-700: #334155; --slate-800: #1e293b; --slate-900: #0f172a;

  --bg: var(--slate-100); --surface: var(--white); --surface-alt: var(--slate-50);
  --text: var(--slate-900); --text-soft: var(--slate-700); --muted: var(--slate-500);
  --border: var(--slate-200); --border-soft: var(--slate-100); --input-border: var(--slate-300);
  --input-bg: var(--slate-50); --chip: var(--slate-100); --chip-hover: var(--slate-200); --row-hover: var(--slate-50);
  --brand-soft: rgba(var(--brand-rgb), 0.1); --brand-pill: var(--brand-hover);

  --ok: #047857; --ok-bg: #ecfdf5; --ok-border: #a7f3d0;
  --warn: #b45309; --warn-bg: #fffbeb; --warn-border: #fcd34d;
  --error: #e11d48; --error-bg: #fff1f2; --error-border: #fecdd3;
  color-scheme: light;
}
html.dark {
  --bg: var(--slate-900); --surface: var(--slate-800); --surface-alt: rgba(15, 23, 42, 0.5);
  --text: var(--slate-100); --text-soft: var(--slate-300); --muted: var(--slate-400);
  --border: var(--slate-700); --border-soft: rgba(51, 65, 85, 0.6); --input-border: var(--slate-700);
  --input-bg: var(--slate-900); --chip: var(--slate-700); --chip-hover: var(--slate-600); --row-hover: var(--slate-900);
  --brand-soft: rgba(var(--brand-rgb), 0.18); --brand-pill: #ff7a4d;

  --ok: #6ee7b7; --ok-bg: rgba(6, 78, 59, 0.4); --ok-border: rgba(4, 120, 87, 0.6);
  --warn: #fcd34d; --warn-bg: rgba(120, 53, 15, 0.3); --warn-border: #b45309;
  --error: #fb7185; --error-bg: rgba(76, 5, 25, 0.4); --error-border: rgba(136, 19, 55, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s, color 0.2s;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); }
main { flex: 1; width: 100%; max-width: 64rem; margin: 0 auto; padding: 24px 16px 60px; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.025em; margin: 0 0 16px; }
h2 { font-size: 1.125rem; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 0.95rem; font-weight: 600; margin: 0 0 6px; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: 9999px; }
html.dark ::-webkit-scrollbar-thumb { background: var(--slate-700); }

/* ---- Header ---- */
.topbar { position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); }
.topbar-inner { max-width: 80rem; margin: 0 auto; padding: 0 16px; min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.125rem; letter-spacing: -0.025em; color: var(--text); white-space: nowrap; }
.brand:hover { color: var(--text); opacity: 0.9; }
.brand img { width: 28px; height: 28px; }
.brand .brand-sub { font-weight: 400; color: var(--brand); }
.main-nav { display: flex; align-items: center; gap: 4px; }
.nav-link { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 6px; font-size: 0.875rem; font-weight: 500; color: var(--text-soft); white-space: nowrap; }
.nav-link:hover { color: var(--brand); }
html.dark .nav-link:hover { color: var(--white); }
.nav-link i { color: var(--brand); }
.nav-link.active { background: var(--brand-soft); }
.user-nav { display: flex; align-items: center; gap: 16px; }
.user-link { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; font-weight: 500; color: var(--text-soft); white-space: nowrap; }
.user-link:hover { color: var(--brand); }
html.dark .user-link:hover { color: var(--white); }
button.logout-link { display: inline-flex; align-items: center; gap: 4px; padding: 0; background: none; border: 0; box-shadow: none; font-size: 0.75rem; font-weight: 500; color: #e11d48; cursor: pointer; }
button.logout-link:hover { background: none; color: #be123c; }
button.icon-btn { padding: 8px; border-radius: 6px; background: none; box-shadow: none; color: var(--text-soft); font-size: 1rem; line-height: 1; }
button.icon-btn:hover { background: var(--chip); color: var(--text); }
html:not(.dark) .show-dark, html.dark .show-light { display: none; }
#mobile-menu-btn { display: none; font-size: 1.25rem; }
.mobile-menu { display: none; border-top: 1px solid var(--border); padding: 8px 16px 16px; }
.mobile-menu.open { display: block; }
.mobile-menu a, .mobile-menu button.mobile-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 12px; border-radius: 6px; font-size: 1rem; font-weight: 500; color: var(--text-soft); background: none; box-shadow: none; text-align: left; justify-content: flex-start; }
.mobile-menu a:hover, .mobile-menu button.mobile-item:hover { background: var(--chip); color: var(--text); }
.mobile-menu i { color: var(--brand); width: 1.1em; text-align: center; }
.mobile-menu .mobile-section { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; }
.mobile-menu button.mobile-item.logout, .mobile-menu button.mobile-item.logout i { color: #e11d48; }
@media (max-width: 1023px) {
  .main-nav, .user-nav { display: none; }
  #mobile-menu-btn { display: inline-flex; }
}

/* ---- Page headings and cards ---- */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; border-left: 4px solid var(--brand); border-bottom: 1px solid var(--border); padding: 0 0 20px 16px; margin-bottom: 24px; }
.page-header h1 { margin: 0; }
.page-header p { margin: 2px 0 0; font-size: 0.875rem; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-top: 2px solid var(--brand); border-radius: 16px; padding: 24px; margin-bottom: 24px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); }
@media (min-width: 640px) { .card { padding: 28px 32px; } }
.card.narrow { max-width: 32rem; }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card-head { display: flex; align-items: center; gap: 12px; margin: 0 0 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border-soft); }
.card-head h2 { margin: 0; }
.card-head p { margin: 0; font-size: 0.75rem; color: var(--muted); }
.card-icon { flex: none; width: 40px; height: 40px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; font-size: 1.05rem; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.8rem; margin: -8px 0 16px; }

/* ---- Forms ---- */
label { display: block; margin-bottom: 18px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-soft); }
label .badge { text-transform: none; letter-spacing: 0; }
label.check { display: flex; gap: 8px; align-items: center; font-size: 0.875rem; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text); }
.inline-check { display: inline-flex !important; margin: 0 0 0 10px; }
.hint label.check { font-size: 0.8rem; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=file], select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--input-border); border-radius: 8px;
  font: inherit; font-size: 0.875rem; font-weight: 400; text-transform: none; letter-spacing: 0;
  background: var(--input-bg); color: var(--text); transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--slate-400); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.25); }
input[type=file] { padding: 8px; cursor: pointer; }
input[type=file]::file-selector-button { margin-right: 12px; padding: 6px 14px; border: 0; border-radius: 8px; background: var(--brand-soft); color: var(--brand); font: inherit; font-weight: 600; cursor: pointer; }
input[type=file]:hover::file-selector-button { background: rgba(var(--brand-rgb), 0.2); }
input.compact { display: inline-block; width: 160px; margin: 0 4px 0 0; padding: 6px 10px; }
textarea { resize: vertical; }
input[type=radio], input[type=checkbox] { accent-color: var(--brand); width: 1.05rem; height: 1.05rem; margin: 0; cursor: pointer; }
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset !important; -webkit-text-fill-color: var(--text) !important; caret-color: var(--text);
}
fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px 6px; margin: 0 0 20px; }
legend { padding: 0 6px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-soft); }
details { margin-bottom: 20px; border: 1px solid var(--border); border-radius: 12px; padding: 12px 18px 0; }
summary { cursor: pointer; font-weight: 600; font-size: 0.875rem; margin-bottom: 12px; color: var(--text); }
summary::marker { color: var(--brand); }

/* ---- Buttons ---- */
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--brand); color: var(--white); border: 0; border-radius: 12px; padding: 10px 24px; font: inherit; font-size: 0.875rem; font-weight: 600; cursor: pointer; text-decoration: none; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); transition: background-color 0.15s, color 0.15s; }
button:hover, .button:hover { background: var(--brand-hover); color: var(--white); }
button:disabled { opacity: 0.6; cursor: wait; }
.button.cta { border-radius: 8px; padding: 10px 20px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; box-shadow: 0 10px 15px -3px rgba(var(--brand-rgb), 0.25); }
.button.small, button.small { padding: 6px 14px; font-size: 0.8rem; border-radius: 8px; }
.button.secondary, button.secondary { background: var(--chip); color: var(--text-soft); box-shadow: none; }
.button.secondary:hover, button.secondary:hover { background: var(--chip-hover); color: var(--text); }
button.link { background: none; color: var(--brand); padding: 0; font-size: 0.8rem; font-weight: 600; box-shadow: none; border-radius: 0; }
button.link:hover { background: none; color: var(--brand-hover); }
button.danger { background: transparent; color: var(--error); border: 1px solid var(--error-border); box-shadow: none; }
button.danger:hover { background: var(--error-bg); color: var(--error); }
form.inline { display: inline; }
.hidden { display: none !important; }

/* ---- Alerts (icons need Font Awesome, linked from the templates) ---- */
.flash { display: flex; gap: 8px; align-items: flex-start; padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; font-size: 0.875rem; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); }
.flash::before { font: var(--fa-font-solid); margin-top: 3px; flex: none; }
.flash.ok { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); }
.flash.ok::before { content: "\f058"; }
.flash.warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); }
.flash.warn::before { content: "\f071"; }
.flash.error { background: var(--error-bg); border-color: var(--error-border); color: var(--error); }
.flash.error::before { content: "\f06a"; }

/* ---- Tables (sit inside a .card.table-card) ---- */
.card.table-card { padding: 12px 16px 8px; overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.list th { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--slate-600); font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
html.dark table.list th { color: var(--slate-400); }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text-soft); vertical-align: middle; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list tbody tr:hover { background: var(--row-hover); }
table.list td.strong, table.list td.strong a { font-weight: 600; color: var(--text); }
table.list td.strong a:hover { color: var(--brand); }
tr.inactive td { opacity: 0.6; }
.row-actions { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.row-actions form { display: inline-flex; gap: 10px; align-items: center; }

/* ---- Pills ---- */
.status { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.7rem; font-weight: 600; text-transform: capitalize; white-space: nowrap; background: rgba(var(--slate-400-rgb), 0.2); color: var(--muted); }
.status.completed, .status.active { background: var(--ok-bg); color: var(--ok); }
.status.completed.warn { background: var(--warn-bg); color: var(--warn); }
.status.failed { background: var(--error-bg); color: var(--error); }
.status.transcribing, .status.cleaning, .status.queued, .status.superadmin { background: rgba(var(--brand-rgb), 0.15); color: var(--brand-pill); }
.badge { display: inline-block; font-size: 0.7rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.shared { background: rgba(var(--brand-rgb), 0.15); color: var(--brand-pill); }
.badge.off { background: var(--chip); color: var(--muted); }

/* ---- New transcription ---- */
.model-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin: 4px 0 14px; }
.model-option { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; margin: 0; font-size: 0.875rem; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text); background: var(--surface); transition: border-color 0.15s, background-color 0.15s; }
.model-option:hover { border-color: var(--slate-400); }
.model-option:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.model-option input { grid-row: span 2; margin-top: 3px; }
.model-label { font-weight: 600; }
.model-summary { color: var(--muted); font-size: 0.8rem; }
.limits { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin-bottom: 14px; font-size: 0.85rem; color: var(--text-soft); }
.limits h3 { color: var(--text); }
.limits ul { margin: 0; padding-left: 18px; }
.progress { position: relative; height: 28px; background: var(--chip); border-radius: 8px; overflow: hidden; margin-bottom: 14px; }
.progress .bar { height: 100%; width: 0; background: var(--brand); transition: width 0.2s; }
.progress-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 600; color: var(--text); }

/* ---- Job page ---- */
.tabs { display: flex; gap: 4px; }
button.tab { background: transparent; color: var(--muted); border: 1px solid transparent; border-bottom: 0; border-radius: 10px 10px 0 0; padding: 8px 18px; box-shadow: none; }
button.tab:hover { background: var(--chip); color: var(--text); }
button.tab.active { position: relative; margin-bottom: -1px; background: var(--surface); color: var(--brand); border-color: var(--border); border-top: 2px solid var(--brand); }
.tab-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 0 16px 16px 16px; padding: 20px; margin-bottom: 24px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); }
.actions { display: flex; gap: 8px; margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--border-soft); }
.transcript { white-space: pre-wrap; word-wrap: break-word; font: 15px/1.7 Georgia, "Times New Roman", serif; color: var(--text); margin: 0; max-height: 70vh; overflow: auto; }
.working { display: flex; align-items: center; margin: 0 0 4px; font-weight: 500; }
.working::before { content: ""; flex: none; width: 14px; height: 14px; margin-right: 12px; border: 2px solid var(--brand); border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.danger-zone { margin-top: 32px; }

/* ---- Login ---- */
body.login-page { align-items: center; justify-content: center; padding: 16px; }
.login-wrap { width: 100%; max-width: 28rem; }
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand img { height: 13rem; width: auto; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.05)); }
.login-brand h1 { margin: 12px 0 4px; }
.login-brand p { margin: 0; font-size: 0.75rem; color: var(--muted); }
.login-wrap .card { border-radius: 12px; }
.login-title { display: flex; align-items: center; gap: 8px; margin: 0 0 20px; padding-bottom: 12px; border-bottom: 1px solid var(--border-soft); font-size: 1.125rem; font-weight: 700; }
.login-title i { color: var(--brand); }
.login-wrap button[type=submit] { width: 100%; border-radius: 8px; }
.login-theme { position: fixed; top: 12px; right: 12px; }

/* Show/Hide toggle inside password and API key fields (added by app.js). */
.password-field { position: relative; display: block; margin-top: 6px; }
.password-field input { margin-top: 0; padding-right: 60px; }
.password-field.compact { display: inline-block; width: 180px; margin: 0 4px 0 0; }
.password-field.compact input { width: 100%; padding-right: 50px; }
button.password-toggle { position: absolute; top: 0; bottom: 0; right: 0; display: flex; align-items: center; padding: 0 12px;
  background: none; border: 0; box-shadow: none; color: var(--slate-500); font-size: 0.75rem; font-weight: 500; text-transform: none; letter-spacing: 0; cursor: pointer; }
button.password-toggle:hover { background: none; color: var(--text-soft); }

/* ---- Usage page ---- */
.range-links { display: flex; gap: 8px; }
.range-link { padding: 6px 14px; border-radius: 10px; font-size: 0.75rem; font-weight: 600; border: 1px solid var(--input-border); color: var(--text-soft); background: var(--surface); }
.range-link:hover { color: var(--text); border-color: var(--brand); }
.range-link.active, .range-link.active:hover { background: var(--brand); border-color: var(--brand); color: var(--white); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.tile { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; }
.tile-title { font-size: 0.75rem; color: var(--muted); }
.tile-value { font-size: 1.5rem; font-weight: 700; color: var(--text); margin-top: 2px; }
.tile-sub { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.card .card-intro { margin: -16px 0 16px; font-size: 0.8rem; color: var(--muted); }
.card.table-card .card-head { margin: 8px 0 8px; padding: 0 0 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { display: block; font-size: 0.7rem; color: var(--muted); }
.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 12px; border-top: 1px solid var(--border); font-size: 0.75rem; color: var(--muted); }
.pagination .pages { display: flex; gap: 4px; align-items: center; }
.pagination a, .pagination span.page { padding: 4px 10px; border-radius: 8px; font-weight: 600; border: 1px solid var(--input-border); color: var(--text-soft); }
.pagination a:hover { border-color: var(--brand); color: var(--text); }
.pagination span.page.current { background: var(--brand); border-color: var(--brand); color: var(--white); }
.pagination span.page.disabled { opacity: 0.4; }
