/* Client Base - calm, warm, simple. Colours live in the variables below. */

:root {
  --bg: #f7f5f1;
  --surface: #ffffff;
  --surface-2: #fbfaf7;
  --text: #22252a;
  --muted: #6c7078;
  --border: #e7e2da;
  --border-strong: #d6cfc4;
  --accent: #3f6f62;
  --accent-hover: #345d52;
  --accent-soft: #e6efeb;
  --danger: #a8443b;
  --danger-soft: #f7e9e7;
  --focus: #7fa99c;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(34, 37, 42, 0.04), 0 2px 8px rgba(34, 37, 42, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

  /* Stage colours (picked by position in the Settings list) */
  --tone-blue-bg: #e7eef8;   --tone-blue-fg: #2f5487;
  --tone-green-bg: #e4f1e8;  --tone-green-fg: #2f6b45;
  --tone-amber-bg: #f8eedb;  --tone-amber-fg: #85601b;
  --tone-violet-bg: #eeeaf6; --tone-violet-fg: #5a4785;
  --tone-grey-bg: #eeecea;   --tone-grey-fg: #5d5a56;
  --tone-rose-bg: #f7e7ea;   --tone-rose-fg: #8a3b4c;
  --tone-teal-bg: #e1f1f1;   --tone-teal-fg: #276666;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

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

h1, h2 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.9rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }

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

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---- Top bar ---- */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand:hover { color: var(--text); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-family: var(--font-display); font-size: 15px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; }
.brand-sub { font-size: 0.78rem; color: var(--muted); }
.nav { display: flex; gap: 4px; }
.nav a {
  text-decoration: none; color: var(--muted); padding: 8px 14px; border-radius: 999px; font-weight: 500;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.nav-button {
  font: inherit; font-weight: 500; color: var(--muted); background: none; border: none;
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
}
.nav-button:hover { color: var(--text); background: var(--surface-2); }
body.signed-out .nav { display: none; }

/* ---- Layout ---- */

.container { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.subtitle { margin: 8px 0 0; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: 12px; text-decoration: none; font-size: 0.9rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 20px; }

/* ---- Buttons ---- */

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
.button:hover { background: var(--surface-2); color: var(--text); border-color: var(--muted); }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-hover); color: #fff; }
.button.danger { color: var(--danger); border-color: #e2bdb8; }
.button.danger:hover { background: var(--danger-soft); }
.button.small { padding: 5px 10px; font-size: 0.85rem; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }

.link-button {
  background: none; border: none; padding: 0; font: inherit; color: var(--accent);
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.link-button.danger { color: var(--danger); }
.icon-button {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; color: var(--muted); font-size: 0.9rem;
}
.icon-button:disabled { opacity: 0.35; cursor: default; }

/* ---- Form controls ---- */

input[type="text"], input[type="email"], input[type="tel"], input[type="search"],
input[type="password"], input[type="date"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px 11px; width: 100%; min-height: 40px;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.invalid { border-color: var(--danger) !important; }

/* ---- Clients list ---- */

.stage-counts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.count-chip {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font: inherit; font-size: 0.9rem; padding: 6px 12px 6px 8px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.count-chip .count-label { padding-left: 4px; color: var(--muted); }
.count-chip strong { font-variant-numeric: tabular-nums; }
.count-chip:hover { border-color: var(--border-strong); }
.count-chip.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.toolbar { display: grid; grid-template-columns: minmax(200px, 2fr) 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.results { margin-top: 6px; }

.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow-x: auto;
}
.client-table { width: 100%; border-collapse: collapse; }
.client-table th {
  text-align: left; font-weight: 600; font-size: 0.8rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border); background: var(--surface-2); padding: 0;
}
.sort-button {
  font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit;
  background: none; border: none; cursor: pointer; padding: 11px 14px; width: 100%; text-align: left;
  white-space: nowrap;
}
.sort-button:hover { color: var(--text); }
th[aria-sort] .sort-button { color: var(--accent); }
.arrow { font-size: 0.7rem; }
.client-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.client-table tr:last-child td { border-bottom: none; }
.client-table tr.clickable { cursor: pointer; }
.client-table tr.clickable:hover td { background: var(--surface-2); }
.client-link { font-weight: 600; text-decoration: none; color: var(--text); }
.client-link:hover { color: var(--accent); text-decoration: underline; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.tone-blue   { background: var(--tone-blue-bg);   color: var(--tone-blue-fg); }
.tone-green  { background: var(--tone-green-bg);  color: var(--tone-green-fg); }
.tone-amber  { background: var(--tone-amber-bg);  color: var(--tone-amber-fg); }
.tone-violet { background: var(--tone-violet-bg); color: var(--tone-violet-fg); }
.tone-grey   { background: var(--tone-grey-bg);   color: var(--tone-grey-fg); }
.tone-rose   { background: var(--tone-rose-bg);   color: var(--tone-rose-fg); }
.tone-teal   { background: var(--tone-teal-bg);   color: var(--tone-teal-fg); }

.tags { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.tag {
  font-size: 0.78rem; padding: 1px 8px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}

.empty {
  text-align: center; padding: 48px 24px; background: var(--surface);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty h1, .empty h2 { margin-bottom: 8px; }
.empty p { color: var(--muted); max-width: 460px; margin: 0 auto 16px; }

/* ---- Profile ---- */

.profile-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 20px; align-items: start; }
.details { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; margin: 0; }
.detail dt { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.detail dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.notes { min-height: 160px; }

.timeline-form { display: flex; flex-direction: column; gap: 8px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.timeline-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.entry { padding: 14px 0 14px 18px; border-bottom: 1px solid var(--border); position: relative; }
.entry::before {
  content: ""; position: absolute; left: 0; top: 21px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent);
}
.entry.auto::before { background: var(--border-strong); }
.entry:last-child { border-bottom: none; }
.entry-meta { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; color: var(--muted); }
.entry-meta time { font-weight: 600; color: var(--text); }
.entry-type {
  font-size: 0.75rem; padding: 0 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}
.entry.auto .entry-type { background: var(--tone-grey-bg); color: var(--tone-grey-fg); }
.entry-meta .link-button { margin-left: auto; opacity: 0; transition: opacity 0.15s; }
.entry:hover .link-button, .entry .link-button:focus-visible { opacity: 1; }
.entry-text { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.entry.auto .entry-text { color: var(--muted); font-style: italic; }
.empty-line { padding: 16px 0; }

/* ---- Add / edit form ---- */

.client-form { max-width: 820px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.field label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 5px; }
.hint { margin: 4px 0 0; font-size: 0.8rem; color: var(--muted); }
.field-error { margin: 4px 0 0; font-size: 0.85rem; color: var(--danger); min-height: 0; }
.field-error:empty { display: none; }
.field-wrap .link-button { margin-top: 4px; }
.field-notes { margin-top: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.timeline-form .form-actions { margin-top: 0; }

/* ---- Settings ---- */

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.option-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.option-row { display: flex; align-items: center; gap: 8px; }
.option-row input[type="text"] { flex: 1; min-width: 0; }
.option-row.retired input[type="text"] { color: var(--muted); text-decoration: line-through; background: var(--surface-2); }
.move { display: flex; gap: 2px; }
.usage { white-space: nowrap; min-width: 64px; }
.checkbox { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; cursor: pointer; }
.add-row { display: flex; gap: 8px; }

/* ---- Sign in ---- */

.auth-wrap { display: flex; justify-content: center; padding-top: 6vh; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { margin-bottom: 8px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.auth-form .form-actions { justify-content: space-between; align-items: center; margin-top: 4px; }
.auth-form .form-actions :only-child { margin-left: auto; }

/* ---- Toast message ---- */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 0.9rem; opacity: 0; pointer-events: none; transition: all 0.2s; z-index: 10;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ---- Smaller screens ---- */

@media (max-width: 900px) {
  .profile-grid, .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  body { font-size: 16px; } /* stops phones zooming into inputs */
  .container { padding: 20px 16px 48px; }
  .topbar-inner { padding: 10px 16px; }
  .brand-sub { display: none; }
  h1 { font-size: 1.6rem; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar .search { grid-column: 1 / -1; }
  .form-grid, .details { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .option-row { flex-wrap: wrap; }
  .option-row input[type="text"] { flex-basis: calc(100% - 70px); }
  .entry-meta .link-button { opacity: 1; }

  /* The client table becomes a stack of cards */
  .table-wrap { background: none; border: none; box-shadow: none; }
  .client-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .client-table, .client-table tbody, .client-table tr, .client-table td { display: block; width: 100%; }
  .client-table tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 10px; padding: 8px 4px; box-shadow: var(--shadow);
  }
  .client-table td { border: none; padding: 4px 12px; display: flex; gap: 12px; }
  .client-table td::before {
    content: attr(data-label); flex: 0 0 72px; color: var(--muted); font-size: 0.8rem; padding-top: 2px;
  }
  .client-table td[data-label="Name"]::before { content: none; }
  .client-table td[data-label="Name"] { font-size: 1.05rem; padding-bottom: 6px; }
}
