/* ── Lucere Mobile Companion PWA ── */

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

:root {
  --navy:    #1e3a5f;
  --navy-dk: #15294a;
  --accent:  #2563eb;
  --surface: #f8fafc;
  --border:  #e2e8f0;
  --text:    #1e293b;
  --muted:   #64748b;
  --green:   #15803d;
  --red:     #dc2626;
  --amber:   #d97706;
  --card-bg: #ffffff;
  --nav-h:   60px;
  --header-h: 56px;
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

/* ── Top header ── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  background: var(--navy);
  color: white;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: env(safe-area-inset-top, 0px) 16px 0;
  z-index: 100;
}

.header-title { font-weight: 700; font-size: 1rem; flex: 1; }

.property-select {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.85rem;
  max-width: 160px;
}
.property-select option { color: var(--text); background: white; }

/* ── Main content area ── */
.page-content {
  padding: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 12px) 16px
           calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
  min-height: 100vh;
}

/* ── Bottom navigation ── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.7rem;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  padding: 6px 0;
  transition: color 0.15s;
}
.nav-tab .icon { font-size: 1.4rem; }
.nav-tab.active { color: var(--accent); }

/* ── Cards ── */
.card {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
  overflow: hidden;
}

.card-header {
  padding: 14px 16px;
  font-weight: 700;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.card-body { padding: 16px; }

/* ── Form elements ── */
.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text);
}

input[type="text"], input[type="email"], input[type="number"],
input[type="date"], textarea, select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: white;
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  min-height: 48px;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

/* ── Radio / toggle pills ── */
.pill-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill-group input[type="radio"] { display: none; }

.pill-group label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 80px;
  padding: 10px 16px;
  border: 2px solid var(--border);
  border-radius: 24px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--muted);
  background: white;
}

.pill-group input[type="radio"]:checked + label {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(37,99,235,0.06);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 20px;
  min-height: 52px;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
}

.btn:active { transform: scale(0.98); }

.btn-primary   { background: var(--accent); color: white; }
.btn-success   { background: var(--green); color: white; }
.btn-danger    { background: var(--red); color: white; }
.btn-secondary { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-outline   { background: transparent; color: var(--accent); border: 2px solid var(--accent); }

.btn:disabled { opacity: 0.5; pointer-events: none; }

/* ── GPS trip status area ── */
.trip-status {
  text-align: center;
  padding: 24px 16px;
}

.trip-stat-big {
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  color: var(--navy);
}

.trip-stat-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

.trip-stats-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 20px;
}

.trip-mini-stat {
  text-align: center;
}

.trip-mini-stat .val {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--navy);
}

.trip-mini-stat .lbl {
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Clock display ── */
.clock-display {
  text-align: center;
  padding: 20px 16px 12px;
}

.clock-time {
  font-size: 2.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--navy);
  letter-spacing: 0.02em;
}

.clock-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Toast notification ── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  white-space: nowrap;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* ── Section divider ── */
.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 20px 0 10px;
}

/* ── Two-column layout for wider screens ── */
@media (min-width: 480px) {
  .page-content { max-width: 480px; margin: 0 auto; }
}

/* ── Device import ── */
.import-row {
  display: flex;
  gap: 12px;
  margin-bottom: 4px;
}

.btn-import {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 8px;
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 72px;
}

.btn-import:active { background: var(--surface); }

.import-icon { font-size: 1.6rem; }

/* ── Import header (back nav) ── */
.import-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 12px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.btn-back {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
  min-height: 44px;
  white-space: nowrap;
}

.btn-select-all {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
}

/* ── Call list ── */
.call-list {
  padding: 0;
  overflow: hidden;
}

.call-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  min-height: 62px;
}

.call-row:last-child { border-bottom: none; }
.call-row:active { background: var(--surface); }

.call-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.call-dir-icon { font-size: 1.25rem; flex-shrink: 0; }

.call-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }

.call-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.call-number { font-size: 0.8rem; color: var(--muted); }
.call-meta   { font-size: 0.8rem; color: var(--muted); }

/* ── Search bar ── */
.search-bar {
  margin-bottom: 12px;
}

.search-bar input[type="search"] {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 14px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  color: var(--text);
  outline: none;
}

.search-bar input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(30,58,95,0.12);
}

/* ── Attribution form (appears after selecting calls) ── */
.attribution-form { margin-top: 8px; }

/* ── SMS threads ── */
.sms-thread-card { margin-bottom: 8px; }

.sms-thread-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.sms-contact-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sms-contact-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.sms-contact-number {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Message picker (per-message selection in SMS log form) */
.msg-pick-row {
  display: grid;
  grid-template-columns: 24px auto 1fr;
  grid-template-rows: auto auto;
  gap: 4px 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  line-height: 1.4;
  align-items: start;
}
.msg-pick-row:last-child { border-bottom: none; }
.msg-pick-row input[type="checkbox"] {
  margin-top: 3px;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  grid-row: 1;
  grid-column: 1;
}
.msg-pick-meta {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  grid-row: 1;
  grid-column: 2;
  align-self: center;
}
.msg-pick-body {
  font-size: 0.9rem;
  color: var(--text);
  word-break: break-word;
  grid-row: 1;
  grid-column: 3;
}
.att-row {
  grid-row: 2;
  grid-column: 2 / -1;
}

/* Attachment chips in message picker */
.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--border);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 0.8rem;
  color: var(--text);
  max-width: 100%;
}
.att-chip.att-img {
  padding: 2px;
  background: transparent;
  border: 1px solid var(--border);
}
.att-thumb {
  max-width: 90px;
  max-height: 70px;
  border-radius: 4px;
  display: block;
  object-fit: cover;
}
.att-loading {
  font-size: 1.4rem;
  padding: 4px 6px;
}
.att-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.rcs-status {
  margin-bottom: 8px;
}
.rcs-status .card-body {
  padding: 12px 16px;
}

/* success green (reuse for RCS active indicator) */
:root { --success: #15803d; }

.sms-thread-meta { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }

.sms-preview {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
