/* public/css/13-dark-mode-a11y.css
   ─────────────────────────────────────────────────────────────────
   пункт 15: Dark mode (prefers-color-scheme:dark media query) +
             Accessibility improvements (focus rings, aria, keyboard nav)
   пункт 4:  Database unavailable error screen styles
   ─────────────────────────────────────────────────────────────────
   This file is appended to the existing CSS bundle.
   The existing token system already has body[data-theme="light"] and a dark
   :root default. This file adds:
     1. @media (prefers-color-scheme: light) — auto-apply light theme for
        users who haven't set a preference in the app but have their OS in
        light mode.
     2. @media (prefers-color-scheme: dark) — ensure dark stays dark (no-op
        but explicit for clarity).
     3. [data-theme="auto"] — respects OS preference dynamically.
     4. Focus ring styles for keyboard navigation.
     5. .db-error-screen — the 503 "service unavailable" overlay.
*/

/* ── 1. OS-level dark mode preference ──────────────────────────── */
/* Default :root is already dark — nothing to override.             */
/* When OS is light AND user hasn't manually chosen a theme:        */
@media (prefers-color-scheme: light) {
  body:not([data-theme]):not([data-theme="dark"]) {
    --bg:           #f0f2fa;
    --panel:        #ffffff;
    --panel-2:      #f5f6fc;
    --panel-3:      #eaecf7;
    --panel-4:      #dde0f0;
    --border:       rgba(0,0,0,0.07);
    --border-hover: rgba(0,0,0,0.13);
    --border-focus: rgba(64,92,232,0.45);
    --text:         rgba(0,0,0,0.88);
    --text-muted:   rgba(0,0,0,0.48);
    --text-dim:     rgba(0,0,0,0.30);
    --accent:       #4255e8;
    --accent-2:     #2f3ecc;
    --accent-3:     #1e2db3;
    --accent-soft:  rgba(66,85,232,0.09);
    --accent-glow:  rgba(66,85,232,0.18);
    --accent-shine: rgba(66,85,232,0.05);
    --danger:       #dc2626;
    --danger-bg:    rgba(220,38,38,0.09);
    --ok:           #16a34a;
    --ok-bg:        rgba(22,163,74,0.09);
    --warn:         #d97706;
    --warn-bg:      rgba(217,119,6,0.09);
    --info:         #2563eb;
    --info-bg:      rgba(37,99,235,0.08);
    --shadow-xs:    0 1px 3px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.03);
    --shadow-sm:    0 2px 10px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
    --shadow:       0 8px 30px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.05);
    --shadow-lg:    0 20px 60px rgba(0,0,0,0.18), 0 8px 20px rgba(0,0,0,0.08);
    --shadow-accent:0 6px 20px rgba(66,85,232,0.22);
    --surface-shine:linear-gradient(180deg,rgba(255,255,255,0.90) 0%,transparent 60%);
    --surface-edge: inset 0 1px 0 rgba(255,255,255,0.95);
  }
}

/* data-theme=auto not used — existing system uses dark/light only */

/* ── 3. Theme toggle button (rendered by settings.ts) ───────────── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--t), border-color var(--t), color var(--t);
}
.theme-toggle:hover {
  background: var(--panel-3);
  border-color: var(--border-hover);
  color: var(--text);
}
.theme-toggle[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── 4. Accessibility — focus ring ──────────────────────────────── */
/* Remove default outline and replace with a visible, consistent focus ring
   that works on all interactive elements without disrupting visual design. */

/* Global focus-visible ring — keyboard only (not pointer) */
:focus-visible {
  outline: none;
  box-shadow: var(--focus, 0 0 0 3px rgba(97,117,255,0.38));
}

/* Ensure buttons, inputs, selects, links, and checkboxes always show ring */
button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(97,117,255,0.38);
}

/* Light theme focus ring */
body[data-theme="light"] button:focus-visible,
body[data-theme="light"] [role="button"]:focus-visible,
body[data-theme="light"] input:focus-visible,
body[data-theme="light"] textarea:focus-visible,
body[data-theme="light"] select:focus-visible,
body[data-theme="light"] a:focus-visible {
  box-shadow: 0 0 0 3px rgba(66,85,232,0.32);
}

/* Skip-to-content link for keyboard users */
.skip-link {
  position: absolute;
  box-shadow: var(--shadow-sm);
  top: -100px;
  left: 0;
  z-index: 9999;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: 0 0 var(--r-sm) 0;
  text-decoration: none;
  transition: top 0.1s;
}
.skip-link:focus {
  top: 0;
}

/* Better focus on table rows */
tr:focus-visible,
[role="row"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ── 5. Accessibility — sr-only (screen-reader only) ────────────── */
.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;
}

/* ── 6. DB error / 503 screen (пункт 4) ─────────────────────────── */
.db-error-screen {
  position: fixed;
  backdrop-filter: blur(18px) saturate(140%);
  inset: 0;
  z-index: 9990;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 32px 16px;
  text-align: center;
  animation: fadeUp 0.3s ease;
}

.db-error-screen__icon {
  box-shadow: var(--shadow-xs);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--warn-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  font-size: 26px;
}

.db-error-screen__title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.db-error-screen__body {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 360px;
  line-height: 1.6;
  margin-bottom: 24px;
}

.db-error-screen__countdown {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 20px;
  font-variant-numeric: tabular-nums;
}

.db-error-screen__btn {
  padding: 10px 24px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  transition: background var(--t), transform 0.1s;
}
.db-error-screen__btn:hover  { background: var(--accent-2); }
.db-error-screen__btn:active { transform: scale(0.97); }
.db-error-screen__btn:focus-visible { box-shadow: var(--focus); }
