/* act.texnet.ca — call tracking
   Replaces a 2013 interface: fixed-width, image buttons, jQuery UI dialogs
   with iframes inside them. This is fluid, keyboard-navigable, and works on a
   phone, which the old one did not. */

:root {
  --bg:         #f6f7f9;
  --surface:    #ffffff;
  --surface-2:  #eef1f5;
  --ink:        #14181f;
  --ink-soft:   #414c5c;
  --muted:      #6b7686;
  --rule:       #dfe4ea;
  --rule-soft:  #eceff3;
  --accent:     #1668b3;
  --accent-ink: #ffffff;
  --accent-dim: #e6f0f9;
  --good:       #1c7350;
  --good-dim:   #e2f0ea;
  --warn:       #8a5a11;
  --warn-dim:   #f8eeda;
  --bad:        #a8403a;
  --bad-dim:    #f7e5e3;

  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Inter Tight", var(--sans);

  --r: 8px;
  --shell: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0f1319;
    --surface:   #161b23;
    --surface-2: #1d232d;
    --ink:       #e8ebef;
    --ink-soft:  #bcc4d0;
    --muted:     #8b95a4;
    --rule:      #28303b;
    --rule-soft: #212832;
    --accent:    #5aa9e8;
    --accent-ink:#0f1319;
    --accent-dim:#15293c;
    --good:      #5bbd95;
    --good-dim:  #13291f;
    --warn:      #d5a45b;
    --warn-dim:  #2a2113;
    --bad:       #e0877f;
    --bad-dim:   #2c1a18;
  }
}
:root[data-theme="dark"] {
  --bg:#0f1319; --surface:#161b23; --surface-2:#1d232d;
  --ink:#e8ebef; --ink-soft:#bcc4d0; --muted:#8b95a4;
  --rule:#28303b; --rule-soft:#212832;
  --accent:#5aa9e8; --accent-ink:#0f1319; --accent-dim:#15293c;
  --good:#5bbd95; --good-dim:#13291f; --warn:#d5a45b; --warn-dim:#2a2113;
  --bad:#e0877f; --bad-dim:#2c1a18;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------- top bar */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--ink);
  padding: 14px 0;
}
.brand-mark {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.brand-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}

.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a {
  display: block;
  padding: 16px 12px 14px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.nav a:hover { color: var(--ink); }
.nav a.is-current { color: var(--ink); border-bottom-color: var(--accent); }
.nav a:focus-visible,
a:focus-visible, button:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

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

.shell { max-width: var(--shell); margin: 0 auto; padding: 26px 20px 80px; }

.page-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  margin: 0;
}
.page-sub { color: var(--muted); font-size: 13.5px; }

/* ------------------------------------------------------------ card */

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  padding: 13px 16px;
  border-bottom: 1px solid var(--rule-soft);
  background: var(--surface);
}
.card-title { font-family: var(--display); font-weight: 600; font-size: 1rem; }
.card-body { padding: 16px; }

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

.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.control { display: flex; align-items: center; gap: 6px; }
.control label { font-size: 12.5px; color: var(--muted); }

select {
  font: inherit;
  font-size: 13.5px;
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

/* ----------------------------------------------------------- chart */

.chart-wrap { overflow-x: auto; padding: 8px 4px 0; }
.chart { display: block; width: 100%; min-width: 560px; height: auto; }
.chart .grid    { stroke: var(--rule-soft); stroke-width: 1; }
.chart .axis    { stroke: var(--rule); stroke-width: 1; }
.chart .bar     { fill: var(--accent); }
.chart .bar:hover { fill: var(--ink); }
.chart .bar-total {
  fill: var(--ink);
  font-family: var(--display);
  font-size: 13px;
  font-weight: 700;
  text-anchor: middle;
}
.chart .x-label {
  fill: var(--muted); font-size: 11.5px; text-anchor: middle;
}
.chart .y-label {
  fill: var(--muted); font-size: 11px; text-anchor: end;
}

.chart-empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ----------------------------------------------------------- stats */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--rule);
  border-top: 1px solid var(--rule);
}
.stat { background: var(--surface); padding: 14px 16px; }
.stat-n {
  font-family: var(--display); font-weight: 700; font-size: 1.5rem;
  letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
}
.stat-l { font-size: 12px; color: var(--muted); }

/* ----------------------------------------------------------- table */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface-2);
  white-space: nowrap;
}
td { padding: 11px 16px; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.dim, .dim { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ------------------------------------------------------------ pill */

.pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill-good { background: var(--good-dim); color: var(--good); }
.pill-warn { background: var(--warn-dim); color: var(--warn); }
.pill-bad  { background: var(--bad-dim);  color: var(--bad); }
.pill-mute { background: var(--surface-2); color: var(--muted); }

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

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------- sign in
   Standalone auth pages. No topbar: every nav link needs a session. */

.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
}

.auth-wrap { width: 100%; max-width: 380px; }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 30px 28px 32px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 22px;
}

.auth-title {
  font-family: var(--display);
  font-size: 1.28rem;
  font-weight: 600;
  margin: 0 0 6px;
}

.auth-note {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.55;
  margin: 0 0 18px;
}

.auth-note code {
  font-size: 0.83em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
}

.auth-link { color: var(--accent); text-decoration: none; font-weight: 500; }
.auth-link:hover { text-decoration: underline; }

.auth-error {
  background: var(--bad-dim);
  color: var(--bad);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 0.875rem;
  margin: 0 0 16px;
}

.auth-form { display: grid; gap: 7px; }

.auth-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}

.auth-input {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px 12px;
  width: 100%;
  margin-bottom: 8px;
}

.auth-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.auth-btn {
  font: inherit;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  margin-top: 6px;
  cursor: pointer;
}

.auth-btn:hover { filter: brightness(1.07); }

/* Sign out sits in the topbar, styled to read as nav rather than a control. */
.signout {
  margin-left: auto;
  display: flex;
}

.signout button {
  font: inherit;
  font-size: 0.875rem;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 6px 2px;
  cursor: pointer;
}

.signout button:hover { color: var(--ink); }

/* ------------------------------------------------------------ forms
   Shared by the Numbers and Settings screens. */

input[type="text"],
input[type="password"],
input[type="tel"] {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 7px 10px;
  max-width: 100%;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="tel"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

input.mono-input { font-variant-numeric: tabular-nums; }

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); color: var(--ink); }

.btn-primary {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: transparent;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.07); border-color: transparent; }

.card-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-top: 1px solid var(--rule-soft);
  background: var(--surface-2);
}

.notice {
  border-radius: 6px;
  padding: 10px 13px;
  font-size: 13.5px;
  margin-bottom: 16px;
}
.notice-good { background: var(--good-dim); color: var(--good); }
.notice-warn { background: var(--warn-dim); color: var(--warn); }
.notice-bad  { background: var(--bad-dim);  color: var(--bad); }

/* A URL meant to be copied out and pasted into someone else's console. */
.urlbox {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  white-space: nowrap;
  color: var(--ink);
}

.form-grid {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 16px 20px;
  align-items: start;
  padding: 16px;
}
.form-grid > .lbl {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
  padding-top: 8px;
}
.help { font-size: 12.5px; color: var(--muted); margin-top: 5px; line-height: 1.5; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; gap: 6px 0; }
  .form-grid > .lbl { padding-top: 14px; }
}

.kv { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 9px 20px; padding: 16px; font-size: 13.5px; }
.kv > dt { color: var(--muted); }
.kv > dd { margin: 0; color: var(--ink); }

/* A nav entry for a page that does not exist yet — present, but inert. */
.nav-todo {
  display: block;
  padding: 16px 12px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  opacity: 0.45;
  cursor: default;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}

/* A submit button that reads as a quiet link — used for row actions inside a
   table, where a full button would dominate the cell it sits in. */
.btn-link {
  font: inherit;
  font-size: 12.5px;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
}
.btn-link:hover { text-decoration: underline; }

/* .btn on an anchor: match the button's box so links and buttons line up. */
a.btn { display: inline-block; text-decoration: none; line-height: 1.2; }

/* ------------------------------------------------------------------- demo

   Only rendered on the public display copy at demo.texnet.ca (DEMO_MODE=1).
   Uses the existing warn tokens so it reads as a notice rather than an error,
   and sits between the header and the shell so it is the first thing under the
   nav on every page without displacing anything. Deliberately not sticky: it
   is a standing fact about the deployment, not an alert to dismiss. */

.demobar {
  max-width: var(--shell);
  margin: 14px auto -6px;
  padding: 8px 14px;
  background: var(--warn-dim);
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 22%, transparent);
  border-radius: var(--r);
  font-size: 0.84rem;
  line-height: 1.5;
  display: flex;
  flex-wrap: wrap;
  gap: 0 6px;
  align-items: baseline;
}

.demobar strong { font-family: var(--display); font-weight: 600; letter-spacing: 0.01em; }

/* Shown only when DB_NAME does not look like a demo database — the one
   configuration mistake that would put real callers on a public page. */
.demobar-warn {
  font-style: normal;
  font-weight: 600;
  color: var(--bad);
  background: var(--bad-dim);
  border-radius: 5px;
  padding: 1px 7px;
}

@media (max-width: 760px) {
  .demobar { margin: 10px 12px -4px; border-radius: 6px; }
}

/* The login screen's own notice. Carries the demo password, since the whole
   point is that a stranger with the link can get in. */
.auth-demo {
  background: var(--warn-dim);
  color: var(--warn);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.85rem;
  line-height: 1.55;
  margin: 0 0 16px;
  text-align: left;
}

.auth-demo code {
  font-size: 0.86em;
  font-weight: 600;
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  padding: 1px 6px;
  border-radius: 4px;
}
