:root {
  --bg: #f2f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #dbe3ec;
  --accent: #0f766e;
  --danger: #be123c;
  --shadow: 0 20px 45px rgba(15, 23, 42, 0.08);
}
html[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131b2e;
  --surface-2: #0e1628;
  --ink: #e2e8f0;
  --muted: #9fb1ca;
  --line: #24314c;
  --accent: #2dd4bf;
  --danger: #fb7185;
  --shadow: 0 24px 45px rgba(2, 6, 23, 0.5);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Vazirmatn FD NL", Tahoma, sans-serif; background: radial-gradient(circle at 80% -10%, rgba(45,212,191,0.16), transparent 30%), radial-gradient(circle at 10% 120%, rgba(59,130,246,0.16), transparent 30%), var(--bg); color: var(--ink); }
a { color: inherit; }
.app-body { min-height: 100vh; }
.layout { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; transition: grid-template-columns .2s ease; }
.layout.sidebar-collapsed { grid-template-columns: 92px 1fr; }
.sidebar { background: color-mix(in srgb, var(--surface) 90%, transparent); border-left: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; backdrop-filter: blur(7px); }
.brand-wrap { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: inline-flex; gap: 10px; text-decoration: none; align-items: center; }
.brand-mark { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-weight: 800; color: #fff; background: linear-gradient(135deg, var(--accent), #0284c7); box-shadow: var(--shadow); }
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 12px; }
.icon-button { border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); color: var(--ink); width: 36px; height: 36px; cursor: pointer; }
.side-links { display: grid; gap: 8px; }
.side-link { display: inline-flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 12px; text-decoration: none; color: var(--muted); border: 1px solid transparent; background: transparent; font: inherit; cursor: pointer; width: 100%; text-align: right; }
.side-link:hover { color: var(--ink); border-color: var(--line); background: var(--surface-2); }
.side-link.active { color: #fff; background: linear-gradient(135deg, var(--accent), #0ea5e9); border-color: transparent; }
.side-footer { margin-top: auto; display: grid; gap: 8px; }
.content-wrap { padding: 24px; }
.content-shell { max-width: 1280px; margin: 0 auto; }
.layout.sidebar-collapsed .side-link span,
.layout.sidebar-collapsed .brand span,
.layout.sidebar-collapsed .side-action span { display: none; }
.layout.sidebar-collapsed .side-link,
.layout.sidebar-collapsed .side-action { justify-content: center; }
.phone-only-wrap { min-height: calc(100vh - 48px); display: grid; place-items: center; }
.phone-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 30px; padding: 18px; box-shadow: var(--shadow); }
.phone-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.phone-head h1 { margin: 0; font-size: 19px; }
.phone-stage { padding: 12px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface-2); }
.stack { display: grid; gap: 12px; }
label { display: grid; gap: 7px; font-size: 14px; }
input, select, textarea { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); }
.phone-field input { direction: ltr; text-align: left; font-size: 24px; border-radius: 18px; letter-spacing: .04em; }
.call-status, .badge { border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; font-size: 13px; }
.badge.status[data-tone="success"], .call-status[data-tone="success"] { background: color-mix(in srgb, #22c55e 22%, var(--surface)); }
.badge.status[data-tone="warning"], .call-status[data-tone="warning"] { background: color-mix(in srgb, #f59e0b 22%, var(--surface)); }
.badge.status[data-tone="danger"], .call-status[data-tone="danger"] { background: color-mix(in srgb, #ef4444 24%, var(--surface)); }
.dialer { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; direction: ltr; }
.dial-key { min-height: 68px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); display: grid; place-items: center; cursor: pointer; }
.dial-key strong { font-size: 24px; }
.dial-key span { font-size: 10px; color: var(--muted); }
.phone-actions { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.small { padding: 8px 10px; font-size: 13px; border-radius: 10px; }
.button.full { width: 100%; }
.button.danger-soft, .danger-soft { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.button.ghost { background: transparent; }
.icons-only .button { min-height: 52px; font-size: 22px; }
.icons-only .call-button { grid-column: 1 / -1; font-size: 28px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); }
.muted { color: var(--muted); }
.ltr { direction: ltr; }
.flash { margin-bottom: 12px; padding: 11px 13px; border-radius: 12px; }
.flash.success { background: color-mix(in srgb, #22c55e 24%, var(--surface)); }
.flash.error { background: color-mix(in srgb, #ef4444 24%, var(--surface)); }
.card, .hero { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.narrow { max-width: 640px; margin: 0 auto; }
.login-page { display: grid; place-items: center; padding: 20px; }
.login-wrap { width: min(420px, 100%); }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 22px; box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand h1 { margin: 0; font-size: 21px; }
.table-shell { overflow-x: auto; }
table { width: 100%; min-width: 850px; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 10; border-left: none; border-bottom: 1px solid var(--line); }
  .layout.sidebar-collapsed .side-link span, .layout.sidebar-collapsed .brand span, .layout.sidebar-collapsed .side-action span { display: inline; }
  .layout.sidebar-collapsed .side-link, .layout.sidebar-collapsed .side-action { justify-content: flex-start; }
  .phone-only-wrap { min-height: auto; }
}

/* UX refresh patch */
.layout { height: 100vh; overflow: hidden; }
.sidebar { height: 100vh; overflow-y: auto; }
.content-wrap { height: 100vh; overflow-y: auto; }
.phone-actions { grid-template-columns: repeat(3, minmax(0,1fr)); direction: rtl; }
.phone-actions .call-button { grid-column: 1 / -1; }
.hidden-audio { display: none; }
.bulk-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bulk-tools select { min-width: 180px; }
.pager { display: flex; justify-content: center; gap: 12px; align-items: center; margin-top: 14px; }
.report-head { align-items: center; }

.settings-card .setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: var(--surface-2);
}
.switch { position: relative; display: inline-block; width: 52px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #94a3b8;
  border-radius: 999px;
  transition: .2s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 24px;
  height: 24px;
  right: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: .2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(-22px); }

@media (max-width: 980px) {
  .layout { height: auto; overflow: visible; }
  .sidebar { height: auto; overflow: visible; }
  .content-wrap { height: auto; overflow: visible; padding: 14px; }
  .card-head, .report-head { flex-direction: column; align-items: stretch; }
  .bulk-tools { width: 100%; }
  .bulk-tools select, .bulk-tools button { width: 100%; }
  .phone-card { width: 100%; max-width: 430px; margin: 0 auto; }
  .phone-field input { font-size: 20px; }
}

@media (max-width: 640px) {
  .table-shell table { min-width: 720px; }
  .phone-actions { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .icons-only .button { font-size: 20px; min-height: 48px; }
}

/* Mobile nav + reports polish */
.button { font-family: inherit; }
.audio-toggle span { font-family: inherit; }

.bulk-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: var(--surface-2);
  margin-bottom: 12px;
}
.bulk-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}
.bulk-submit { min-width: 140px; }
.reports-card { overflow: hidden; }
.report-table-shell {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.report-table { min-width: 860px; }

@media (max-width: 980px) {
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 40;
    padding: 8px 10px;
  }
  .brand { display: none; }
  .brand-wrap { justify-content: flex-start; }
  #sidebar-toggle { display: none; }
  .sidebar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .side-links,
  .side-footer {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scrollbar-width: none;
  }
  .side-links::-webkit-scrollbar,
  .side-footer::-webkit-scrollbar { display: none; }
  .side-link,
  .side-action {
    min-width: 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 12px;
    justify-content: center;
    flex: 0 0 44px;
  }
  .side-link span,
  .side-action span { display: none !important; }
  .side-footer { margin-top: 0; }

  .bulk-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .bulk-submit { width: 100%; }
  .report-table { min-width: 760px; }
  .audio-upload-grid { grid-template-columns: 1fr; }
}


/* Mobile hotfix v2 */
html, body { max-width: 100%; overflow-x: clip; }
.layout, .content-shell, .reports-card, .report-table-shell { max-width: 100%; }

@media (max-width: 980px) {
  .sidebar {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    overflow: hidden;
  }
  .side-links,
  .side-footer {
    display: flex;
    align-items: center;
    flex-wrap: nowrap !important;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 6px;
    width: 50%;
    min-width: 0;
    justify-content: flex-start;
  }
  .side-footer { justify-content: flex-end; }
  .side-link,
  .side-action {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    min-width: 42px;
  }

  .reports-card { overflow: hidden; }
  .report-table-shell {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  .report-table {
    min-width: 920px;
    width: max-content;
  }

  .bulk-panel {
    overflow: hidden;
    width: 100%;
  }
}

.muted-state {
  background: color-mix(in srgb, #f59e0b 28%, var(--surface)) !important;
  border-color: color-mix(in srgb, #f59e0b 45%, var(--line)) !important;
  color: #b45309 !important;
  box-shadow: 0 0 0 2px color-mix(in srgb, #f59e0b 18%, transparent) inset;
}

.bulk-grid select {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 36px 10px 12px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%),
    linear-gradient(180deg, var(--surface), var(--surface-2));
  background-position:
    calc(12px) calc(50% - 3px),
    calc(18px) calc(50% - 3px),
    0 0;
  background-size: 6px 6px, 6px 6px, 100% 100%;
  background-repeat: no-repeat;
}
.bulk-grid label {
  font-weight: 700;
  color: var(--muted);
}
.audio-toggle {
  font-family: inherit !important;
  font-size: 13px;
}

.ivr-route-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ivr-route-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13px;
}
.ivr-details {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: var(--surface-2);
}
.ivr-details summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.ivr-details summary::-webkit-details-marker { display: none; }
.ivr-details-body { margin-top: 12px; }
.audio-upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.audio-upload-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: var(--surface);
}
.audio-upload-card audio {
  width: 100%;
}

/* mobile reports redesign + header equal height */
.mobile-brand { display: none; }
@media (max-width: 980px) {
  .sidebar {
    min-height: 62px !important;
    height: 62px !important;
    padding: 8px 10px !important;
    display: grid !important;
    grid-template-columns: auto 1fr 1fr !important;
    align-items: center !important;
    gap: 8px !important;
  }
  .mobile-brand {
    display: inline-flex;
    min-width: 0;
  }
  .mobile-brand strong { font-size: 13px; }
  .brand-wrap > .brand:not(.mobile-brand) { display: none !important; }
  .brand-wrap { display: contents !important; }
  .side-links, .side-footer {
    width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
  }
  .content-wrap {
    height: calc(100vh - 62px) !important;
  }

  .report-table-shell { display: none !important; }
  .report-cards { display: grid; gap: 10px; margin-top: 10px; }
  .report-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px;
    background: var(--surface);
    display: grid;
    gap: 8px;
  }
  .report-select {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
  }
  .report-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }
  .report-row span { color: var(--muted); font-size: 12px; }
  .report-row strong { font-size: 13px; overflow-wrap: anywhere; }
  .report-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
}
@media (min-width: 981px) {
  .report-cards { display: none; }
}
