/* Legacy Letters — senior-friendly, offline-first UI
   Accent: deep teal (#1F5F6B) — calm, trustworthy, letter-desk feel */

:root {
  --accent: #1f5f6b;
  --accent-hover: #174a54;
  --accent-soft: #e6f1f3;
  --accent-mid: #2a7a88;
  --danger: #a32020;
  --danger-soft: #fdecec;
  --warn: #8a5a00;
  --warn-soft: #fff4db;
  --ok: #1a6b4a;
  --ok-soft: #e6f4ed;
  --text: #1a1a1a;
  --text-muted: #4a5568;
  --border: #c8c4bc;
  --surface: #ffffff;
  --bg: #f7f5f1;
  --cream: #f0ebe3;
  --shadow: 0 2px 10px rgba(26, 26, 26, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --touch: 48px;
  --max: 720px;
}

*,
*::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;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.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;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 12px;
}

.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);
  scrollbar-width: thin;
}

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

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

.tab.active,
.tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--surface);
}

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

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

.panel[hidden] {
  display: none !important;
}

.panel-title {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  color: var(--text);
  line-height: 1.25;
}

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

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.panel-head .panel-lead {
  margin-bottom: 0;
}

/* 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.5;
  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-height: 2.5rem;
  padding: 0.35rem 0.5rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.btn-icon {
  background: transparent;
  border: 2px solid transparent;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.25rem;
  min-width: var(--touch);
  min-height: var(--touch);
}

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

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

.file-label {
  cursor: pointer;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 0.35rem;
  margin-left: 0.25rem;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

@media (min-width: 560px) {
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

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

.stat-card.stat-primary {
  border-color: var(--accent);
  background: linear-gradient(160deg, #fff 60%, var(--accent-soft));
}

.stat-card.stat-warn {
  border-color: #e0c070;
  background: linear-gradient(160deg, #fff 60%, var(--warn-soft));
}

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

.stat-value {
  margin: 0.2rem 0 0.4rem;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.stat-link {
  display: inline-block;
  background: none;
  border: none;
  padding: 0.25rem 0;
  min-height: auto;
  color: var(--accent);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.stat-link:hover {
  color: var(--accent-hover);
}

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

.location-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.location-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.location-pill strong {
  color: var(--text);
  font-weight: 700;
}

.loc-icon {
  font-size: 1rem;
}

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

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

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

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

.card-head h3 {
  margin: 0;
}

.card-text {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.meta-line {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

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

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.item-card:focus-within {
  border-color: var(--accent);
}

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

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

.item-title button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
  min-height: auto;
}

.item-title button:hover {
  color: var(--accent-hover);
}

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

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

.item-excerpt {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.15rem;
}

.item-actions .btn {
  min-height: var(--touch);
  padding: 0.45rem 0.85rem;
  font-size: 0.95rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--cream);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.chip-accent {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #b5d4da;
}

.chip-ok {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: #a8d4be;
}

.chip-warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: #e0c070;
}

.chip-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #e0a0a0;
}

.empty-msg {
  margin: 0.75rem 0;
  padding: 1.1rem;
  background: var(--cream);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-align: center;
}

/* Filters */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1rem;
  align-items: flex-end;
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.85rem;
  min-width: 0;
}

.field.grow {
  flex: 1 1 12rem;
  margin-bottom: 0;
}

.filter-bar .field {
  margin-bottom: 0;
  flex: 1 1 8rem;
}

.field-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.req {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 0.75rem;
}

@media (min-width: 520px) {
  .field-row {
    grid-template-columns: 1fr 1fr;
  }
}

input[type="text"],
input[type="search"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 0.6rem 0.75rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: none;
}

textarea {
  min-height: 6rem;
  resize: vertical;
  line-height: 1.45;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%231F5F6B' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  padding-right: 2.25rem;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 95, 107, 0.2);
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.inline-form .field {
  margin-bottom: 0;
}

.practice-box {
  background: var(--accent-soft);
  border: 1px solid #b5d4da;
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  margin-bottom: 0.85rem;
}

.timer-display {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--accent);
  min-width: 3.5rem;
  padding: 0.5rem 0;
}

/* Tips & bars */
.tips-list {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text);
}

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

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 7rem 1fr 2.5rem;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.9rem;
}

.bar-label {
  color: var(--text-muted);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 0.7rem;
  background: var(--cream);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  min-width: 0;
}

.bar-count {
  text-align: right;
  font-weight: 700;
  color: var(--text);
}

/* Dialogs */
.modal {
  border: none;
  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);
  background: var(--surface);
  color: var(--text);
}

.modal::backdrop {
  background: rgba(26, 26, 26, 0.5);
}

.modal-sm {
  max-width: min(420px, calc(100vw - 1.5rem));
}

.modal-form {
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 900px);
}

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

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

.modal-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.detail-block {
  margin-bottom: 1rem;
}

.detail-block h3 {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-block p,
.detail-body-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

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

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

.app-footer p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Print */
.print-root {
  display: none;
}

@media print {
  body * {
    visibility: hidden;
  }

  .print-root,
  .print-root * {
    visibility: visible;
  }

  .print-root {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    padding: 1rem;
    color: #000;
    background: #fff;
  }

  .print-root h1 {
    font-size: 1.4rem;
    margin: 0 0 0.5rem;
  }

  .print-root h2 {
    font-size: 1.15rem;
    margin: 1.25rem 0 0.4rem;
    border-bottom: 1px solid #999;
    padding-bottom: 0.2rem;
  }

  .print-root p,
  .print-root li {
    font-size: 0.95rem;
    line-height: 1.4;
  }

  .app-header,
  .tab-nav,
  #main,
  .app-footer,
  .toast,
  dialog {
    display: none !important;
  }
}

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