/* ==========================================================================
   P2P File Sharing - Modern WebRTC Stylesheet
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #475569;
  --secondary-hover: #334155;
  --success: #10b981;
  --success-dark: #059669;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;

  --bg: #0f172a;
  --card-bg: #1e293b;
  --card-border: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-subtle: #334155;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

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

/* ==========================================================================
   Layout
   ========================================================================== */

.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem 1rem 8rem 1rem;
}

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

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.logo-icon {
  font-size: 2.2rem;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

h1 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

/* ==========================================================================
   Stepper (7 bước WebRTC)
   ========================================================================== */

.stepper-container {
  margin-bottom: 1.75rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 600px;
  background: var(--card-bg);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
}

.stepper-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  position: relative;
  z-index: 2;
  transition: all 0.3s ease;
}

.step-circle {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  background: #334155;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  transition: all 0.3s ease;
}

.step-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.stepper-line {
  flex: 1;
  height: 2px;
  background: #334155;
  margin: 0 0.4rem;
  margin-top: -16px;
  z-index: 1;
}

.stepper-item.active .step-circle {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.6);
  transform: scale(1.15);
}

.stepper-item.active .step-label {
  color: #93c5fd;
  font-weight: 600;
}

.stepper-item.completed .step-circle {
  background: var(--success);
  color: #fff;
}

.stepper-item.completed .step-label {
  color: var(--success);
}

/* ==========================================================================
   Cards & Components
   ========================================================================== */

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

/* Lobby */
.lobby-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.lobby-box {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.divider-vertical {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
}

/* Waiting Screens */
.screen-waiting {
  padding: 3rem 1.5rem;
}

.display-code {
  font-family: var(--font-mono);
  font-size: 2.75rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: #38bdf8;
  display: inline-block;
  padding: 0.5rem 1.5rem;
  background: #0f172a;
  border-radius: var(--radius-md);
  border: 2px dashed #0284c7;
}

.room-code-display-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}

.status-indicator-box {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1.2rem;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-full);
  color: #7dd3fc;
  font-size: 0.9rem;
}

.pulsing-dot {
  width: 10px;
  height: 10px;
  background: #38bdf8;
  border-radius: var(--radius-full);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.6; }
  50% { transform: scale(1.3); opacity: 1; box-shadow: 0 0 8px #38bdf8; }
  100% { transform: scale(0.9); opacity: 0.6; }
}

.waiting-spinner, .connecting-loader {
  width: 44px;
  height: 44px;
  border: 4px solid #334155;
  border-top-color: var(--primary);
  border-radius: var(--radius-full);
  margin: 0 auto 1.25rem auto;
  animation: spin 1s linear infinite;
}

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

/* Connected Status Bar */
.status-bar-card {
  padding: 1.25rem;
  background: #1e293b;
  border-left: 4px solid var(--success);
}

.status-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.peer-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1rem;
}

.status-dot-online {
  width: 10px;
  height: 10px;
  background: var(--success);
  border-radius: var(--radius-full);
  box-shadow: 0 0 8px var(--success);
}

.room-tag {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

.connection-telemetry {
  display: flex;
  gap: 1.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.telemetry-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

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

/* File Drop Zone */
.file-drop-zone {
  border: 2px dashed #475569;
  border-radius: var(--radius-md);
  padding: 2.25rem 1.5rem;
  text-align: center;
  background: rgba(15, 23, 42, 0.4);
  cursor: pointer;
  transition: all 0.2s ease;
}

.file-drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.1);
}

.drop-zone-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.file-browse-link {
  color: #38bdf8;
  text-decoration: underline;
  cursor: pointer;
  font-weight: 500;
}

.hidden-file-input {
  display: none;
}

/* Selected File Card */
.selected-file-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #0f172a;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.25rem;
  margin-top: 1rem;
}

.selected-file-info {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.file-icon {
  font-size: 1.75rem;
}

.file-name {
  font-size: 0.95rem;
  word-break: break-all;
}

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

/* Action Buttons */
.transfer-action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.benchmark-btn-group {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Progress Card */
.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.progress-bar-track {
  width: 100%;
  height: 12px;
  background: #334155;
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #2563eb);
  transition: width 0.15s ease;
}

.progress-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Result Card */
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 1rem;
  background: #0f172a;
  padding: 1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
}

.result-grid .full-width {
  grid-column: 1 / -1;
  word-break: break-all;
}

/* Benchmark Result */
.benchmark-bars-container {
  background: #0f172a;
  padding: 1rem;
  border-radius: var(--radius-md);
}

.bar-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.bar-track {
  width: 100%;
  height: 28px;
  background: #334155;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  display: flex;
  align-items: center;
  padding-left: 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  transition: width 0.4s ease;
}

.bar-p2p {
  background: linear-gradient(90deg, #059669, #10b981);
}

.bar-relay {
  background: linear-gradient(90deg, #4f46e5, #6366f1);
}

.benchmark-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.benchmark-table th, .benchmark-table td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.benchmark-table th {
  background: rgba(15, 23, 42, 0.5);
  color: var(--text-muted);
}

.server-stats-badge {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
}

/* ==========================================================================
   Collapsible Log Panel
   ========================================================================== */

.log-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #090d16;
  border-top: 2px solid #334155;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  height: 280px;
  display: flex;
  flex-direction: column;
  transition: height 0.25s ease;
  z-index: 100;
}

.log-panel.collapsed {
  height: 38px;
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 1rem;
  background: #1e293b;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.log-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0.5rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.log-entry {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.log-time {
  color: #64748b;
  min-width: 80px;
}

.badge-tag {
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 48px;
  text-align: center;
}

.log-tag-ws { background: #3b82f6; color: #fff; }
.log-tag-pc { background: #8b5cf6; color: #fff; }
.log-tag-ice { background: #ec4899; color: #fff; }
.log-tag-dc { background: #10b981; color: #fff; }
.log-tag-xfer { background: #06b6d4; color: #fff; }
.log-tag-relay { background: #f59e0b; color: #fff; }
.log-tag-bench { background: #eab308; color: #000; }

.log-msg {
  flex: 1;
  word-break: break-all;
}

.btn-log-details {
  background: none;
  border: 1px solid #475569;
  color: #94a3b8;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-log-details:hover {
  background: #334155;
  color: #fff;
}

/* ==========================================================================
   Modals & Dialogs
   ========================================================================== */

.custom-modal {
  margin: auto;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  background: var(--card-bg);
  color: var(--text-main);
  padding: 1.5rem;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.custom-modal::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal-lg {
  max-width: 800px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.modal-scroll-body {
  max-height: 60vh;
  overflow-y: auto;
  margin: 1rem 0;
}

.code-block {
  background: #090d16;
  padding: 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  overflow-x: auto;
  border: 1px solid #1e293b;
}

/* SDP Syntax Highlights */
.sdp-hl-media { color: #f43f5e; font-weight: bold; }
.sdp-hl-fingerprint { color: #38bdf8; font-weight: bold; }
.sdp-hl-sctp { color: #a855f7; font-weight: bold; }
.sdp-hl-candidate { color: #10b981; }
.sdp-hl-conn { color: #fbbf24; }

/* ==========================================================================
   Toasts
   ========================================================================== */

.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  color: #fff;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  animation: slideIn 0.3s ease;
  max-width: 400px;
}

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

.toast.fade-out {
  opacity: 0;
  transform: translateX(50%);
  transition: all 0.3s ease;
}

.toast-info { background: #0284c7; }
.toast-success { background: #059669; }
.toast-warning { background: #d97706; }
.toast-error { background: #dc2626; }

/* ==========================================================================
   Buttons & Inputs
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.15rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

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

.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover:not(:disabled) { background: var(--secondary-hover); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-dark); }

.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover:not(:disabled) { background: #d97706; color: #fff; }

.btn-outline-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: #fca5a5;
}
.btn-outline-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn-text {
  background: transparent;
  color: var(--text-muted);
}
.btn-text:hover { color: #fff; }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-xs { padding: 0.2rem 0.5rem; font-size: 0.75rem; }
.btn-block { width: 100%; }

.form-control {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: #0f172a;
  color: var(--text-main);
  font-size: 0.95rem;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
}

.form-select {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: #0f172a;
  color: var(--text-main);
  font-size: 0.85rem;
}

.input-group {
  display: flex;
  gap: 0.5rem;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-lan { background: #065f46; color: #6ee7b7; }
.badge-stun { background: #1e40af; color: #93c5fd; }
.badge-turn { background: #831843; color: #fbcfe8; }
.badge-success { background: #065f46; color: #6ee7b7; }
.badge-danger { background: #7f1d1d; color: #fca5a5; }

.badge-pill {
  border-radius: var(--radius-full);
  background: #475569;
  color: #fff;
}

.alert {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}
.alert-danger {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.text-uppercase { text-transform: uppercase; }
.text-muted { color: var(--text-muted); }
.text-primary { color: #38bdf8; }
.text-success { color: #34d399; }
.text-info { color: #38bdf8; }
.text-warning { color: #fbbf24; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.hidden { display: none !important; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.small { font-size: 0.8rem; }

/* Responsive adjustments */
@media (max-width: 768px) {
  .lobby-grid {
    grid-template-columns: 1fr;
  }
  .divider-vertical {
    justify-content: center;
    margin: 0.5rem 0;
  }
  .result-grid {
    grid-template-columns: 1fr;
  }
  .transfer-action-buttons {
    flex-direction: column;
    align-items: stretch;
  }
  .benchmark-btn-group {
    flex-direction: column;
    align-items: stretch;
  }
}
