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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --accent: #6C63FF;
  --accent-hover: #5a52d5;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b0;
  --text-muted: #6a6a7a;
  --success: #4caf50;
  --danger: #e53935;
  --warning: #ff9800;
  --border: #2a2a4a;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

#app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}

.header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Page container */
.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.page.active {
  display: flex;
  flex-direction: column;
}

#conversation-page.active {
  overflow: hidden;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  text-decoration: none;
  color: white;
}

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

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

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

.btn-success {
  background: var(--success);
}

.btn-success:hover:not(:disabled) {
  background: #388e3c;
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: #c62828;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
}

.btn-icon.large {
  width: 56px;
  height: 56px;
  font-size: 24px;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--accent);
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

/* Login page */
.login-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
}

.login-container .logo {
  font-size: 48px;
  margin-bottom: 8px;
}

.login-container h2 {
  font-size: 24px;
  margin-bottom: 4px;
  color: var(--accent);
}

.login-container p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 14px;
}

.login-form {
  width: 100%;
  max-width: 360px;
}

/* Pending page */
.pending-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
}

.pending-container .spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Contact list */
.contact-list {
  list-style: none;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
  border-bottom: 1px solid var(--border);
}

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

.contact-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  color: var(--accent);
  flex-shrink: 0;
}

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

.contact-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-email {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot.online {
  background: var(--success);
}

/* Chat page */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.chat-header .back-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

.message.sent {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.received {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message .time {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
}

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.chat-input-area input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.chat-input-area input:focus {
  border-color: var(--accent);
}

/* Call page */
.call-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  position: relative;
}

.call-container .remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.call-container .local-video {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 120px;
  height: 160px;
  border-radius: var(--radius);
  object-fit: cover;
  border: 2px solid var(--border);
  background: #000;
  z-index: 10;
}

.call-info {
  text-align: center;
  z-index: 5;
}

.call-info h3 {
  font-size: 24px;
  margin-bottom: 8px;
}

.call-info p {
  color: var(--text-secondary);
  font-size: 14px;
}

.call-controls {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  z-index: 10;
}

/* Incoming call modal */
.incoming-call-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.incoming-call-modal.active {
  display: flex;
}

.incoming-call-modal h3 {
  font-size: 20px;
}

.incoming-call-modal p {
  color: var(--text-secondary);
}

.incoming-call-modal .actions {
  display: flex;
  gap: 32px;
}

/* Admin page */
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.admin-tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
}

.admin-tab.active {
  background: var(--accent);
  color: white;
}

.user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.user-item .user-info {
  flex: 1;
}

.user-item .user-email {
  font-weight: 600;
  font-size: 14px;
}

.user-item .user-date {
  font-size: 12px;
  color: var(--text-muted);
}

.user-item .user-actions {
  display: flex;
  gap: 8px;
}

/* Admin section tabs */
.admin-section-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border);
}

.admin-section-tab {
  padding: 10px 20px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}

.admin-section-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Config form */
.config-warning {
  background: rgba(255, 152, 0, 0.1);
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--warning);
  margin-bottom: 16px;
}

.config-group {
  margin-bottom: 20px;
}

.config-group-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.config-field {
  margin-bottom: 12px;
}

.config-field label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.config-field .config-source {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-muted);
}

.config-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: monospace;
}

.config-field input:focus {
  border-color: var(--accent);
}

/* System dashboard */
.system-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
}

.service-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

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

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

.service-dot.running {
  background: var(--success);
}

.service-dot.stopped {
  background: var(--danger);
}

.service-name {
  font-weight: 600;
  min-width: 100px;
}

.service-status {
  color: var(--text-secondary);
  font-size: 13px;
}

.service-detail {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 12px;
  font-family: monospace;
}

.system-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.system-metric {
  display: flex;
  gap: 4px;
}

.system-metric .label {
  color: var(--text-muted);
}

.system-metric .value {
  color: var(--text-primary);
  font-family: monospace;
}

.log-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.log-tab {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
}

.log-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.log-viewer {
  background: #0a0a1a;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-bottom: 8px;
}

.log-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.log-auto-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.log-auto-refresh input[type="checkbox"] {
  accent-color: var(--accent);
}

/* Status badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-pending {
  background: var(--warning);
  color: #000;
}

.badge-approved {
  background: var(--success);
  color: white;
}

.badge-blocked {
  background: var(--danger);
  color: white;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 14px;
  border: 1px solid var(--border);
  animation: slideIn 0.3s ease;
  max-width: 320px;
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--danger);
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

/* Utility */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

/* Responsive */
@media (min-width: 768px) {
  .page {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
  }

  .call-container .local-video {
    width: 180px;
    height: 240px;
  }
}
