/* Clearview Reader — senior-friendly, offline-first UI */

:root {
  --accent: #0c4a6e;
  --accent-hover: #083552;
  --accent-soft: #e0f2fe;
  --accent-mid: #0369a1;
  --danger: #a32020;
  --danger-soft: #fdecec;
  --warn: #8a5a00;
  --warn-soft: #fff4db;
  --ok: #1a6b4a;
  --ok-soft: #e6f4ed;
  --text: #1a1f28;
  --text-muted: #4a5568;
  --border: #c5cdd9;
  --surface: #ffffff;
  --bg: #f0f5f9;
  --shadow: 0 2px 10px rgba(26, 31, 40, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --touch: 48px;
  --max: 720px;
  --space: 1rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  z-index: 1000;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.85rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  font-size: 1.75rem;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.tagline {
  margin: 0.1rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Tab nav */
.tab-nav {
  max-width: var(--max);
  margin: 0 auto;
  width: 100%;
  display: flex;
  gap: 0.25rem;
  padding: 0.65rem 0.75rem 0;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 40;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 2px solid var(--border);
}

.tab {
  flex: 1 1 auto;
  min-height: var(--touch);
  min-width: 4.5rem;
  padding: 0.5rem 0.65rem;
  border: 2px solid transparent;
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.tab:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.tab.active {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--border);
  border-bottom: 2px solid var(--surface);
  margin-bottom: -2px;
}

/* Main */
main {
  flex: 1;
  max-width: var(--max);
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.panel-title {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  color: var(--text);
}

.panel-lead {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.6rem 1.1rem;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--accent-soft);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: #861a1a;
}

.btn-text {
  background: transparent;
  color: var(--accent);
  border-color: transparent;
  min-width: auto;
  padding: 0.4rem 0.6rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-text:hover:not(:disabled) {
  color: var(--accent-hover);
  background: var(--accent-soft);
}

.btn-sm {
  min-height: 44px;
  padding: 0.4rem 0.75rem;
  font-size: 0.95rem;
}

.btn-step {
  min-width: var(--touch);
  padding: 0.4rem 0.65rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch);
  min-height: var(--touch);
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-icon:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.75rem;
}

/* Cards & stats */
.card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.card-head h3 {
  margin: 0;
}

.card h3 {
  margin: 0 0 0.65rem;
  font-size: 1.1rem;
  color: var(--text);
}

.sample-card {
  border-color: var(--accent-mid);
  background: linear-gradient(180deg, #f0f9ff 0%, var(--surface) 48%);
}

.danger-card {
  border-color: #e0a0a0;
  background: #fffafa;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.stat-grid.compact {
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}

.stat-card.stat-primary {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.stat-card.stat-accent {
  border-color: #7dd3fc;
  background: #f0f9ff;
}

.stat-label {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-value {
  margin: 0.2rem 0 0.45rem;
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.15;
}

.stat-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.2rem 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.stat-link:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Forms */
.field {
  margin-bottom: 0.9rem;
}

.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.field input[type="text"],
.field input[type="search"],
.field input[type="range"],
.field select,
.field textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 0.55rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--text);
  background: var(--surface);
}

.field textarea {
  min-height: 8rem;
  resize: vertical;
  line-height: 1.45;
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

.field-hint,
.hint {
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.req {
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--danger);
}

.check-label {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  min-height: var(--touch);
  padding: 0.35rem 0;
  cursor: pointer;
  font-weight: 500;
}

.check-label input {
  width: 1.35rem;
  height: 1.35rem;
  margin-top: 0.15rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

@media (min-width: 560px) {
  .filter-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.filters .field:last-of-type {
  margin-bottom: 0.25rem;
}

/* Lists */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.item-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}

.item-card.is-favorite {
  border-color: var(--accent-mid);
}

.item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.item-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}

.item-meta {
  margin: 0.15rem 0 0.45rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.item-preview {
  margin: 0 0 0.65rem;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.pill.sample {
  background: var(--warn-soft);
  color: var(--warn);
}

.empty-msg {
  margin: 0.5rem 0 0;
  padding: 1rem;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

.result-count,
.status-msg {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 500;
}

.howto-list {
  margin: 0 0 0.75rem;
  padding-left: 1.35rem;
}

.howto-list li {
  margin-bottom: 0.45rem;
}

.tip-list {
  margin: 0;
  padding-left: 1.25rem;
}

.tip-list li {
  margin-bottom: 0.5rem;
}

/* Category breakdown */
.category-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.category-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.75rem;
  align-items: center;
}

.category-name {
  font-weight: 600;
}

.category-count {
  font-weight: 700;
  color: var(--accent);
}

.category-bar {
  grid-column: 1 / -1;
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.category-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  min-width: 0;
}

/* Reader */
.reader-empty-card {
  text-align: left;
}

.reader-toolbar {
  margin-bottom: 1rem;
}

.reader-kicker {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.reader-title {
  margin: 0.15rem 0 0.85rem;
  font-size: 1.25rem;
  line-height: 1.25;
}

.reader-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

@media (min-width: 560px) {
  .reader-controls {
    grid-template-columns: 1.4fr 1fr 1fr;
  }
}

.control-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.stepper {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.stepper input[type="range"] {
  flex: 1 1 120px;
  min-height: 44px;
  accent-color: var(--accent);
}

.stepper-value {
  min-width: 3.5rem;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
}

.speech-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
}

.speech-rate-field {
  margin: 0;
  min-width: 7rem;
}

.speech-rate-field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

.speech-rate-field select {
  min-height: var(--touch);
  padding: 0.45rem 0.65rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface);
}

.reader-actions {
  margin-top: 0.65rem;
}

.reader-stage {
  border: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.15rem;
  min-height: 12rem;
  box-shadow: var(--shadow);
}

.reader-body {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-weight: 500;
}

.reader-notes {
  margin: 0.85rem 0 0;
  padding: 0.85rem 1rem;
  background: var(--warn-soft);
  border: 2px solid #e8c96a;
  border-radius: var(--radius-sm);
  color: var(--text);
}

/* Contrast modes — WCAG AA+ */
.contrast-light {
  background: #ffffff;
  color: #111111;
}

.contrast-dark {
  background: #000000;
  color: #ffffff;
  border-color: #333;
}

.contrast-yellow {
  background: #fff59d;
  color: #111111;
  border-color: #c9b84a;
}

.contrast-soft {
  background: #faf6eb;
  color: #0b2e4a;
  border-color: #c9b98a;
}

/* Dialogs */
dialog {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  max-width: min(560px, calc(100vw - 1.5rem));
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  color: var(--text);
  background: var(--surface);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-bottom: 2px solid var(--border);
}

.dialog-head h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--accent);
}

.dialog-body {
  padding: 1rem;
  max-height: min(70vh, 520px);
  overflow-y: auto;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
  padding: 0.85rem 1rem;
  border-top: 2px solid var(--border);
  background: var(--bg);
}

.form-error {
  margin: 0.5rem 0 0;
  padding: 0.65rem 0.75rem;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(480px, calc(100vw - 2rem));
  padding: 0.85rem 1.15rem;
  background: var(--text);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.toast[hidden] {
  display: none;
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 1.1rem 1rem 1.4rem;
  text-align: center;
  border-top: 2px solid var(--border);
  background: var(--surface);
}

.app-footer p {
  margin: 0;
  max-width: var(--max);
  margin-inline: auto;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
