/* ══════════════════════════════════════════════════════════════
   Sandstone Connect — Design System
   Sandstone Cloud brand: teal-blue on dark navy
   comms.sandstonecloud.com
   ══════════════════════════════════════════════════════════════ */

/* ── Fonts ────────────────────────────────────────────────── */
/* Loaded via Google Fonts in <head>:
   Fraunces (display), Inter (body/UI), JetBrains Mono (code) */

/* ── Design tokens ────────────────────────────────────────── */

:root {
  /* Surface — dark navy, high contrast */
  --bg-primary:     #0E1117;
  --bg-surface:     #161B26;
  --bg-raised:      #1E2535;
  --bg-input:       #0B0E13;

  /* Text — high contrast whites */
  --text-primary:   #F5F5F5;
  --text-secondary: #B0ACA6;
  --text-muted:     #7A7670;

  /* Border — visible structure */
  --border:         rgba(255, 255, 255, 0.12);
  --border-focus:   rgba(42, 191, 171, 0.5);

  /* Brand — teal to blue (from logo) */
  --teal:           #2ABFAB;
  --teal-hover:     #35D4BE;
  --teal-muted:     rgba(42, 191, 171, 0.12);
  --blue:           #5B7FD6;
  --blue-muted:     rgba(91, 127, 214, 0.12);

  /* Navy — primary buttons (Engram reference) */
  --navy:           #1A2332;
  --navy-hover:     #243044;

  /* Semantic — muted, not bright */
  --success:        #3A6B4A;
  --success-muted:  rgba(58, 107, 74, 0.15);
  --caution:        #8C6B2A;
  --caution-muted:  rgba(140, 107, 42, 0.15);
  --error:          #7A2E2E;
  --error-muted:    rgba(122, 46, 46, 0.15);

  /* Auth page — light mode, clean/corporate */
  --auth-bg:        #FFFFFF;
  --auth-surface:   #FFFFFF;
  --auth-border:    #E0E0E0;
  --auth-text:      #1A1A1A;
  --auth-muted:     #6B6B6B;

  /* Typography */
  --font-display:   'Fraunces', Georgia, serif;
  --font-body:      'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:      'JetBrains Mono', 'Fira Code', monospace;

  /* Type scale (4px grid) */
  --text-xs:    0.75rem;   /* 12px */
  --text-sm:    0.875rem;  /* 14px */
  --text-md:    1rem;      /* 16px */
  --text-lg:    1.125rem;  /* 18px */
  --text-xl:    1.375rem;  /* 22px */
  --text-2xl:   1.75rem;   /* 28px */
  --text-3xl:   2.25rem;   /* 36px */

  /* Spacing (4px base) */
  --sp-1:   4px;
  --sp-2:   8px;
  --sp-3:   12px;
  --sp-4:   16px;
  --sp-6:   24px;
  --sp-8:   32px;
  --sp-12:  48px;
  --sp-16:  64px;

  /* Radius */
  --radius-sm:    4px;
  --radius-md:    8px;
  --radius-lg:    12px;
  --radius-xl:    16px;
  --radius-full:  999px;

  /* Elevation — modals only */
  --shadow-modal: 0 4px 24px rgba(0, 0, 0, 0.30);

  /* Motion */
  --ease:         cubic-bezier(0.25, 0.1, 0.25, 1.0);
  --ease-enter:   cubic-bezier(0.0, 0.0, 0.2, 1.0);
  --ease-exit:    cubic-bezier(0.4, 0.0, 1.0, 1.0);
  --dur-micro:    80ms;
  --dur-quick:    150ms;
  --dur-default:  220ms;
  --dur-slow:     350ms;

  /* Layout */
  --sidebar-width: 240px;
  --content-max:   1200px;
}

/* ── Reset ────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--teal); text-decoration: none; transition: opacity var(--dur-quick) var(--ease); }
a:hover { opacity: 0.85; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.2;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Layout ───────────────────────────────────────────────── */

.app-layout {
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */

.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-logo {
  padding: var(--sp-6) var(--sp-6) var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.sidebar-logo img { height: 32px; }

.sidebar-brand {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.06em;
}

.sidebar-rule {
  height: 1px;
  border: none;
  background: linear-gradient(90deg, var(--teal), var(--blue));
  margin: 0 var(--sp-6);
  opacity: 0.6;
}

.sidebar-nav {
  flex: 1;
  padding: var(--sp-4) var(--sp-3);
  overflow-y: auto;
}

.nav-section {
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  user-select: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--dur-quick) var(--ease), color var(--dur-quick) var(--ease);
  margin-bottom: 2px;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--bg-raised);
  color: var(--text-primary);
  opacity: 1;
}

.nav-item.active {
  border-left-color: var(--teal);
  background: var(--bg-raised);
  color: var(--text-primary);
}

.nav-item .icon {
  font-size: var(--text-md);
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: var(--sp-3);
  border-top: 1px solid var(--border);
}

.nav-item-settings {
  margin-bottom: var(--sp-3);
}

.sidebar-user {
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
}

.sidebar-user .user-email {
  color: var(--text-secondary);
  font-size: var(--text-xs);
  display: block;
  margin-bottom: var(--sp-1);
  word-break: break-all;
}

.sidebar-link {
  font-size: var(--text-xs);
  color: var(--text-muted);
  transition: color var(--dur-quick) var(--ease);
}

.sidebar-link:hover { color: var(--text-secondary); opacity: 1; }

.sidebar-meta {
  padding: var(--sp-2) var(--sp-3) 0;
  font-size: var(--text-xs);
}

.sidebar-meta-sep { color: var(--text-muted); margin: 0 var(--sp-1); }

/* ── Main content ─────────────────────────────────────────── */

.main-content {
  margin-left: var(--sidebar-width);
  padding: var(--sp-8);
  max-width: var(--content-max);
}

.page-header {
  margin-bottom: var(--sp-8);
}

.page-header h1 {
  font-size: var(--text-2xl);
  color: var(--text-primary);
  margin-bottom: var(--sp-1);
}

.page-header p {
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

/* ── Cards ────────────────────────────────────────────────── */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}

.card-title {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
}

.stat-card .stat-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
}

.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1;
}

/* ── Buttons ──────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 40px;
  padding: 0 var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--dur-quick) var(--ease), background var(--dur-quick) var(--ease);
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { opacity: 0.85; }

/* Primary — dark navy, one per view */
.btn-primary {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--navy-hover);
  border-color: var(--navy-hover);
  opacity: 1;
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Secondary — teal outlined */
.btn-secondary {
  background: transparent;
  border-color: var(--teal);
  color: var(--teal);
}

.btn-secondary:hover {
  background: var(--teal-muted);
  opacity: 1;
}

/* Ghost — no border, no bg */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
  height: auto;
  padding: var(--sp-1) var(--sp-2);
}

.btn-ghost:hover {
  color: var(--text-primary);
  opacity: 1;
}

.btn-sm { height: 36px; padding: 0 var(--sp-3); font-size: var(--text-xs); }
.btn-lg { height: 48px; padding: 0 var(--sp-6); font-size: var(--text-md); }

/* ── Forms ────────────────────────────────────────────────── */

.form-group { margin-bottom: var(--sp-6); }

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  height: 40px;
  padding: 0 var(--sp-3);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-md);
  transition: border-color var(--dur-quick) var(--ease);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 2px var(--border-focus);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
  padding: var(--sp-3);
  height: auto;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
}

/* ── Tables ───────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
}

.table tr:last-child td { border-bottom: none; }

.table .msg-body {
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Badges ───────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.badge-inbound  { background: var(--teal-muted);    color: var(--teal); }
.badge-outbound { background: var(--blue-muted);     color: var(--blue); }
.badge-success  { background: var(--success-muted);  color: var(--success); }
.badge-error    { background: var(--error-muted);     color: var(--error); }
.badge-caution  { background: var(--caution-muted);   color: var(--caution); }

/* ── Alerts ───────────────────────────────────────────────── */

.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.alert-success { background: var(--success-muted); color: var(--success); }
.alert-error   { background: var(--error-muted);   color: var(--error); }

/* ── Toast ────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  top: var(--sp-6);
  right: var(--sp-6);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.toast {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-modal);
  font-size: var(--text-sm);
  animation: toastIn var(--dur-default) var(--ease-enter);
  max-width: 360px;
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--error); }

@keyframes toastIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Auth page (light mode — Engram reference) ────────────── */

.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #F8F9FA;
  color: var(--auth-text);
}

.auth-container {
  width: 100%;
  max-width: 480px;
  padding: var(--sp-8);
}

.auth-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.auth-header img { height: 36px; }

.auth-header-text {
  font-family: var(--font-body);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--auth-text);
  letter-spacing: -0.01em;
}

.auth-header-sub {
  font-size: var(--text-xs);
  color: var(--auth-muted);
  font-weight: 400;
  display: block;
}

.auth-rule {
  height: 1px;
  border: none;
  background: linear-gradient(90deg, var(--teal), var(--blue));
  margin-bottom: var(--sp-8);
  opacity: 0.5;
}

.auth-card {
  background: #FFFFFF;
  border: 1px solid var(--auth-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-8);
  margin-bottom: var(--sp-6);
}

.auth-card h2 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 500;
  color: var(--auth-text);
  margin-bottom: var(--sp-2);
}

.auth-card p {
  color: var(--auth-muted);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-6);
}

.auth-card .form-label {
  color: var(--auth-text);
  font-weight: 600;
  font-size: var(--text-sm);
}

.auth-card .form-input {
  background: var(--auth-surface);
  border: 1px solid var(--auth-border);
  color: var(--auth-text);
  border-radius: var(--radius-md);
  height: 48px;
  font-size: var(--text-md);
}

.auth-card .form-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(42, 191, 171, 0.15);
}

.auth-card .form-input::placeholder {
  color: var(--auth-muted);
}

.auth-card .form-hint {
  color: var(--auth-muted);
}

.auth-card .alert-error {
  background: rgba(122, 46, 46, 0.08);
  color: var(--error);
}

/* Auth buttons — Engram style */
.btn-auth-primary {
  width: 100%;
  height: 48px;
  background: var(--navy);
  border: none;
  border-radius: var(--radius-lg);
  color: #fff;
  font-family: var(--font-body);
  font-size: var(--text-md);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-quick) var(--ease);
}

.btn-auth-primary:hover { background: var(--navy-hover); }
.btn-auth-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-auth-secondary {
  width: 100%;
  height: 48px;
  background: transparent;
  border: 1px solid var(--auth-border);
  border-radius: var(--radius-lg);
  color: var(--auth-text);
  font-family: var(--font-body);
  font-size: var(--text-md);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-quick) var(--ease);
}

.btn-auth-secondary:hover { background: var(--auth-border); }

.auth-footer {
  text-align: center;
  margin-top: var(--sp-12);
}

.auth-footer img { height: 40px; margin-bottom: var(--sp-2); }

.auth-footer-text {
  font-size: var(--text-xs);
  color: var(--teal);
}

.auth-link {
  font-size: var(--text-sm);
  color: var(--auth-muted);
  margin-top: var(--sp-3);
  display: block;
  text-align: right;
}

.auth-link:hover { color: var(--auth-text); }

/* ── Search / Filters ─────────────────────────────────────── */

.filter-bar {
  display: flex;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
  flex-wrap: wrap;
}

.filter-bar .form-input,
.filter-bar .form-select { max-width: 250px; }

.search-input { flex: 1; min-width: 200px; }

/* ── Status dot ───────────────────────────────────────────── */

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  margin-right: var(--sp-2);
}

.status-dot.online  { background: var(--success); }
.status-dot.offline { background: var(--error); }
.status-dot.unknown { background: var(--text-muted); }

/* ── Settings list ────────────────────────────────────────── */

.settings-list { list-style: none; }

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}

.settings-item:last-child { border-bottom: none; }

.settings-key {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.settings-value {
  font-size: var(--text-sm);
  color: var(--text-primary);
  text-align: right;
}

/* ── CCP container (Voice page) ───────────────────────────── */

.ccp-container {
  height: 480px;
  width: 100%;
  max-width: 400px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-primary);
}

.ccp-container iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.ccp-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: var(--sp-8);
}

.ccp-fallback p { margin-bottom: var(--sp-4); font-size: var(--text-sm); }

/* ── Loading / skeleton ───────────────────────────────────── */

.skeleton {
  background: linear-gradient(90deg, var(--bg-raised) 25%, var(--bg-surface) 50%, var(--bg-raised) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.loading-text {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-12);
  color: var(--text-muted);
  gap: var(--sp-3);
  font-size: var(--text-sm);
}

/* Keep spinner for sub-1s operations */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--teal);
  border-radius: var(--radius-full);
  animation: spin 600ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ──────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: var(--sp-12);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* ── Responsive ───────────────────────────────────────────── */

.mobile-toggle {
  display: none;
  position: fixed;
  top: var(--sp-3);
  left: var(--sp-3);
  z-index: 200;
  padding: var(--sp-2);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-xl);
  cursor: pointer;
}

@media (max-width: 768px) {

  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--dur-default) var(--ease);
  }

  .sidebar.open { transform: translateX(0); }

  .main-content {
    margin-left: 0;
    padding: var(--sp-4);
    padding-top: var(--sp-12);
  }

  .mobile-toggle { display: block; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  .filter-bar { flex-direction: column; }
  .filter-bar .form-input,
  .filter-bar .form-select { max-width: 100%; }

  .table { font-size: var(--text-xs); }
  .table th, .table td { padding: var(--sp-2) var(--sp-3); }

  .auth-container { padding: var(--sp-4); max-width: 100%; }
  .auth-card { padding: var(--sp-6); border-radius: var(--radius-md); }
  .auth-header img { height: 28px; }
}

/* ── Utility ──────────────────────────────────────────────── */

.mt-1 { margin-top: var(--sp-2); }
.mt-2 { margin-top: var(--sp-4); }
.mt-3 { margin-top: var(--sp-6); }
.mb-1 { margin-bottom: var(--sp-2); }
.mb-2 { margin-bottom: var(--sp-4); }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: var(--sp-2); }
.gap-2 { gap: var(--sp-4); }
.text-muted { color: var(--text-muted); }
.text-teal { color: var(--teal); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-mono { font-family: var(--font-mono); font-size: 0.9em; }
.hidden { display: none !important; }
