/* ===================================================
   CallSync Design System - Denkcode Studio Standard
   Taktile 3D-UI, Obsidian Theme, High Precision Micro-Interactions
   =================================================== */

:root {
  --bg-deep: #080b12;
  --bg-surface: #0f1422;
  --bg-card: #151c2e;
  --bg-card-alt: #1a2238;
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(255, 255, 255, 0.14);
  --border-tactile-top: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --color-green: #10b981;
  --color-green-glow: rgba(16, 185, 129, 0.28);
  --color-yellow: #f59e0b;
  --color-yellow-glow: rgba(245, 158, 11, 0.32);
  --color-red: #ef4444;
  --color-red-glow: rgba(239, 68, 68, 0.35);
  --color-blue: #3b82f6;
  --color-blue-glow: rgba(59, 130, 246, 0.3);
  --color-gray: #64748b;

  --shadow-tactile: 0 16px 36px -10px rgba(0, 0, 0, 0.65), 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-btn: 0 4px 12px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

input, code {
  user-select: text;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  background-image: 
    radial-gradient(ellipse at 50% 0%, rgba(30, 64, 130, 0.18) 0%, transparent 65%),
    radial-gradient(ellipse at 85% 100%, rgba(20, 30, 60, 0.2) 0%, transparent 50%);
  background-attachment: fixed;
}

.app-viewport {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px env(safe-area-inset-bottom, 16px) 16px;
}

/* ================= TOP NAVIGATION ================= */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 8px;
  padding-top: max(16px, env(safe-area-inset-top, 16px));
  border-bottom: 1px solid var(--border-subtle);
  gap: 16px;
  flex-wrap: wrap;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-gem {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #1e3a8a 0%, #0284c7 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  position: relative;
  box-shadow: 0 4px 15px rgba(2, 132, 199, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.gem-pulse {
  position: absolute;
  inset: -2px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(56, 189, 248, 0.5);
  animation: pulse-border 2.5s infinite;
}

@keyframes pulse-border {
  0%, 100% { opacity: 0.2; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.04); }
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #ffffff 30%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #38bdf8;
}

/* Nav Tabs */
.nav-tabs {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-primary);
  transition: transform 0.15s ease, background 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.95);
}

.primary-btn-sm {
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-btn);
  color: #fff;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.primary-btn-sm:active {
  transform: translateY(1px);
}

/* ================= MAIN BODY ================= */
.main-body {
  flex: 1;
  padding: 20px 0;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

/* Taktile Base Class */
.tactile {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-tactile);
  border-radius: var(--radius-lg);
  position: relative;
  box-shadow: var(--shadow-tactile), var(--border-tactile-top);
}

/* Metrics KPI Strip */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.metric-card {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
}

.metric-card.glow-red {
  border-color: rgba(239, 68, 68, 0.25);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.08) 0%, var(--bg-surface) 100%);
}

.metric-card.glow-yellow {
  border-color: rgba(245, 158, 11, 0.25);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.08) 0%, var(--bg-surface) 100%);
}

.metric-card.glow-green {
  border-color: rgba(16, 185, 129, 0.25);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, var(--bg-surface) 100%);
}

.metric-icon {
  font-size: 1.4rem;
}

.metric-data {
  display: flex;
  flex-direction: column;
}

.metric-val {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Action Strip */
.action-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  flex: 1;
  max-width: 360px;
}

.search-box input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  width: 100%;
}

.status-connection {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.ws-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e2e8f0;
  box-shadow: 0 0 8px #94a3b8;
  transition: all 0.3s ease;
}

.ws-indicator.online {
  background: var(--color-green);
  box-shadow: 0 0 10px var(--color-green);
}

.ws-indicator.offline {
  background: var(--color-red);
  box-shadow: 0 0 10px var(--color-red);
}

/* ================= DEVICES GRID ================= */
.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

/* Phone Card - High-End Tactile Hardware Aesthetic */
.device-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}

.device-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--color-gray);
  transition: background 0.3s ease;
}

/* Status variants for cards */
.device-card.status-free::before {
  background: var(--color-green);
}

.device-card.status-ringing::before {
  background: var(--color-yellow);
}

.device-card.status-ringing {
  border-color: rgba(245, 158, 11, 0.4);
  box-shadow: 0 20px 40px -10px var(--color-yellow-glow), var(--border-tactile-top);
  animation: card-ring-pulse 1.6s infinite ease-in-out;
}

@keyframes card-ring-pulse {
  0%, 100% { border-color: rgba(245, 158, 11, 0.3); }
  50% { border-color: rgba(245, 158, 11, 0.7); }
}

.device-card.status-incall::before {
  background: var(--color-red);
}

.device-card.status-incall {
  border-color: rgba(239, 68, 68, 0.4);
  box-shadow: 0 20px 40px -10px var(--color-red-glow), var(--border-tactile-top);
}

.device-card.status-offline {
  opacity: 0.65;
  filter: grayscale(0.5);
}

/* Card Header */
.dev-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.dev-name-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dev-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.dev-os-pill {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  align-self: flex-start;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* LED Indicator in Card */
.dev-status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
}

.led-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  position: relative;
}

.led-free {
  background: var(--color-green);
  box-shadow: 0 0 10px var(--color-green);
}

.led-ringing {
  background: var(--color-yellow);
  box-shadow: 0 0 12px var(--color-yellow);
  animation: led-blink 0.6s infinite alternate;
}

.led-incall {
  background: var(--color-red);
  box-shadow: 0 0 14px var(--color-red);
}

.led-offline {
  background: var(--color-gray);
}

@keyframes led-blink {
  0% { opacity: 0.4; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1.15); }
}

/* Card Body - Call Info */
.dev-call-details {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.call-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.call-label {
  color: var(--text-secondary);
}

.call-number {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 0.95rem;
  color: #38bdf8;
  letter-spacing: 0.03em;
}

.call-direction {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
}

.dir-incoming {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.4);
}

.dir-outgoing {
  background: rgba(168, 85, 247, 0.2);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.4);
}

.live-timer {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--color-red);
  letter-spacing: 0.05em;
  text-align: center;
  padding: 6px 0;
  background: rgba(239, 68, 68, 0.08);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Card Footer */
.dev-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  padding-top: 12px;
}

.dev-actions {
  display: flex;
  gap: 6px;
}

.text-btn-sm {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.text-btn-sm:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.text-btn-sm.delete:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-red);
}

/* Empty State */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  background: var(--bg-surface);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.empty-icon {
  font-size: 3rem;
  opacity: 0.7;
}

.empty-state h3 {
  font-size: 1.25rem;
  font-weight: 700;
}

.empty-state p {
  color: var(--text-secondary);
  max-width: 440px;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ================= DEVICE SETTINGS PANEL ================= */
.device-panel-container {
  max-width: 680px;
  margin: 0 auto;
}

.device-config-card {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.header-title h3 {
  font-size: 1.25rem;
  font-weight: 800;
}

.header-title p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.device-badge {
  background: #1e3a8a;
  color: #60a5fa;
  border: 1px solid #2563eb;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.config-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.config-row label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.input-with-button {
  display: flex;
  gap: 10px;
}

.input-with-button input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
}

.input-with-button input:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 2px var(--color-blue-glow);
}

.id-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 14px;
}

.id-display code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: #38bdf8;
}

.copy-btn, .secondary-btn {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.hint-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Permissions Checklist */
.permissions-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.permissions-section h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.perm-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.perm-item:last-of-type {
  border-bottom: none;
}

.perm-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.perm-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.perm-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.perm-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.perm-pill.success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--color-green);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.perm-pill.warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--color-yellow);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.primary-btn {
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-btn);
  color: #fff;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 12px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-btn.full-width {
  width: 100%;
}

/* Simulator Grid */
.test-simulator {
  border-top: 1px solid var(--border-subtle);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.test-simulator h4 {
  font-size: 0.95rem;
  font-weight: 700;
}

.test-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.sim-buttons-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.sim-btn {
  padding: 12px 8px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: all 0.15s ease;
}

.sim-btn span {
  font-size: 1.2rem;
}

.sim-btn.sim-ring:active {
  background: rgba(245, 158, 11, 0.2);
  border-color: var(--color-yellow);
}

.sim-btn.sim-connect:active {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--color-red);
}

.sim-btn.sim-hangup:active {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--color-green);
}

/* ================= MODAL ================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  max-width: 440px;
  width: 100%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.2rem;
  font-weight: 800;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.qr-canvas-box {
  background: #fff;
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.pairing-link-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pairing-link-box label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ================= FOOTER ================= */
.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
  padding: 16px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer-privacy {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #38bdf8;
}

/* Mobile Adjustments */
@media (max-width: 600px) {
  .top-nav {
    flex-direction: column;
    align-items: stretch;
  }
  
  .nav-controls {
    justify-content: space-between;
  }

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

  .devices-grid {
    grid-template-columns: 1fr;
  }

  .sim-buttons-grid {
    grid-template-columns: 1fr;
  }
}
