/* ui.css: the Digitalage News design system, shared by the public site and
   the admin. Modelled on shadcn/ui (zinc neutrals, 10px radius, quiet
   borders, soft shadows) with the Digitalage blue as the accent.
   Components: buttons, badges, cards, inputs, dialogs (modal + sheet),
   toasts, skeletons. Behaviour lives in static/scripts/ui.js.
   When this file changes, bump newsCSSVersion in news_public_templates.go. */

@font-face {
  font-family: "Inter";
  src: url("/static/fonts/inter-latin-var.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Newsreader";
  src: url("/static/fonts/newsreader-latin-var.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Newsreader";
  src: url("/static/fonts/newsreader-latin-var-italic.woff2") format("woff2");
  font-weight: 200 800;
  font-style: italic;
  font-display: swap;
}
/* JetBrains Mono (OFL, static/fonts/OFL-JetBrainsMono.txt): tickers and table
   figures only, so it is not preloaded. */
@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/jetbrains-mono-latin-var.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-subtle: #fafafa;
  --fg: #09090b;
  --fg-2: #27272a;
  --muted: #f4f4f5;
  --muted-fg: #71717a;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --card: #ffffff;
  --primary: #18181b;
  --primary-hover: #27272a;
  --primary-fg: #fafafa;
  --brand: #2c7aa6;
  --brand-strong: #1d5f85;
  --brand-bright: #4a9dcc;
  --brand-soft: #eaf4fa;
  --brand-ring: rgba(74, 157, 204, 0.35);
  --success: #15803d;
  --success-soft: #ecfdf3;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-strong: #b91c1c;
  --danger-soft: #fef2f2;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow-xs: 0 1px 2px rgba(9, 9, 11, 0.05);
  --shadow-sm: 0 1px 3px rgba(9, 9, 11, 0.06), 0 1px 2px rgba(9, 9, 11, 0.04);
  --shadow-md: 0 6px 16px -4px rgba(9, 9, 11, 0.1), 0 2px 6px -2px rgba(9, 9, 11, 0.06);
  --shadow-lg: 0 24px 48px -12px rgba(9, 9, 11, 0.22), 0 8px 20px -8px rgba(9, 9, 11, 0.1);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Newsreader", "Iowan Old Style", "Source Serif Pro", Charter, Georgia, serif;
  --paper: #faf8f4;
  --ink: #111111;
  --rule: #1a1a1a;
  --live: #dc2626;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-in: cubic-bezier(0.7, 0, 0.84, 0);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-feature-settings: "cv11", "ss01", "ss03";
  color: var(--fg-2);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg, video { display: block; max-width: 100%; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand-bright); outline-offset: 2px; border-radius: var(--radius-sm); }
::selection { background: var(--brand-soft); color: var(--fg); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.icon { width: 16px; height: 16px; flex: none; }

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  padding: 8px 14px; border-radius: var(--radius); background: var(--primary); color: var(--primary-fg);
  font-size: 14px; font-weight: 500; text-decoration: none; transition: top 0.2s var(--ease-out);
}
.skip-link:focus { top: 12px; }

/* ---------- Buttons ---------- */
.btn {
  --btn-h: 38px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--btn-h); padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; line-height: 1; letter-spacing: -0.005em;
  white-space: nowrap; text-decoration: none; cursor: pointer; user-select: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.12s var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; pointer-events: none; }
.btn-primary { background: var(--primary); color: var(--primary-fg); box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-brand { background: var(--brand); color: #fff; box-shadow: var(--shadow-xs); }
.btn-brand:hover { background: var(--brand-strong); }
.btn-secondary { background: var(--muted); color: var(--fg); }
.btn-secondary:hover { background: #e9e9ec; }
.btn-outline { background: var(--bg); color: var(--fg); border-color: var(--border); box-shadow: var(--shadow-xs); }
.btn-outline:hover { background: var(--bg-subtle); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--fg-2); }
.btn-ghost:hover { background: var(--muted); color: var(--fg); }
.btn-destructive { background: var(--danger); color: #fff; box-shadow: var(--shadow-xs); }
.btn-destructive:hover { background: var(--danger-strong); }
.btn-sm { --btn-h: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { --btn-h: 44px; padding: 0 20px; font-size: 15px; }
.btn-icon { width: var(--btn-h); padding: 0; }
.btn .arrow { transition: transform 0.2s var(--ease-out); }
.btn:hover .arrow { transform: translateX(2px); }
.spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: ui-rot 0.7s linear infinite; }
@keyframes ui-rot { to { transform: rotate(360deg); } }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 9px; border-radius: 999px;
  border: 1px solid transparent; font-size: 12px; font-weight: 500; line-height: 1;
  white-space: nowrap; text-decoration: none; background: var(--muted); color: var(--fg-2);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.badge-outline { background: var(--bg); border-color: var(--border); }
.badge-brand { background: var(--brand-soft); color: var(--brand-strong); }
.badge-dark { background: var(--primary); color: var(--primary-fg); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
a.badge:hover { background: var(--brand-soft); color: var(--brand-strong); }
a.badge-outline:hover { border-color: var(--border-strong); background: var(--bg-subtle); color: var(--fg); }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); }

/* ---------- Inputs ---------- */
.input, .textarea, .select {
  display: block; width: 100%; min-height: 38px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg);
  font-size: 14px; color: var(--fg); box-shadow: var(--shadow-xs);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--brand-bright); box-shadow: 0 0 0 3px var(--brand-ring); }
.textarea { min-height: 76px; resize: vertical; line-height: 1.5; }

/* ---------- Dialogs: modal (centered) and sheet (side panel) ----------
   Native <dialog>, so focus trapping, Esc and the top layer come free.
   The backdrop blurs the page; ui.js animates the panel in and out. */
.ui-dialog, .ui-sheet {
  padding: 0; border: 0; background: transparent; color: inherit;
  max-width: none; max-height: none; overflow: visible;
}
.ui-dialog::backdrop, .ui-sheet::backdrop {
  background: rgba(9, 9, 11, 0.42);
  -webkit-backdrop-filter: blur(6px) saturate(140%);
  backdrop-filter: blur(6px) saturate(140%);
  animation: ui-fade-in 0.28s var(--ease-out) both;
}
.ui-dialog.is-closing::backdrop, .ui-sheet.is-closing::backdrop { animation: ui-fade-out 0.22s var(--ease-in-out) both; }
@keyframes ui-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ui-fade-out { from { opacity: 1; } to { opacity: 0; } }

.ui-dialog { width: min(520px, calc(100vw - 32px)); margin: auto; }
.ui-dialog__panel {
  position: relative; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); padding: 24px;
  max-height: calc(100dvh - 48px); overflow: auto;
}
.ui-dialog--wide { width: min(1080px, calc(100vw - 32px)); }
.ui-dialog--wide .ui-dialog__panel { padding: 12px; }
.ui-dialog__title { margin: 0 32px 6px 0; font-size: 18px; font-weight: 600; letter-spacing: -0.015em; color: var(--fg); line-height: 1.3; }
.ui-dialog__desc { margin: 0; font-size: 14px; line-height: 1.6; color: var(--muted-fg); }
.ui-dialog__body { margin-top: 16px; font-size: 14.5px; line-height: 1.65; color: var(--fg-2); }
.ui-dialog__body p { margin: 0 0 12px; }
.ui-dialog__body a { color: var(--brand); font-weight: 500; text-underline-offset: 3px; }
.ui-dialog__footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
@media (max-width: 480px) {
  .ui-dialog__footer { flex-direction: column-reverse; }
  .ui-dialog__footer .btn { width: 100%; }
}
.ui-dialog__close {
  position: absolute; top: 14px; right: 14px; width: 32px; height: 32px;
  display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted-fg); cursor: pointer; transition: background-color 0.15s, color 0.15s;
}
.ui-dialog__close:hover { background: var(--muted); color: var(--fg); }
.ui-dialog__icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; margin-bottom: 14px; background: var(--muted); color: var(--fg); }
.ui-dialog__icon--danger { background: var(--danger-soft); color: var(--danger); }
.ui-dialog__icon--brand { background: var(--brand-soft); color: var(--brand); }
.ui-dialog__img { display: block; width: 100%; height: auto; max-height: calc(100dvh - 120px); object-fit: contain; border-radius: var(--radius); background: var(--muted); }
.ui-dialog__caption { padding: 10px 6px 2px; font-size: 13px; color: var(--muted-fg); }

.ui-sheet {
  margin: 0 0 0 auto; height: 100dvh; width: min(380px, 88vw);
}
.ui-sheet__panel {
  height: 100%; background: var(--card); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); padding: 20px; display: flex; flex-direction: column; overflow-y: auto;
}

/* CSS fallbacks when the motion library is not available. */
.ui-dialog[open]:not(.is-js) .ui-dialog__panel { animation: ui-pop-in 0.28s var(--ease-out) both; }
.ui-dialog.is-closing:not(.is-js) .ui-dialog__panel { animation: ui-pop-out 0.2s var(--ease-in-out) both; }
.ui-sheet[open]:not(.is-js) .ui-sheet__panel { animation: ui-slide-in 0.34s var(--ease-out) both; }
.ui-sheet.is-closing:not(.is-js) .ui-sheet__panel { animation: ui-slide-out 0.24s var(--ease-in-out) both; }
@keyframes ui-pop-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes ui-pop-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(6px) scale(0.97); } }
@keyframes ui-slide-in { from { transform: translateX(100%); } to { transform: none; } }
@keyframes ui-slide-out { from { transform: none; } to { transform: translateX(100%); } }
html.ui-locked { overflow: hidden; scrollbar-gutter: stable; }

/* ---------- Toasts (bottom right; top on phones) ---------- */
.ui-toasts {
  position: fixed; z-index: 1000; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.ui-toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px;
  padding: 14px 16px; border-radius: var(--radius-lg); border: 1px solid var(--border);
  background: var(--card); box-shadow: var(--shadow-lg); font-size: 14px; line-height: 1.45; color: var(--fg);
  animation: ui-toast-in 0.35s var(--ease-out) both;
}
.ui-toast.is-leaving { animation: ui-toast-out 0.25s var(--ease-in-out) both; }
.ui-toast__icon { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.ui-toast--success .ui-toast__icon { color: var(--success); }
.ui-toast--error .ui-toast__icon { color: var(--danger); }
.ui-toast--info .ui-toast__icon { color: var(--brand); }
.ui-toast__msg { flex: 1; font-weight: 500; }
.ui-toast__x { flex: none; border: 0; background: transparent; color: var(--muted-fg); cursor: pointer; padding: 2px; border-radius: 6px; }
.ui-toast__x:hover { color: var(--fg); background: var(--muted); }
@keyframes ui-toast-in { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes ui-toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(8px) scale(0.97); } }
@media (max-width: 640px) {
  .ui-toasts { right: 16px; left: 16px; bottom: auto; top: 16px; width: auto; }
}

/* ---------- Skeleton shimmer (image placeholders) ---------- */
.ui-skeleton { background: linear-gradient(100deg, var(--muted) 30%, #fafafa 50%, var(--muted) 70%); background-size: 300% 100%; animation: ui-shimmer 1.6s ease-in-out infinite; }
@keyframes ui-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

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