@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@500;600&family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

/* ============================================================
   Tokens — enamelled telecom equipment: slate panels, signal lamps
   ============================================================ */
:root {
  --panel:        #161B22;
  --panel-raised: #1E252E;
  --panel-sunk:   #11151B;
  --edge:         #2C3540;
  --edge-bright:  #3D4855;

  --ink:      #E6E9ED;
  --ink-dim:  #8B95A3;
  --ink-faint:#5C6673;

  --lamp-idle: #4A5563;
  --lamp-ring: #FFB020;   /* dialling / ringing */
  --lamp-live: #35D08A;   /* connected to agent */
  --lamp-dead: #E5484D;   /* failed */
  --lamp-out:  #8B7FD4;   /* opted out */

  --font-display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --font-body:    'IBM Plex Sans', system-ui, sans-serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, monospace;

  --radius: 3px;
  --gap: 20px;
}


/* ---- Light theme: same equipment, daylight enamel ---- */
[data-theme="light"] {
  --panel:        #FFFFFF;
  --panel-raised: #EFF2F5;
  --panel-sunk:   #E4E9ED;
  --edge:         #D3D9DF;
  --edge-bright:  #B4BDC7;

  --ink:      #171C22;
  --ink-dim:  #56616F;
  --ink-faint:#828D9B;

  --lamp-idle: #C0C8D1;
  --lamp-ring: #C97A00;
  --lamp-live: #0B8F62;
  --lamp-dead: #C8353A;
  --lamp-out:  #5F42BF;
}

[data-theme="light"] body {
  background: #F4F7F9;
  background-image: repeating-linear-gradient(
    180deg, transparent 0 3px, rgba(0,0,0,.012) 3px 4px);
}
[data-theme="light"] .key-go   { background:#DFF3E8; border-color:#8FCFB0; color:#0A5F42; }
[data-theme="light"] .key-go:hover { background:#CFEBDD; }
[data-theme="light"] .key-stop { background:#FBE3E4; border-color:#E5A3A6; color:#8E2226; }
[data-theme="light"] .key-stop:hover { background:#F6D3D5; }
[data-theme="light"] .key:hover { background:#E4E9EE; }
[data-theme="light"] .alert  { background:#FBE3E4; border-color:#E5A3A6; color:#8E2226; }
[data-theme="light"] .notice { background:#DFF3E8; border-color:#8FCFB0; color:#0A5F42; }
[data-theme="light"] .lamp   { border-color:#DDE3E8; box-shadow:0 0 0 1px var(--edge-bright), inset 0 3px 10px rgba(0,0,0,.16); }
[data-theme="light"] .log-row { border-bottom-color:#E9EDF1; }
[data-theme="light"] td { border-bottom-color:#E9EDF1; }

* { box-sizing: border-box; }

/* display overrides below must never resurrect a hidden element */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--panel-sunk);
  background-image: repeating-linear-gradient(
    180deg, transparent 0 3px, rgba(255,255,255,.012) 3px 4px);
  color: var(--ink);
  font: 400 15px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

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

/* ---- Type ---- */
.display {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(26px, 3.4vw, 38px);
  letter-spacing: .01em;
  line-height: 1.1;
  margin: 0 0 6px;
}
.eyebrow {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 10px;
}
.muted  { color: var(--ink-dim); margin: 0 0 18px; }
.hint   { color: var(--ink-faint); font-size: 12px; font-weight: 400; }
.mono   { font-family: var(--font-mono); }

/* ---- Panels ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 24px;
}
.panel.setup { width: min(440px, 100%); }

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--edge);
}
.panel-head h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin: 0;
}

/* ---- App chrome ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--edge);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.brand span { color: var(--lamp-ring); }
.topbar nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.topbar nav a {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius);
}
.topbar nav a:hover { color: var(--ink); background: var(--panel-raised); }
.topbar nav a[aria-current="page"] { color: var(--lamp-ring); background: var(--panel-raised); }

.wrap { max-width: 1180px; margin: 0 auto; padding: var(--gap); }
.grid-console {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: var(--gap);
  align-items: start;
}
.stack { display: grid; gap: 14px; }
.stack-cols { align-items: end; }

/* ============================================================
   Signature: the line lamp + handset panel
   ============================================================ */
.handset {
  text-align: center;
  display: flex;
  flex-direction: column;
}
.handset .key-row { margin-top: auto; }

.lamp {
  width: 96px;
  height: 96px;
  margin: 4px auto 20px;
  border-radius: 50%;
  background: var(--lamp-idle);
  border: 5px solid var(--panel-sunk);
  box-shadow: 0 0 0 1px var(--edge-bright), inset 0 3px 10px rgba(0,0,0,.5);
  transition: background .25s ease, box-shadow .25s ease;
}
.lamp[data-state="dialing"],
.lamp[data-state="ringing"] {
  background: var(--lamp-ring);
  box-shadow: 0 0 0 1px var(--edge-bright), 0 0 34px -4px var(--lamp-ring);
  animation: pulse 1.15s ease-in-out infinite;
}
.lamp[data-state="connected"] {
  background: var(--lamp-live);
  box-shadow: 0 0 0 1px var(--edge-bright), 0 0 40px -2px var(--lamp-live);
}
.lamp[data-state="failed"] { background: var(--lamp-dead); }
.lamp[data-state="opted_out"] { background: var(--lamp-out); }

@keyframes pulse { 50% { opacity: .42; } }
@media (prefers-reduced-motion: reduce) {
  .lamp { animation: none !important; }
}

.line-state {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: .18em;
  text-transform: uppercase;
  margin: 0 0 4px;
}
.timer {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: .04em;
  color: var(--ink);
  margin: 0 0 4px;
}
.lead-name {
  font-size: 17px;
  font-weight: 600;
  margin: 18px 0 2px;
}
.lead-phone.is-number { font-family: var(--font-mono); }
.lead-phone {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink-dim);
  margin: 0;
}

/* ---- Keys (buttons shaped like equipment keys) ---- */
.key {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--panel-raised);
  border: 1px solid var(--edge-bright);
  border-bottom-width: 3px;
  border-radius: var(--radius);
  padding: 13px 22px;
  cursor: pointer;
  transition: transform .06s ease, background .15s ease;
  width: 100%;
}
.key:hover { background: #29323D; }
.key:active { transform: translateY(2px); border-bottom-width: 1px; }
.key:focus-visible { outline: 2px solid var(--lamp-ring); outline-offset: 2px; }
.key[disabled] { opacity: .4; cursor: not-allowed; }
.key-go   { background: #1D3D2E; border-color: #2E6B4E; color: #A9EFCB; }
.key-go:hover { background: #24503B; }
.key-stop { background: #3D2224; border-color: #7A3A3E; color: #F5B5B7; }
.key-stop:hover { background: #4E2A2D; }
.key-sm { font-size: 13px; padding: 8px 14px; width: auto; }

.key-row { display: flex; gap: 10px; margin-top: 20px; }

/* ---- Busy lamp field: the 500-lead queue strip ---- */
.blf {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 14px;
  background: var(--panel-sunk);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  max-height: 190px;
  overflow-y: auto;
}
.blf i {
  width: 9px;
  height: 9px;
  border-radius: 1px;
  background: var(--lamp-idle);
  opacity: .35;
}
.blf i[data-s="transferred"] { background: var(--lamp-live); opacity: 1; }
.blf i[data-s="more_info"]   { background: var(--lamp-ring); opacity: 1; }
.blf i[data-s="no_answer"]   { background: var(--ink-faint); opacity: .8; }
.blf i[data-s="failed"]      { background: var(--lamp-dead); opacity: .9; }
.blf i[data-s="opted_out"]   { background: var(--lamp-out); opacity: .9; }
.blf i[data-s="calling"]     { background: var(--lamp-ring); opacity: 1; animation: pulse 1s infinite; }

/* ---- Tallies ---- */
.tallies {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 1px;
  background: var(--edge);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.tally { background: var(--panel); padding: 12px 10px; }
.tally b {
  display: block;
  font-family: var(--font-mono);
  font-size: 23px;
  font-weight: 500;
}
.tally span {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ---- Log ---- */
.log { max-height: 340px; overflow-y: auto; }
.log-row {
  display: grid;
  grid-template-columns: 62px 1fr auto;
  gap: 12px;
  align-items: baseline;
  padding: 9px 2px;
  border-bottom: 1px solid var(--panel-raised);
  font-size: 14px;
}
.log-row time { font-family: var(--font-mono); font-size: 12px; color: var(--ink-faint); }
.log-row .num { font-family: var(--font-mono); }
.badge {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 2px;
  border: 1px solid var(--edge-bright);
  color: var(--ink-dim);
  white-space: nowrap;
}
.badge[data-s="transferred"] { color: var(--lamp-live); border-color: var(--lamp-live); }
.badge[data-s="more_info"]   { color: var(--lamp-ring); border-color: var(--lamp-ring); }
.badge[data-s="opted_out"]   { color: var(--lamp-out);  border-color: var(--lamp-out); }
.badge[data-s="failed"]      { color: var(--lamp-dead); border-color: var(--lamp-dead); }

/* ---- Forms ---- */
label { display: block; font-size: 13px; color: var(--ink-dim); font-weight: 500; }
input, select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 10px 12px;
  background: var(--panel-sunk);
  border: 1px solid var(--edge-bright);
  border-radius: var(--radius);
  color: var(--ink);
  font: 400 15px var(--font-body);
}
input[type="file"] { padding: 8px; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--lamp-ring);
  outline-offset: 1px;
  border-color: transparent;
}
hr { border: 0; border-top: 1px solid var(--edge); margin: 6px 0; }

.alert {
  background: #3D2224;
  border: 1px solid #7A3A3E;
  border-radius: var(--radius);
  padding: 11px 14px;
  color: #F5B5B7;
  font-size: 14px;
}
.notice {
  background: #1D3D2E;
  border: 1px solid #2E6B4E;
  border-radius: var(--radius);
  padding: 11px 14px;
  color: #A9EFCB;
  font-size: 14px;
}
.empty {
  padding: 34px 20px;
  text-align: center;
  color: var(--ink-faint);
  border: 1px dashed var(--edge-bright);
  border-radius: var(--radius);
}

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--edge);
}
td { padding: 10px; border-bottom: 1px solid var(--panel-raised); vertical-align: middle; }
td.num { font-family: var(--font-mono); }
.scroller { overflow-x: auto; }

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

/* ============================================================
   Phone layout — bottom tab bar, thumb-sized targets, notch safe
   ============================================================ */
.theme-toggle {
  background: none;
  border: 1px solid var(--edge-bright);
  border-radius: var(--radius);
  color: var(--ink-dim);
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: 6px 11px;
  min-height: 34px;
}
.theme-toggle:hover { color: var(--ink); background: var(--panel-raised); }

@media (max-width: 760px) {
  .topbar {
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }
  .topbar nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 40;
    background: var(--panel);
    border-top: 1px solid var(--edge);
    display: flex;
    gap: 0;
    margin: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .topbar nav a {
    flex: 1;
    text-align: center;
    padding: 13px 4px;
    font-size: 11px;
    letter-spacing: .06em;
    border-radius: 0;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .topbar nav a[aria-current="page"] {
    background: none;
    box-shadow: inset 0 2px 0 var(--lamp-ring);
  }
  .wrap { padding: 14px; padding-bottom: 88px; }
  .panel { padding: 18px 16px; }

  /* Thumb-sized controls */
  .key { min-height: 50px; font-size: 15px; }
  .key-sm { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .theme-toggle { min-height: 44px; padding: 0 14px; }
  input, select, textarea { min-height: 46px; font-size: 16px; } /* 16px stops iOS zooming on focus */
  .heard-row .key-sm { flex: 1 1 45%; }

  .lamp { width: 84px; height: 84px; }
  .timer { font-size: 27px; }
  .display { font-size: 25px; }
  .blf { max-height: 150px; }
  .blf i { width: 8px; height: 8px; }

  /* Tables scroll rather than squash */
  table { min-width: 560px; }
  .log-row { grid-template-columns: 52px 1fr auto; font-size: 13px; }
}

@media (max-width: 400px) {
  .tallies { grid-template-columns: repeat(auto-fit, minmax(60px, 1fr)); }
  .tally b { font-size: 20px; }
  .tally span { font-size: 10px; letter-spacing: .1em; }
}

/* Standalone (added to home screen) gets the notch padding too */
@media (display-mode: standalone) {
  body { padding-top: env(safe-area-inset-top); }
}
