/* ── Reset & Variables ───────────────────────────────────────────── */

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

:root {
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #1e293b;
  --bg-sidebar-hover: #334155;
  --bg-topbar: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-sidebar: #cbd5e1;
  --text-sidebar-active: #ffffff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --accent: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --border: #e2e8f0;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --transition: 0.2s ease;
}

html {
  font-size: 15px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
  border: none;
  font: inherit;
  background: none;
}

/* ── Utilities ──────────────────────────────────────────────────── */

.hidden {
  display: none !important;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.9rem;
  transition: all var(--transition);
  gap: 0.4rem;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  border: 1.5px solid var(--border);
  color: var(--text);
  background: var(--bg-card);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-ghost {
  color: var(--text-sidebar);
  opacity: 0.7;
}

.btn-ghost:hover {
  opacity: 1;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Login Screen ───────────────────────────────────────────────── */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  padding: 1rem;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.logo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 1.3rem;
  margin-bottom: 0.8rem;
}

.logo-sm {
  width: 36px;
  height: 36px;
  font-size: 0.85rem;
  border-radius: var(--radius);
}

.login-logo h1 {
  font-size: 1.4rem;
  font-weight: 700;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

.login-error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: border-color var(--transition);
  background: var(--bg-card);
  color: var(--text);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.divider {
  display: flex;
  align-items: center;
  margin: 1.2rem 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider span {
  padding: 0 0.8rem;
}

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

.app {
  display: flex;
  min-height: 100vh;
}

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-sidebar-active);
}

.sidebar-close {
  display: none;
  margin-left: auto;
  color: var(--text-sidebar);
  font-size: 1.4rem;
  background: none;
  border: none;
}

.sidebar-nav {
  flex: 1;
  padding: 0.6rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: background var(--transition);
}

.nav-item:hover {
  background: var(--bg-sidebar-hover);
}

.nav-item.active {
  background: var(--primary);
  color: var(--text-sidebar-active);
}

.nav-icon {
  font-size: 1.1rem;
  width: 1.4rem;
  text-align: center;
}

.sidebar-footer {
  padding: 0.8rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ── Main Content ───────────────────────────────────────────────── */

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ─────────────────────────────────────────────────────── */

.topbar {
  height: var(--topbar-h);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.2rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-btn {
  display: none;
  font-size: 1.3rem;
  color: var(--text);
}

.line-selector {
  display: flex;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 3px;
}

.line-btn {
  padding: 0.35rem 0.9rem;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all var(--transition);
}

.line-btn.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: var(--shadow);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.ws-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.ws-indicator.online {
  background: var(--accent);
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

.ws-indicator.offline {
  background: var(--text-muted);
}

.user-display {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── View Container ─────────────────────────────────────────────── */

.view-container {
  flex: 1;
  padding: 1.2rem;
  overflow-y: auto;
}

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

.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.card-body {
  padding: 1.1rem;
}

/* ── Filter Tabs ────────────────────────────────────────────────── */

.filter-tabs {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 0.3rem 0.7rem;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  transition: all var(--transition);
}

.filter-tab.active {
  background: var(--primary);
  color: #fff;
}

.filter-tab:hover:not(.active) {
  background: var(--border);
}

/* ── Call List ───────────────────────────────────────────────────── */

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

.call-item {
  display: flex;
  align-items: center;
  padding: 0.7rem 1.1rem;
  gap: 0.8rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

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

.call-item:hover {
  background: var(--bg);
}

.call-direction {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.call-direction.incoming {
  background: #dbeafe;
  color: var(--primary);
}

.call-direction.outgoing {
  background: #d1fae5;
  color: var(--accent);
}

.call-direction.missed {
  background: #fef2f2;
  color: var(--danger);
}

.call-info {
  flex: 1;
  min-width: 0;
}

.call-name {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.call-number {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.call-meta {
  text-align: right;
  flex-shrink: 0;
}

.call-date {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.call-duration {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ── Mailbox ────────────────────────────────────────────────────── */

.mailbox-item {
  display: flex;
  align-items: flex-start;
  padding: 0.8rem 1.1rem;
  gap: 0.8rem;
  border-bottom: 1px solid var(--border);
}

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

.mailbox-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.mailbox-info {
  flex: 1;
  min-width: 0;
}

.mailbox-caller {
  font-weight: 500;
  font-size: 0.9rem;
}

.mailbox-details {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.audio-player {
  margin-top: 0.5rem;
  width: 100%;
  max-width: 320px;
}

.audio-player audio {
  width: 100%;
  height: 36px;
  border-radius: var(--radius);
}

/* ── Forwarding ─────────────────────────────────────────────────── */

.forwarding-options {
  display: grid;
  gap: 0.8rem;
  max-width: 480px;
}

.forwarding-option {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.2rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
}

.forwarding-option:hover {
  border-color: var(--primary);
}

.forwarding-option.active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.fwd-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  background: var(--bg);
}

.forwarding-option.active .fwd-icon {
  background: var(--primary);
  color: #fff;
}

.fwd-info h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.fwd-info p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.forwarding-status {
  margin-top: 1rem;
  padding: 0.7rem 1rem;
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.forwarding-status strong {
  color: var(--text);
}

/* ── Live Status ────────────────────────────────────────────────── */

.status-feed {
  list-style: none;
  max-height: 70vh;
  overflow-y: auto;
}

.status-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.status-empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.6rem;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.65rem 1.1rem;
  border-bottom: 1px solid var(--border);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.ring {
  background: var(--warning);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
  animation: pulse 1.5s ease infinite;
}

.status-dot.connect {
  background: var(--accent);
}

.status-dot.disconnect {
  background: var(--text-muted);
}

.status-dot.outbound {
  background: var(--primary);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.status-text {
  flex: 1;
  font-size: 0.85rem;
}

.status-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Loading / Empty States ─────────────────────────────────────── */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  gap: 0.6rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

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

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
  }

  .sidebar-close {
    display: block;
  }

  .main {
    margin-left: 0;
  }

  .menu-btn {
    display: block;
  }

  .line-selector {
    flex: 1;
    justify-content: center;
  }

  .user-display {
    display: none;
  }

  .call-item,
  .mailbox-item,
  .status-item {
    padding-left: 0.7rem;
    padding-right: 0.7rem;
  }

  .forwarding-option {
    padding: 0.8rem;
  }
}

/* ── Backdrop for mobile sidebar ────────────────────────────────── */

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.sidebar-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}
