:root {
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  
  --success: #10b981;
  --success-light: #ecfdf5;
  --success-text: #065f46;
  
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  
  --danger: #ef4444;
  --danger-light: #fef2f2;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ================= AUTH SCREEN ================= */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 20%, #e0e7ff 0%, #f8fafc 60%);
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.auth-header {
  text-align: center;
  margin-bottom: 28px;
}

.brand-badge {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.brand-badge.small {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  margin-bottom: 0;
}

.auth-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.auth-footer {
  margin-top: 24px;
  text-align: center;
}

.badge-lock {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-main);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

/* ================= DASHBOARD LAYOUT ================= */
.dashboard-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

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

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

.logo-text {
  font-size: 17px;
  color: var(--text-main);
}

.logo-text strong {
  color: var(--primary);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--success-text);
  background: var(--success-light);
  padding: 3px 10px;
  border-radius: 20px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background-color: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.7; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.7; }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 12px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.user-pill {
  font-size: 13px;
  font-weight: 600;
  background: var(--bg-hover);
  padding: 6px 12px;
  border-radius: 20px;
  color: var(--text-main);
}

.main-container {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ================= KPI STATS ================= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bg-blue { background: #eff6ff; color: #2563eb; }
.bg-green { background: #ecfdf5; color: #10b981; }
.bg-purple { background: #f5f3ff; color: #7c3aed; }
.bg-amber { background: #fffbeb; color: #d97706; }

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ================= SECTIONS & CARDS ================= */
.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
}

.section-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ================= CHANNELS LIST ================= */
.channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
}

.channel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.channel-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-md);
}

.channel-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.channel-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}

.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-badge.active {
  background: var(--success-light);
  color: var(--success-text);
}

.channel-metrics-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
}

.channel-metric-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 3px;
  padding: 0 4px;
}

.channel-metric-item:not(:last-child) {
  border-right: 1px solid var(--border);
}

.channel-metric-item .metric-num {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.channel-metric-item.highlight .metric-num {
  color: #059669;
}

.channel-metric-item .metric-svg-shield {
  width: 14px;
  height: 14px;
  color: #10b981;
  stroke: #10b981;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.channel-metric-item .metric-time {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
}

.channel-metric-item .metric-lbl {
  font-size: 9.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
  white-space: nowrap;
}

.url-box {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.url-text {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.fields-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
}

.tags-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 5px;
  margin-top: 3px;
}

.tag-badge {
  font-size: 9.5px;
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-hover);
  color: var(--text-main);
  padding: 1.5px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  line-height: 1.3;
}

.tag-badge.accent {
  background: var(--primary-light);
  color: var(--primary);
  border-color: #bfdbfe;
  font-weight: 500;
}

.channel-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ================= EMPTY STATE ================= */
.empty-state {
  text-align: center;
  padding: 48px 20px;
}

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

.empty-state h4 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 400px;
  margin: 0 auto 20px;
}

/* ================= BUTTONS & INPUTS ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  outline: none;
}

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

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

.btn-outline {
  background: white;
  border-color: var(--border);
  color: var(--text-main);
}

.btn-outline:hover {
  background: var(--bg-hover);
  border-color: #cbd5e1;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

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

.btn-block {
  width: 100%;
}

.btn-danger {
  color: var(--danger);
  border-color: #fecaca;
}

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

.form-group {
  margin-bottom: 18px;
}

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

.form-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.help-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

input[type="text"],
input[type="password"],
select {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--text-main);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* ================= SECURITY POLICY CARD ================= */
.security-card {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.06) 0%, rgba(59, 130, 246, 0.06) 100%);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.security-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.security-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #10b981;
  flex-shrink: 0;
}

.security-card-icon svg {
  stroke: #10b981;
}

.security-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.security-card-title strong {
  font-size: 13.5px;
  color: var(--text-main);
}

.security-badge-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
}

.security-card-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.4;
}

.security-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
}

.badge-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.05);
  color: var(--text-main);
  border: 1px solid rgba(15, 23, 42, 0.08);
  line-height: 1.3;
}

/* ================= WEBHOOKS LIST IN MODAL ================= */
.webhooks-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.webhook-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.webhook-input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.webhook-lock-icon {
  position: absolute;
  left: 10px;
  font-size: 13px;
  pointer-events: none;
  z-index: 1;
}

.webhook-input-wrapper .webhook-url-input {
  width: 100%;
  padding-left: 32px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  letter-spacing: 0.2px;
}

.webhook-input-wrapper .webhook-url-input.is-masked {
  background: #f8fafc;
  color: #475569;
}

/* ================= TAGS INPUT ================= */
.tags-input-wrapper {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  min-height: 44px;
}

.tags-input-wrapper:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-chip {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag-chip button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

.tag-chip button:hover {
  color: var(--danger);
}

.tags-input-wrapper input {
  border: none;
  outline: none;
  box-shadow: none;
  padding: 4px;
  flex: 1;
  min-width: 120px;
}

/* ================= MODAL ================= */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-card {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.modal-card.modal-lg {
  max-width: 1000px;
}

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

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-main);
}

.modal-card form {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

/* ================= API TESTER ================= */
.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.col-4 { flex: 4; }
.col-6 { flex: 6; }
.col-2 { flex: 2; }
.flex-end { align-self: flex-end; }

.quick-methods {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
}

.form-select {
  width: 100%;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  padding: 10px 38px 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: white;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
  color: var(--text-main);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.form-select:hover {
  border-color: #cbd5e1;
  background-color: #fcfdfe;
}

.form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.btn-chip {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-chip:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

.btn-chip.chip-accent {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
  font-weight: 600;
}

.btn-chip.chip-accent:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

.diff-viewer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.diff-pane {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.diff-header {
  background: var(--bg-main);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status-tag {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
  background: #e2e8f0;
  color: var(--text-muted);
}

.status-tag.tag-success {
  background: var(--success-light);
  color: var(--success-text);
}

.code-block {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.6;
  padding: 14px;
  background: #fafafa;
  max-height: 380px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ================= TABLE ================= */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.data-table th {
  background: var(--bg-main);
  padding: 10px 14px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

/* ================= TOAST ================= */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  pointer-events: none;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}
