/* styles.css — shared across index.html and admin.html
   Design intent: a dense operational tool, not a CRM dashboard. No cards,
   no avatars, no big whitespace — the owner processes hundreds of rows in
   one sitting, so every pixel of vertical space is budgeted. */

:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --border: #e1e4e8;
  --border-strong: #c7cbd1;
  --text: #16181d;
  --text-muted: #6b7280;
  --text-faint: #9aa1ab;
  --accent: #0f6a4f;       /* primary action (Send) */
  --accent-dark: #0b5340;
  --accent-contrast: #ffffff;
  --warn: #b45309;
  --danger: #b91c1c;
  --danger-bg: #fdecec;
  --highlight-bg: #eaf7f1;
  --row-height: 56px;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body { padding-bottom: env(safe-area-inset-bottom); }

a { color: var(--accent-dark); }

button, input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom-on-focus */
}

button {
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 12px;
  min-height: 40px;
}
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--accent-dark); }

button.subtle {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

button.danger { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="url"], select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

.tabular { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------- App shell ---------- */

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.screen { padding: 12px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px calc(8px + env(safe-area-inset-top) * 0);
}

.topbar-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.topbar-row:last-child { margin-bottom: 0; }
.topbar-row select { flex: 1; min-width: 0; }
.icon-btn { width: 40px; flex: 0 0 40px; padding: 8px; text-align: center; }

.filter-row { display: flex; gap: 6px; overflow-x: auto; }
.filter-chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  min-height: unset;
}
.filter-chip.active { background: var(--text); color: #fff; border-color: var(--text); }

/* ---------- Contact list ---------- */

.list-wrap { flex: 1; }

.contact-row {
  display: grid;
  grid-template-columns: 1fr 56px 64px 28px 46px 28px 28px;
  align-items: center;
  gap: 6px;
  min-height: var(--row-height);
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: background-color 0.25s ease;
}
.contact-row.just-highlighted { background: var(--highlight-bg); }

.contact-name { line-height: 1.15; min-width: 0; }
.contact-name .first, .contact-name .last { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-name .last { color: var(--text-muted); }
.contact-name .phone-only { color: var(--text-muted); font-size: 13px; }

.contact-phone { color: var(--text-muted); font-size: 13px; text-align: left; }

.send-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.02em;
  padding: 0;
  height: 34px;
  border-radius: var(--radius);
}
.send-btn:disabled { background: var(--border-strong); border-color: var(--border-strong); color: var(--text-faint); }

.count-cell { text-align: center; color: var(--text-muted); font-size: 13px; }
.last-sent-cell { text-align: center; color: var(--text-muted); font-size: 12px; }
.click-cell { text-align: center; font-size: 14px; }
.click-cell.clicked { color: var(--accent); }
.click-cell.not-clicked { color: var(--text-faint); }

.row-menu-btn { background: transparent; border: none; color: var(--text-faint); min-height: unset; padding: 4px; }

.list-headers {
  display: grid;
  grid-template-columns: 1fr 56px 64px 28px 46px 28px 28px;
  gap: 6px;
  padding: 6px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
}

.empty-list-note { padding: 24px 16px; text-align: center; color: var(--text-muted); }

/* ---------- Empty state / onboarding ---------- */

.empty-state {
  padding: 32px 20px;
  text-align: center;
}
.empty-state h2 { margin: 0 0 8px; font-size: 20px; }
.empty-state p { color: var(--text-muted); margin: 0 0 20px; }
.empty-state .actions { display: flex; flex-direction: column; gap: 10px; max-width: 320px; margin: 0 auto; }

/* ---------- Toast / undo ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.toast button { background: transparent; border: none; color: #7ee0bd; min-height: unset; padding: 0; font-weight: 700; }

/* ---------- Modals / sheets ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 14px 14px 0 0;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.sheet h3 { margin: 0 0 12px; }
.sheet .subdued-url { color: var(--text-faint); font-size: 12px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet-actions button { flex: 1; }

@media (min-width: 560px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 12px; max-width: 480px; }
}

/* ---------- Login / auth ---------- */

.auth-card {
  max-width: 360px;
  margin: 48px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}
.auth-card h1 { font-size: 18px; margin: 0 0 4px; }
.auth-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.auth-error { background: var(--danger-bg); color: var(--danger); padding: 8px 10px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }

/* ---------- Import wizard ---------- */

.import-steps { display: flex; gap: 4px; margin-bottom: 16px; font-size: 12px; color: var(--text-faint); }
.import-steps .step.active { color: var(--accent); font-weight: 700; }

.mapping-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.mapping-row .label { width: 110px; flex: 0 0 110px; font-size: 13px; color: var(--text-muted); }

.preview-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.preview-table { border-collapse: collapse; width: 100%; font-size: 12px; }
table.preview-table th, table.preview-table td {
  border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; white-space: nowrap;
}
table.preview-table tr.invalid td { background: var(--danger-bg); }

.summary-box { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.summary-box .metric { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.summary-box .metric b { font-variant-numeric: tabular-nums; }

.progress-bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin: 12px 0; }
.progress-bar > div { height: 100%; background: var(--accent); transition: width 0.2s ease; }

/* ---------- Settings / overflow menu ---------- */

.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list li { border-bottom: 1px solid var(--border); }
.menu-list button {
  width: 100%; text-align: left; border: none; background: transparent; border-radius: 0;
  padding: 12px 4px; font-size: 15px;
}

/* ---------- Admin-specific ---------- */

.admin-shell { max-width: 1100px; }
.admin-tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); padding: 8px 10px 0; background: var(--surface); position: sticky; top: 0; z-index: 20; }
.admin-tab { border: none; background: transparent; padding: 10px 12px; border-bottom: 2px solid transparent; color: var(--text-muted); border-radius: 0; min-height: unset; }
.admin-tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); }
table.data-table th, table.data-table td { border-bottom: 1px solid var(--border); padding: 8px; text-align: left; }
table.data-table th { font-size: 11px; text-transform: uppercase; color: var(--text-faint); letter-spacing: 0.03em; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.active { background: #e6f4ea; color: #1e7e34; }
.badge.disabled { background: var(--danger-bg); color: var(--danger); }
.badge.invited { background: #fff4e5; color: var(--warn); }
.badge.accepted { background: #e6f4ea; color: #1e7e34; }

.section-title { font-size: 16px; font-weight: 700; margin: 20px 0 10px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; min-width: 160px; }

.small-note { font-size: 12px; color: var(--text-faint); }

.loading-state, .blocked-state { padding: 40px 16px; text-align: center; color: var(--text-muted); }

@media (min-width: 720px) {
  #app.owner-app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
