* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-left h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.header-right {
  display: flex;
  gap: 0.5rem;
}

.badge {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-family: monospace;
  color: var(--text-secondary);
}

main {
  display: flex;
  min-height: calc(100vh - 57px);
}

.sidebar {
  width: 220px;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-btn {
  background: none;
  border: none;
  padding: 0.625rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  text-align: left;
  font-size: 0.875rem;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.nav-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-btn.active {
  background: var(--primary);
  color: white;
  font-weight: 600;
}

.content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

.content h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.select, .input {
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.875rem;
  color: var(--text);
  min-width: 200px;
}

.select:disabled, .input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.data-table {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  overflow: hidden;
}

.data-table table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  background: var(--bg);
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: var(--bg);
}

.hint {
  color: var(--text-muted);
  padding: 2rem;
  text-align: center;
  font-size: 0.875rem;
}

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-queued { background: #fef3c7; color: #92400e; }
.status-sending { background: #dbeafe; color: #1e40af; }
.status-sent { background: #d1fae5; color: #065f46; }
.status-delivered { background: #d1fae5; color: #065f46; }
.status-failed { background: #fee2e2; color: #991b1b; }
.status-received { background: #e0e7ff; color: #3730a3; }
.status-read { background: #f3e8ff; color: #6b21a8; }

/* Method badge */
.method-badge {
  display: inline-block;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  font-family: monospace;
}

.method-post { background: #d1fae5; color: #065f46; }
.method-get { background: #dbeafe; color: #1e40af; }

/* Code block */
.code-block {
  background: #1e293b;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 0.5rem;
  font-family: monospace;
  font-size: 0.75rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--card);
  border-radius: 1rem;
  width: 90%;
  max-width: 640px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1.125rem;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--text-muted);
  padding: 0.25rem;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 1.5rem;
}

/* Form */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
  color: var(--text);
}

.form-group input, .form-group select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  font-size: 0.875rem;
}

.form-group .hint-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 0.75rem 1.5rem;
  border-radius: 0.75rem;
  color: white;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 300;
  animation: slideIn 0.3s ease;
  box-shadow: 0 10px 15px rgba(0,0,0,0.2);
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

@keyframes slideIn {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Empty state */
.empty-state {
  padding: 3rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-state p {
  font-size: 0.875rem;
}

/* Copy button */
.copy-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  cursor: pointer;
  font-size: 0.6875rem;
  font-family: monospace;
  color: var(--text-secondary);
  margin-left: 0.5rem;
}

.copy-btn:hover {
  background: var(--bg);
}

/* Help / Documentation Footer */
.help-footer {
  border-top: 1px solid var(--border);
  background: var(--card);
  margin-top: 1rem;
}

.help-header {
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  transition: color 0.15s;
}

.help-header:hover {
  color: var(--text);
  background: var(--bg);
}

.help-content {
  padding: 0 1.5rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.help-section {
  max-width: 800px;
}

.help-section h4 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin: 1rem 0 0.5rem;
}

.help-section p {
  margin-bottom: 0.5rem;
}

.help-section ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.help-section ol li {
  margin-bottom: 0.25rem;
}

.help-footer-meta {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.help-footer-meta a {
  color: var(--primary);
  text-decoration: none;
}

.help-footer-meta a:hover {
  text-decoration: underline;
}

/* Phone Widget — independent floating windows */
#phone-widgets {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 150;
  overflow: hidden;
}

.phone-widget {
  width: 340px;
  height: 460px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: fixed;
  pointer-events: all;
  transition: box-shadow 0.2s;
  min-width: 280px;
  min-height: 350px;
  z-index: 151;
}

.phone-widget:hover {
  box-shadow: 0 12px 48px rgba(0,0,0,0.2);
}

.widget-header {
  background: var(--primary);
  color: white;
  padding: 0.625rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}

.widget-header:active {
  cursor: grabbing;
}

.widget-title {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.widget-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.25rem;
  opacity: 0.8;
  transition: opacity 0.15s;
}

.widget-close:hover {
  opacity: 1;
}

.widget-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.widget-tab {
  flex: 1;
  padding: 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all 0.15s;
  border-bottom: 2px solid transparent;
}

.widget-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.widget-tab:hover {
  background: var(--bg);
}

/* Widget conversation list */
.widget-conversations {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.widget-conv-item {
  padding: 0.625rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.widget-conv-item:hover {
  background: var(--bg);
}

.widget-conv-item.conv-active {
  background: #eef2ff;
}

/* Chat view: fills space, input sticks to bottom */
.widget-chat-view {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
}

.widget-back {
  font-size: 1.25rem;
  line-height: 1;
  padding: 0 0.25rem;
  cursor: pointer;
}

.widget-back:hover {
  opacity: 0.7;
}

.widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
}

.widget-input-area {
  display: flex;
  gap: 0.375rem;
  padding: 0.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  margin-top: auto; /* stick to bottom */
}

.widget-to {
  width: 120px;
  flex-shrink: 0;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.75rem;
  font-family: monospace;
}

.widget-body {
  flex: 1;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.75rem;
}

/* Resize handle at bottom-right corner */
.widget-resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 10;
}

.widget-resize-handle::after {
  content: '';
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  opacity: 0.5;
}



/* Dashboard — phone grid */
.phone-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.5rem 0;
  min-height: 200px;
  align-content: flex-start;
}

/* Mini phone handset cards */
.phone-handset {
  width: 148px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.875rem;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
  user-select: none;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.phone-handset:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 16px rgba(99,102,241,0.12);
}

.handset-icon {
  font-size: 1.75rem;
  line-height: 1;
  margin-bottom: 0.125rem;
}

.handset-number {
  font-size: 0.8125rem;
  font-weight: 700;
  font-family: monospace;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.handset-badge {
  position: absolute;
  top: 0.375rem;
  right: 0.375rem;
  background: var(--primary);
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  min-width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.25rem;
}

.handset-status {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 600;
}

.handset-snippet {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.handset-partners {
  font-size: 0.625rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

/* Webhook Console — fixed bottom terminal panel */
.webhook-console {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #0d1117;
  border-top: 2px solid #30363d;
  font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  height: 260px;
  transition: height 0.15s ease;
}

.webhook-console.collapsed {
  height: 36px !important;
}

.webhook-console.collapsed .console-body,
.webhook-console.collapsed .console-resize {
  display: none;
}

.console-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 1rem;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  user-select: none;
  flex-shrink: 0;
  cursor: ns-resize;
}

.console-title {
  color: #c9d1d9;
  font-weight: 700;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.console-badge {
  background: #30363d;
  color: #8b949e;
  font-size: 0.625rem;
  padding: 0.0625rem 0.5rem;
  border-radius: 999px;
  min-width: 1.25rem;
  text-align: center;
}

.console-status {
  color: #8b949e;
  font-size: 0.625rem;
}

.console-spacer {
  flex: 1;
}

.console-btn {
  background: none;
  border: 1px solid #30363d;
  color: #8b949e;
  cursor: pointer;
  font-size: 0.6875rem;
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  transition: color 0.15s, border-color 0.15s;
}

.console-btn:hover {
  color: #c9d1d9;
  border-color: #c9d1d9;
}

.console-body {
  flex: 1;
  padding: 0.375rem 0.75rem;
  overflow-y: auto;
  scroll-behavior: smooth;
  min-height: 0;
}

.console-body::-webkit-scrollbar {
  width: 6px;
}

.console-body::-webkit-scrollbar-track {
  background: #0d1117;
}

.console-body::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 3px;
}

.console-body::-webkit-scrollbar-thumb:hover {
  background: #484f58;
}

.console-line {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid #21262d;
  white-space: pre-wrap;
  word-break: break-all;
  cursor: pointer;
  transition: background 0.1s;
  font-size: 0.6875rem;
  line-height: 1.5;
}

.console-line:last-child {
  border-bottom: none;
}

.console-line:hover {
  background: #161b22;
}

.console-line .line-time {
  color: #8b949e;
  font-size: 0.625rem;
  margin-right: 0.5rem;
  user-select: none;
}

.console-line .line-event {
  font-weight: 700;
  font-size: 0.625rem;
  text-transform: uppercase;
  padding: 0.0625rem 0.375rem;
  border-radius: 0.1875rem;
  margin-right: 0.375rem;
}

.line-event-inbound {
  color: #58a6ff;
  background: rgba(88,166,255,0.12);
}

.line-event-status {
  color: #d2a8ff;
  background: rgba(210,168,255,0.12);
}

.line-event-outbound {
  color: #7ee787;
  background: rgba(126,231,135,0.12);
}

.console-line .line-url {
  color: #c9d1d9;
  font-size: 0.6875rem;
}

.console-line .line-status {
  font-weight: 700;
  margin: 0 0.25rem;
}

.line-status-200, .line-status-201, .line-status-204 {
  color: #22c55e;
}

.line-status-400, .line-status-404, .line-status-422 {
  color: #eab308;
}

.line-status-500 {
  color: #ef4444;
}

.line-status-pending {
  color: #8b949e;
}

.line-status-success {
  color: #22c55e;
}

.line-status-failed {
  color: #ef4444;
}

.console-line .line-arrow {
  color: #30363d;
  margin: 0 0.25rem;
}

.console-line .line-msgid {
  color: #8b949e;
  font-size: 0.625rem;
  margin-left: 0.5rem;
}

/* Expanded detail inside a console line */
.console-detail {
  display: none;
  margin-top: 0.375rem;
  padding: 0.5rem 0.75rem;
  background: #161b22;
  border-radius: 0.375rem;
  border: 1px solid #30363d;
  font-size: 0.6875rem;
  line-height: 1.6;
}

.console-detail.open {
  display: block;
}

.console-detail .detail-label {
  color: #8b949e;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.5rem;
}

.console-detail .detail-label:first-child {
  margin-top: 0;
}

.console-detail .detail-value {
  color: #c9d1d9;
  font-family: inherit;
  white-space: pre-wrap;
  word-break: break-all;
  background: #0d1117;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  margin-top: 0.125rem;
  max-height: 120px;
  overflow-y: auto;
  font-size: 0.6875rem;
}

.console-detail .detail-value::-webkit-scrollbar {
  width: 4px;
}

.console-detail .detail-value::-webkit-scrollbar-track {
  background: #0d1117;
}

.console-detail .detail-value::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 2px;
}

.console-info {
  color: #8b949e;
  font-style: italic;
  cursor: default;
}

.console-info:hover {
  background: transparent;
}

/* Resize handle */
.console-resize {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  cursor: ns-resize;
  background: transparent;
  z-index: 1001;
}

.console-resize:hover,
.console-resize:active {
  background: #30363d;
}

/* Push main content up so it's not hidden behind the console */
main {
  padding-bottom: 270px;
}

/* Responsive */
@media (max-width: 768px) {
  .help-content {
    padding: 0 1rem 1rem;
  }
  #phone-widgets {
    right: 0.5rem;
    bottom: 0.5rem;
  }
  .phone-widget {
    width: 300px;
    height: 400px;
  }
}

/* Responsive */
@media (max-width: 768px) {
  main {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .nav-btn {
    white-space: nowrap;
  }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .select, .input {
    min-width: auto;
  }
}
