/* ContactBook Plus — senior-friendly, offline-first UI */

:root {
  --accent: #0d6e6e;
  --accent-hover: #0a5555;
  --accent-soft: #e6f4f4;
  --accent-mid: #149494;
  --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: #f3f6f6;
  --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;
}

img {
  max-width: 100%;
}

/* 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-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.25rem;
  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;
}

.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;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

/* Cards & stats */
.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-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.card-head h3,
.card > h3 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.card-head h3 {
  margin-bottom: 0;
}

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

.sample-card {
  border-color: var(--accent);
  border-style: dashed;
  background: var(--accent-soft);
}

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

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 0.85rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

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

.stat-card.stat-warn {
  border-color: #d4a017;
  background: var(--warn-soft);
}

.stat-card.stat-danger {
  border-color: #d07070;
  background: var(--danger-soft);
}

.stat-card.stat-ok {
  border-color: #5aab85;
  background: var(--ok-soft);
}

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

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

.stat-card.stat-primary .stat-value {
  color: var(--accent);
}

.stat-card.stat-warn .stat-value {
  color: var(--warn);
}

.stat-card.stat-danger .stat-value {
  color: var(--danger);
}

.stat-card.stat-ok .stat-value {
  color: var(--ok);
}

.stat-link {
  margin-top: 0.35rem;
  padding: 0.35rem 0;
  min-height: 44px;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.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.15rem;
}

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

.location-pill strong {
  color: var(--text);
  font-size: 1.05rem;
}

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

/* Filters */
.filters {
  margin-bottom: 1rem;
}

.field {
  margin-bottom: 0.9rem;
}

.field:last-child {
  margin-bottom: 0;
}

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

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

.field-hint {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field input[type="text"],
.field input[type="number"],
.field input[type="search"],
.field input[type="date"],
.field input[type="tel"],
.field input[type="email"],
.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: 5rem;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 110, 110, 0.22);
}

.field input::placeholder,
.field textarea::placeholder {
  color: #7a8494;
}

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

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

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

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

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.checkbox-field input[type="checkbox"] {
  width: 1.4rem;
  height: 1.4rem;
  min-width: 1.4rem;
  margin-top: 0.15rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.checkbox-field label {
  margin: 0;
  font-weight: 500;
  cursor: pointer;
}

.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;
}

/* Photo picker */
.photo-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.1rem;
  padding: 0.85rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.photo-actions {
  flex: 1;
  min-width: 10rem;
}

/* Avatars */
.avatar,
.avatar-lg,
.avatar-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.avatar {
  width: 64px;
  height: 64px;
  font-size: 1.25rem;
}

.avatar-lg {
  width: 88px;
  height: 88px;
  font-size: 1.6rem;
}

.avatar-sm {
  width: 48px;
  height: 48px;
  font-size: 1rem;
}

.avatar img,
.avatar-lg img,
.avatar-sm img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Item lists & contact cards */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.contact-grid {
  gap: 0.85rem;
}

.item-card {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  padding: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.item-card.nudge {
  border-color: #d4a017;
  background: #fffdf5;
}

.item-card.birthday {
  border-color: #5aab85;
  background: #f5fbf8;
}

.item-main {
  flex: 1;
  min-width: 0;
}

.item-title {
  margin: 0 0 0.15rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

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

.item-notes {
  margin: 0.4rem 0 0;
  font-size: 0.95rem;
  color: var(--text);
  font-style: italic;
}

.item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.tag.tag-nudge {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: #e0c06a;
}

.tag.tag-bday {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: #8ec9ad;
}

.tag.tag-sample {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #8ec5c5;
}

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

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

/* Result count / empty */
.result-count {
  margin: 0 0 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.empty-msg {
  margin: 0.5rem 0 0;
  padding: 1rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-align: center;
}

.status-msg {
  margin: 0.65rem 0 0;
  font-weight: 600;
  color: var(--accent);
  min-height: 1.4em;
}

.muted {
  color: var(--text-muted);
}

.subhead {
  margin: 1.1rem 0 0.55rem;
  font-size: 1rem;
  color: var(--text);
}

/* Category / relationship bars */
.category-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.cat-row {
  display: grid;
  grid-template-columns: 7.5rem 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.cat-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.cat-bar-track {
  height: 12px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

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

.cat-count {
  font-weight: 700;
  color: var(--text);
  min-width: 1.5rem;
  text-align: right;
}

@media (max-width: 420px) {
  .cat-row {
    grid-template-columns: 1fr auto;
  }
  .cat-bar-track {
    grid-column: 1 / -1;
  }
}

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

.tip-list li {
  margin-bottom: 0.55rem;
  color: var(--text);
}

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

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

/* Detail view */
.detail-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  margin-bottom: 1.15rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.detail-name {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.detail-relation {
  margin: 0;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.detail-dl {
  margin: 0;
}

.detail-row {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  gap: 0.35rem 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--bg);
}

.detail-row dt {
  margin: 0;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.detail-row dd {
  margin: 0;
  color: var(--text);
  word-break: break-word;
}

.detail-row dd a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.detail-notes-box {
  margin-top: 1rem;
  padding: 0.85rem;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  border: 1px solid #b5d9d9;
}

.detail-notes-box h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.detail-notes-box p {
  margin: 0;
  white-space: pre-wrap;
}

/* Modal / dialog */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(520px, calc(100vw - 1.5rem));
  width: 100%;
  box-shadow: 0 12px 40px rgba(26, 31, 40, 0.22);
  color: var(--text);
  background: var(--surface);
}

.modal::backdrop {
  background: rgba(26, 31, 40, 0.55);
}

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

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

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

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

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

.modal-footer-wrap {
  justify-content: stretch;
}

.modal-footer-wrap .btn {
  flex: 1 1 auto;
}

.modal-lead {
  margin: 0 0 0.75rem;
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  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 6px 24px rgba(0, 0, 0, 0.25);
  text-align: center;
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 1.1rem 1rem 1.4rem;
  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);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .btn,
  .tab {
    transition: none;
  }
}

/* Print-friendly basics */
@media print {
  .tab-nav,
  .header-actions,
  .app-footer,
  .skip-link {
    display: none;
  }
  body {
    background: #fff;
  }
}
