/* ==============================================================
   Connection Technologies — Customer Portal
   Mobile-first stylesheet. Safe-area aware. WCAG-AA contrast.
   ============================================================== */

:root {
  --ct-navy:    #193E5E;
  --ct-navy-2:  #0e1726;
  --ct-blue:    #1863DC;
  --ct-blue-2:  #046bd2;
  --ct-orange:  #f3744d;
  --ct-text:    #15233a;
  --ct-muted:   #5a6b85;
  --ct-border:  #e2e8f0;
  --ct-border-2:#cbd5e1;
  --ct-bg:      #f5f8fc;
  --ct-card:    #ffffff;
  --ct-success: #16a34a;
  --ct-danger:  #dc2626;
  --ct-warn:    #d97706;

  --shadow-sm: 0 1px 2px rgba(14,23,38,0.05);
  --shadow-md: 0 4px 16px rgba(14,23,38,0.07);
  --shadow-lg: 0 12px 32px rgba(14,23,38,0.12);

  --radius:     10px;
  --radius-lg:  16px;
  --radius-xl:  22px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bot:    env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body.portal-body {
  font-family: var(--font-sans);
  color: var(--ct-text);
  background: var(--ct-bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  font-size: 16px;
  /* leave space for iPhone home indicator etc */
  padding-bottom: var(--safe-bot);
}

a { color: var(--ct-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 max(20px, calc(20px + var(--safe-left)));
  padding-right:  max(20px, calc(20px + var(--safe-right)));
}

.muted { color: var(--ct-muted); }
.small { font-size: 13px; }

/* ============================================================
   Header / nav
   ============================================================ */

.portal-header {
  background: var(--ct-card);
  border-bottom: 1px solid var(--ct-border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: var(--safe-top);
}
.portal-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
}
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand__logo {
  height: 36px; width: auto;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,0.04));
}

.portal-nav {
  display: flex;
  align-items: center;
  gap: 24px;
  font-weight: 500;
}
.portal-nav a {
  color: var(--ct-navy);
  padding: 8px 0;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.portal-nav a:hover { text-decoration: none; color: var(--ct-blue); }
.portal-nav a.is-active {
  color: var(--ct-blue);
  border-bottom-color: var(--ct-blue);
}
.portal-nav__user {
  color: var(--ct-muted);
  font-weight: 500;
  font-size: 14px;
  padding-left: 18px;
  border-left: 1px solid var(--ct-border);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.portal-nav__logout { margin: 0; }

.link-btn {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--ct-blue); font: inherit;
}
.link-btn:hover { text-decoration: underline; }

/* Hamburger */
.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--ct-border);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  width: 40px; height: 40px;
}
.nav-toggle span,
.nav-toggle span::before,
.nav-toggle span::after {
  content: ''; display: block;
  width: 22px; height: 2px;
  background: var(--ct-navy); border-radius: 2px;
  transition: transform .2s, opacity .2s, top .2s;
  position: relative;
}
.nav-toggle span::before { position: absolute; top: -7px; }
.nav-toggle span::after  { position: absolute; top:  7px; }
.nav-toggle[aria-expanded="true"] span                { background: transparent; }
.nav-toggle[aria-expanded="true"] span::before        { top: 0; transform: rotate(45deg);  background: var(--ct-navy); }
.nav-toggle[aria-expanded="true"] span::after         { top: 0; transform: rotate(-45deg); background: var(--ct-navy); }

.impersonation-banner {
  background: var(--ct-orange);
  color: #fff;
  text-align: center;
  padding: 10px 16px;
  font-weight: 500;
  padding-top: calc(10px + var(--safe-top));
}
.impersonation-banner .link-btn {
  color: #fff;
  text-decoration: underline;
  margin-left: 8px;
}

/* ============================================================
   Main / pages
   ============================================================ */

.portal-main { flex: 1; padding: 28px 0 64px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-title {
  font-size: clamp(22px, 2.5vw, 30px);
  line-height: 1.2;
  margin: 0 0 4px;
  color: var(--ct-navy);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.page-sub { margin: 0; color: var(--ct-muted); font-size: 15px; }

.section-title {
  font-size: 18px;
  color: var(--ct-navy);
  margin: 32px 0 14px;
  font-weight: 700;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
  color: var(--ct-muted);
  font-weight: 500;
  font-size: 14px;
}
.back-link:hover { color: var(--ct-blue); text-decoration: none; }

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
  text-decoration: none;
  min-height: 44px; /* iOS touch target */
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--ct-blue); color: #fff; border-color: var(--ct-blue);
  box-shadow: 0 1px 0 rgba(8,30,80,0.08);
}
.btn--primary:hover {
  background: var(--ct-blue-2); border-color: var(--ct-blue-2);
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(24,99,220,0.25);
}
.btn--secondary {
  background: #fff; color: var(--ct-navy); border-color: var(--ct-border-2);
}
.btn--secondary:hover {
  border-color: var(--ct-blue); color: var(--ct-blue); text-decoration: none;
}
.btn--block { width: 100%; }
.btn--small { padding: 8px 14px; font-size: 14px; min-height: 38px; }

/* ============================================================
   Cards / grids
   ============================================================ */

.card {
  background: var(--ct-card);
  border: 1px solid var(--ct-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 18px;
  color: var(--ct-navy);
}

.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.card-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.number-card {
  background: var(--ct-card);
  border: 1px solid var(--ct-border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, transform .15s, border-color .15s;
  position: relative;
  overflow: hidden;
}
.number-card::after {
  content: ''; position: absolute;
  top: 0; right: 0; width: 80px; height: 80px;
  background: radial-gradient(closest-side, rgba(24,99,220,0.10), transparent 70%);
  pointer-events: none;
}
.number-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--ct-blue);
  text-decoration: none;
  transform: translateY(-1px);
}
.number-card--inactive {
  opacity: 0.65;
  background: repeating-linear-gradient(
    -45deg,
    var(--ct-card),
    var(--ct-card) 12px,
    rgba(0,0,0,0.025) 12px,
    rgba(0,0,0,0.025) 24px
  );
}
.number-card--inactive:hover { opacity: 0.85; }
.number-card__phone {
  font-size: 22px;
  font-weight: 700;
  color: var(--ct-navy);
  letter-spacing: -0.01em;
}
.number-card__nick { color: var(--ct-muted); font-size: 14px; }
.number-card__forward { font-size: 14px; }
.number-card__forward .muted { display: block; font-size: 12px; }
.number-card__status { margin-top: 4px; }

/* ============================================================
   Empty / orders / tables
   ============================================================ */

.empty-state {
  text-align: center;
  padding: 36px 20px 48px;
  background: var(--ct-card);
  border: 1px solid var(--ct-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.empty-state h2 { margin: 8px 0 6px; color: var(--ct-navy); }
.empty-state p  { margin: 4px 0; color: var(--ct-muted); }
.empty-state__art {
  width: min(420px, 80%);
  margin: 0 auto 8px;
  display: block;
}
.empty-state__cta { margin-top: 18px; }

.orders-section { margin-top: 36px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--ct-card);
  border: 1px solid var(--ct-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.data-table th, .data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--ct-border);
  vertical-align: middle;
}
.data-table th {
  background: #f8fafc;
  color: var(--ct-navy);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table code {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--ct-bg);
  padding: 2px 6px;
  border-radius: 4px;
}

.data-table--calls td.num,
.data-table--calls th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.data-table--calls td { vertical-align: top; }

/* ============================================================
   Forms
   ============================================================ */

.form { display: flex; flex-direction: column; gap: 16px; }
.form__field { display: flex; flex-direction: column; gap: 6px; }
.form__field span { font-weight: 600; color: var(--ct-navy); font-size: 14px; }
.form__field input,
.form__field select,
.form__field textarea {
  font: inherit;
  font-size: 16px; /* prevent iOS zoom on focus */
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--ct-border-2);
  background: #fff;
  color: var(--ct-text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  min-height: 44px;
}
.form__field input:focus,
.form__field select:focus,
.form__field textarea:focus {
  border-color: var(--ct-blue);
  box-shadow: 0 0 0 3px rgba(24,99,220,0.18);
}
.form__hint { color: var(--ct-muted); font-size: 13px; }

/* ============================================================
   Auth shell — split screen on desktop, hero-on-top on mobile
   ============================================================ */

.auth-shell {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: calc(100dvh - var(--safe-top));
}
.auth-shell__hero {
  background:
    radial-gradient(1200px 600px at 70% 10%, rgba(24,99,220,0.18), transparent 60%),
    linear-gradient(160deg, #f5f8fc 0%, #eaf1fb 60%, #d6e4f8 100%);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}
.auth-shell__hero img {
  max-width: 560px;
  width: 100%;
  height: auto;
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 50px rgba(14,23,38,0.10);
}
.auth-shell__hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(2px 2px at 20% 30%, rgba(24,99,220,0.20) 50%, transparent 51%) 0 0/40px 40px,
    radial-gradient(2px 2px at 70% 60%, rgba(24,99,220,0.12) 50%, transparent 51%) 0 0/52px 52px;
  pointer-events: none;
  opacity: 0.7;
}
.auth-shell__form {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px max(24px, calc(24px + var(--safe-right))) 40px max(24px, calc(24px + var(--safe-left)));
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: transparent; /* form panel doesn't need its own card on the split layout */
  padding: 0;
  border: 0;
  box-shadow: none;
}
/* On standalone pages (forgot password etc) use the bordered look */
.auth-card--standalone {
  background: var(--ct-card);
  padding: 32px 28px;
  border: 1px solid var(--ct-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.auth-card--wide { max-width: 560px; }
.auth-card__title {
  margin: 0 0 6px;
  font-size: clamp(22px, 2.6vw, 28px);
  color: var(--ct-navy);
  letter-spacing: -0.01em;
  font-weight: 700;
}
.auth-card__sub  { margin: 0 0 22px; color: var(--ct-muted); }
.auth-card__links { margin-top: 18px; text-align: center; font-size: 14px; }
.auth-card__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}
.auth-card__brand img {
  height: 32px; width: auto;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,0.04));
}

/* ============================================================
   Alerts / badges / pills
   ============================================================ */

.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert--danger  { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert--success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert--warn    { background: #fffbeb; color: #78350f; border-color: #fde68a; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}
.badge--ok     { background: #ecfdf5; color: #047857; }
.badge--warn   { background: #fffbeb; color: #b45309; }
.badge--danger { background: #fef2f2; color: #b91c1c; }

.call-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.02em;
}
.call-pill--answered { background: #dcfce7; color: #14532d; }
.call-pill--missed   { background: #fef3c7; color: #78350f; }
.call-pill--busy     { background: #fee2e2; color: #7f1d1d; }
.call-pill--failed   { background: #e2e8f0; color: #334155; }

/* ============================================================
   KV list / addons
   ============================================================ */

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 8px 0 0;
}
.kv dt { color: var(--ct-muted); font-weight: 500; }
.kv dd { margin: 0; font-weight: 500; }
.addon-list { margin: 0; padding-left: 18px; }

/* ============================================================
   Search / inline-form / section-head / call summary
   ============================================================ */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.section-head .link {
  color: var(--ct-blue);
  font-weight: 600;
  text-decoration: none;
  font-size: 14px;
}
.section-head .link:hover { text-decoration: underline; }

.search-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.search-form input[type="search"] {
  font: inherit;
  font-size: 16px;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--ct-border-2);
  background: #fff;
  flex: 1 1 240px;
  min-width: 0;
  outline: none;
  min-height: 44px;
}
.search-form input[type="search"]:focus {
  border-color: var(--ct-blue);
  box-shadow: 0 0 0 3px rgba(24,99,220,0.18);
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ct-muted);
}
.inline-form select {
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--ct-border-2);
  background: #fff;
  color: var(--ct-text);
  min-height: 38px;
}

.call-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin: 14px 0 22px;
}
.call-stat {
  background: var(--ct-card);
  border: 1px solid var(--ct-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.call-stat__num {
  font-size: 26px;
  font-weight: 700;
  color: var(--ct-navy);
  font-variant-numeric: tabular-nums;
}
.call-stat__lbl {
  font-size: 12px;
  color: var(--ct-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

/* ============================================================
   Footer
   ============================================================ */

.portal-footer {
  background: var(--ct-card);
  border-top: 1px solid var(--ct-border);
  padding: 18px 0 calc(18px + var(--safe-bot));
  font-size: 14px;
  color: var(--ct-muted);
}
.portal-footer__row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
}

/* ============================================================
   ───────────────  Responsive / mobile  ────────────────────────
   Most small-screen tweaks live below. The base styles above are
   already mobile-safe; we layer on adjustments as breakpoints
   widen.
   ============================================================ */

/* ↓↓↓ Tablet & mobile (≤860px): switch to single-column layout,
       hamburger nav, and turn the auth shell into a stacked hero. */
@media (max-width: 860px) {

  /* Auth: stack hero on top */
  .auth-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }
  .auth-shell__hero {
    min-height: 200px;
    padding: 20px;
    aspect-ratio: 16/9;
    max-height: 36vh;
  }
  .auth-shell__hero img {
    max-width: 360px;
    border-radius: var(--radius-lg);
  }
  .auth-shell__form { padding: 24px 20px 36px; }

  /* Detail grid → single column */
  .detail-grid { grid-template-columns: 1fr; gap: 16px; }

  /* Header: hide inline nav, show hamburger */
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }

  .portal-nav {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(86vw, 320px);
    background: var(--ct-card);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 24px 20px calc(24px + var(--safe-bot));
    padding-top: calc(72px + var(--safe-top));
    box-shadow: -12px 0 32px rgba(14,23,38,0.18);
    transform: translateX(100%);
    transition: transform .25s ease;
    z-index: 25;
  }
  .portal-nav.is-open { transform: translateX(0); }

  .portal-nav a {
    padding: 14px 6px;
    border-bottom: 1px solid var(--ct-border);
    font-size: 16px;
  }
  .portal-nav a.is-active {
    color: var(--ct-blue);
    border-bottom-color: var(--ct-border);
    background: rgba(24,99,220,0.05);
    border-radius: 8px 8px 0 0;
  }
  .portal-nav__user {
    border-left: 0;
    padding-left: 6px;
    padding-top: 16px;
    border-top: 1px solid var(--ct-border);
    margin-top: 8px;
    max-width: none;
    font-size: 13px;
  }
  .portal-nav__logout {
    margin-top: 12px;
  }
  .portal-nav__logout button {
    background: var(--ct-bg);
    border-radius: 10px;
    padding: 12px 14px;
    width: 100%;
    text-align: left;
  }

  /* Backdrop when drawer is open */
  body.nav-open::before {
    content: '';
    position: fixed; inset: 0;
    background: rgba(14,23,38,0.4);
    z-index: 24;
  }
  body.nav-open { overflow: hidden; }
}

/* ↓↓↓ Phone (≤620px): table → card stack, generous spacing */
@media (max-width: 620px) {
  .container { padding-left: max(16px, calc(16px + var(--safe-left))); padding-right: max(16px, calc(16px + var(--safe-right))); }
  .portal-main { padding: 18px 0 48px; }
  .card { padding: 18px; border-radius: var(--radius-lg); }

  .page-header { gap: 12px; margin-bottom: 18px; }
  .page-header > .btn { width: 100%; }

  .card-grid { grid-template-columns: 1fr; gap: 12px; }

  /* ── Card-stack tables (responsive transformation) ── */
  .data-table,
  .data-table thead,
  .data-table tbody,
  .data-table tr,
  .data-table th,
  .data-table td {
    display: block;
    width: 100%;
  }
  .data-table {
    border: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
  }
  .data-table thead { display: none; }
  .data-table tr {
    background: var(--ct-card);
    border: 1px solid var(--ct-border);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
    padding: 8px 6px;
    box-shadow: var(--shadow-sm);
  }
  .data-table td {
    padding: 8px 12px;
    border-bottom: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
    min-height: 36px;
  }
  .data-table td::before {
    content: attr(data-label);
    color: var(--ct-muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex: 0 0 auto;
    text-align: left;
  }
  .data-table td:empty,
  .data-table td:has(> :empty:only-child) { display: none; }

  /* Call summary stats: 2-up on phone */
  .call-summary { grid-template-columns: 1fr 1fr; }
  .call-stat { padding: 14px; }
  .call-stat__num { font-size: 22px; }

  /* Empty state image smaller */
  .empty-state__art { width: min(280px, 78%); }

  /* Footer rows stack */
  .portal-footer__row { gap: 6px; }
}

/* Small phones (≤380px): tighter still */
@media (max-width: 380px) {
  .call-summary { grid-template-columns: 1fr; }
  .page-title { font-size: 22px; }
  .number-card__phone { font-size: 20px; }
}

/* ↑↑↑ Desktop only: a couple of polish tweaks above 1080px */
@media (min-width: 1080px) {
  .portal-main { padding-top: 36px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
