/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg:        #0f1117;
  --color-surface:   #1a1d27;
  --color-surface2:  #22263a;
  --color-border:    #2e3350;
  --color-primary:   #6366f1;
  --color-primary-h: #818cf8;
  --color-text:      #e2e8f0;
  --color-muted:     #64748b;
  --color-success:   #22c55e;
  --color-warn:      #f59e0b;
  --color-danger:    #ef4444;
  --font:            'Inter', system-ui, sans-serif;
  --radius:          10px;
  --radius-sm:       6px;
  --shadow:          0 2px 16px rgba(0,0,0,.4);
}

html { font-size: 15px; overflow-x: hidden; }
body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

a { color: var(--color-primary-h); text-decoration: none; }
a:hover { text-decoration: underline; }

code { font-family: 'Courier New', monospace; background: var(--color-surface2); padding: 2px 6px; border-radius: 4px; font-size: .85em; }

/* ── Nav ─────────────────────────────────────────────────── */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 58px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand { display: flex; align-items: center; gap: .5rem; }
.nav-logo  { font-size: 1.3rem; }
.nav-title { font-weight: 700; font-size: 1.05rem; color: var(--color-text); }

.nav-links {
  display: flex;
  gap: .25rem;
  list-style: none;
}

.nav-link {
  display: block;
  padding: .4rem .9rem;
  border-radius: var(--radius-sm);
  color: var(--color-muted);
  font-size: .9rem;
  font-weight: 500;
  transition: color .15s, background .15s;
}
.nav-link:hover { color: var(--color-text); background: var(--color-surface2); text-decoration: none; }
.nav-link.active { color: var(--color-primary-h); background: rgba(99,102,241,.12); }

/* ── Main layout ─────────────────────────────────────────── */
.main { flex: 1; max-width: 1100px; width: 100%; margin: 0 auto; padding: 2rem 1.5rem; }

/* ── Footer ─────────────────────────────────────────────── */
.footer { text-align: center; padding: 1.25rem; color: var(--color-muted); font-size: .8rem; border-top: 1px solid var(--color-border); }

/* ── Page header ─────────────────────────────────────────── */
.page-header   { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.page-title    { font-size: 1.6rem; font-weight: 700; }
.page-line-num { font-size: .85rem; color: var(--color-muted); letter-spacing: .03em; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }

.stat-card  { padding: 1.1rem 1.25rem; }
.stat-label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--color-muted); margin-bottom: .35rem; }
.stat-value { font-size: 1.1rem; font-weight: 600; color: var(--color-text); }

/* ── Badges ─────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: .25em .65em; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-active { background: rgba(34,197,94,.15); color: var(--color-success); }
.badge-warn   { background: rgba(245,158,11,.15); color: var(--color-warn); }
.badge-dir    { background: var(--color-surface2); color: var(--color-muted); }

.badge-status--completed,
.badge-status--received   { background: rgba(34,197,94,.15); color: var(--color-success); }
.badge-status--inprogress { background: rgba(99,102,241,.15); color: var(--color-primary-h); }
.badge-status--busy,
.badge-status--failed,
.badge-status--noanswer   { background: rgba(239,68,68,.15); color: var(--color-danger); }
.badge-status--ringing,
.badge-status--queued     { background: rgba(245,158,11,.15); color: var(--color-warn); }

/* ── Alerts ─────────────────────────────────────────────── */
.alert { padding: .9rem 1.25rem; border-radius: var(--radius-sm); margin-bottom: 1.5rem; font-size: .92rem; }
.alert-warn { background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.3); color: var(--color-warn); }

/* ── Section ─────────────────────────────────────────────── */
.section { margin-bottom: 2.5rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.section-title  { font-size: 1.15rem; font-weight: 600; }
.section-count  { color: var(--color-muted); font-size: .85rem; }

/* ── Tables ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--color-border); }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table thead tr { background: var(--color-surface2); }
.table th { padding: .7rem 1rem; text-align: left; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--color-muted); white-space: nowrap; }
.table td { padding: .65rem 1rem; border-top: 1px solid var(--color-border); vertical-align: middle; }
.table tbody tr:hover { background: rgba(255,255,255,.025); }

.mono  { font-family: 'Courier New', monospace; font-size: .85em; color: var(--color-text); }
.small { font-size: .8em; }
.ts    { color: var(--color-muted); font-size: .83em; white-space: nowrap; }
.muted { color: var(--color-muted); }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state { padding: 2rem 1rem; text-align: center; color: var(--color-muted); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); }
.empty-state.large { padding: 4rem 2rem; }
.empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-h); }
.btn-outline { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: var(--color-surface2); border-color: var(--color-primary); }
.btn-sm { padding: .3rem .75rem; font-size: .8rem; }

/* ── Collapsible sections ────────────────────────────────── */
.collapsible > summary {
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.collapsible > summary::-webkit-details-marker { display: none; }

.form-section-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: .6rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1.25rem;
}
.form-section-summary .form-section-title { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }

.collapsible-chevron {
  color: var(--color-muted);
  font-size: .8rem;
  transition: transform .2s ease;
  flex-shrink: 0;
}
details[open] > .form-section-summary .collapsible-chevron { transform: rotate(180deg); }

/* ── Forms ───────────────────────────────────────────────── */
.settings-form  { display: flex; flex-direction: column; gap: 1.5rem; }
.form-section-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 1.25rem; padding-bottom: .6rem; border-bottom: 1px solid var(--color-border); }

.form-group { margin-bottom: 1.1rem; }
.form-group--check { display: flex; align-items: center; }
.form-label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .35rem; color: var(--color-text); }
.form-hint  { display: block; font-size: .78rem; color: var(--color-muted); margin-top: .3rem; }
.mb-4 { margin-bottom: 1rem; }

.form-input {
  width: 100%;
  background: var(--color-surface2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .55rem .85rem;
  color: var(--color-text);
  font-family: var(--font);
  font-size: .9rem;
  transition: border-color .15s;
  outline: none;
}
.form-input:focus  { border-color: var(--color-primary); }
.form-input--sm    { padding: .35rem .6rem; font-size: .85rem; width: auto; }
.form-textarea     { resize: vertical; min-height: 80px; }
.form-select       { appearance: none; cursor: pointer; }

.form-check-label { display: flex; align-items: center; gap: .6rem; cursor: pointer; font-size: .9rem; }
.form-check-label input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--color-primary); cursor: pointer; }

.form-actions { display: flex; gap: .75rem; padding-top: .5rem; }

/* ── Business hours grid ─────────────────────────────────── */
.hours-grid   { display: flex; flex-direction: column; gap: .6rem; }
.hours-header { display: grid; grid-template-columns: 120px 60px 1fr 1fr; gap: .75rem; padding: 0 .25rem; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--color-muted); }
.hours-row    { display: grid; grid-template-columns: 120px 60px 1fr 1fr; gap: .75rem; align-items: center; padding: .45rem .25rem; border-radius: var(--radius-sm); }
.hours-row:hover { background: var(--color-surface2); }
.hours-day    { font-size: .88rem; font-weight: 500; }
.hours-toggle { width: 16px; height: 16px; accent-color: var(--color-primary); cursor: pointer; }
.hours-time   { width: 100%; }

/* ── Audio player ────────────────────────────────────────── */
.audio-player   { height: 32px; max-width: 220px; vertical-align: middle; accent-color: var(--color-primary); }
.vm-audio-wrap  { display: flex; align-items: center; gap: .5rem; }

/* ── Transcript ──────────────────────────────────────────── */
.transcript { font-size: .85rem; font-style: italic; color: var(--color-muted); max-width: 300px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-body   { max-width: 340px; font-size: .88rem; word-break: break-word; white-space: normal; }

/* ── Delete button ───────────────────────────────────────── */
.btn-del {
  background: none;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: .2rem .4rem;
  border-radius: var(--radius-sm);
  transition: color .15s, background .15s;
  line-height: 1;
}
.btn-del:hover { color: var(--color-danger); background: rgba(239,68,68,.1); }

/* ── IVR Options ─────────────────────────────────────────── */
.ivr-options        { display: flex; flex-direction: column; gap: .75rem; margin-top: .75rem; padding: .75rem; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); }
.ivr-option         { display: flex; align-items: flex-start; gap: .75rem; padding: .5rem 0; }
.ivr-option--fixed  { opacity: .7; }
.ivr-option-body    { display: flex; flex-direction: column; gap: .4rem; flex: 1; }
.ivr-ext-wrap       { display: flex; flex-direction: column; gap: .25rem; margin-top: .25rem; }

/* ── Bottom nav (mobile tab bar) ─────────────────────────── */
.nav-bottom {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 62px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  z-index: 200;
}
.nav-bottom-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--color-muted);
  font-size: .62rem;
  font-weight: 500;
  text-decoration: none;
  padding: 6px 0;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-bottom-link:hover { text-decoration: none; color: var(--color-text); }
.nav-bottom-link.active { color: var(--color-primary-h); }
.nav-bottom-icon { font-size: 1.25rem; line-height: 1; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 700px) {
  /* Activate bottom tab bar */
  .nav-links  { display: none; }
  .nav-bottom { display: flex; }
  .nav        { padding: 0 1rem; height: 50px; }
  .nav-title  { font-size: .95rem; }

  /* Content area: pad bottom so it clears the tab bar */
  .main { padding: 1rem .9rem 80px; }

  /* Page headings */
  .page-title   { font-size: 1.2rem; }
  .section-title { font-size: .95rem; }
  .section      { margin-bottom: 1.5rem; }

  /* Stat cards — 2×2 grid */
  .cards-row  { grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1.25rem; }
  .stat-card  { padding: .8rem .9rem; }
  .stat-label { font-size: .68rem; }
  .stat-value { font-size: .95rem; }

  /* Tables — keep horizontal scroll, tighten cells */
  .table th      { padding: .5rem .5rem; font-size: .65rem; }
  .table td      { padding: .45rem .5rem; font-size: .8rem; }
  .ts            { font-size: .72rem; }
  .msg-body      { max-width: 140px; }
  .transcript    { max-width: 120px; }
  .col-num       { display: none; }
  /* Compact audio in table */
  .audio-player  { max-width: 110px; width: 110px; height: 28px; }
  .vm-audio-wrap { flex-direction: row; flex-wrap: wrap; gap: .3rem; }

  /* Cards / form */
  .card       { padding: 1rem; }
  .form-input { font-size: .95rem; padding: .65rem .85rem; min-height: 44px; }
  .btn        { min-height: 44px; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }

  /* Business hours grid */
  .hours-header,
  .hours-row { grid-template-columns: 76px 38px 1fr 1fr; gap: .4rem; }
  .hours-day  { font-size: .75rem; }
  .hours-time { font-size: .78rem; }

  /* Audio player */
  .audio-player   { max-width: 100%; width: 100%; }
  .vm-audio-wrap  { flex-direction: column; align-items: flex-start; gap: .35rem; }

  /* IVR section */
  .ivr-options  { padding: .6rem; gap: .5rem; }
  .ivr-option   { gap: .5rem; }
}
