/* Modern Sleek SaaS Layout (Inspired by HTTPSOK) */

:root,
[data-theme="dark"] {
  --bg-main: #0B0F17;
  --bg-sidebar: #0E131F;
  --bg-panel: #111827;
  --bg-panel-hover: #162033;
  --bg-input: #172033;
  --bg-terminal: #070A10;

  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #3B82F6;

  --text-main: #F3F4F6;
  --text-heading: #FFFFFF;
  --text-muted: #9CA3AF;
  --text-sub: #6B7280;

  --bg-pill: rgba(255, 255, 255, 0.06);
  --badge-neutral-bg: rgba(255, 255, 255, 0.07);

  --primary: #3B82F6;
  --primary-hover: #2563EB;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --accent: #8B5CF6;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-panel: 0 4px 20px -2px rgba(0, 0, 0, 0.5);
  --shadow-modal: 0 20px 40px -5px rgba(0, 0, 0, 0.8);
  --modal-overlay-bg: rgba(0, 0, 0, 0.75);
}

[data-theme="light"] {
  --bg-main: #F8FAFC;
  --bg-sidebar: #FFFFFF;
  --bg-panel: #FFFFFF;
  --bg-panel-hover: #F1F5F9;
  --bg-input: #F8FAFC;
  --bg-terminal: #0B1120;

  --border-color: rgba(0, 0, 0, 0.08);
  --border-focus: #2563EB;

  --text-main: #1E293B;
  --text-heading: #0F172A;
  --text-muted: #64748B;
  --text-sub: #94A3B8;

  --bg-pill: rgba(0, 0, 0, 0.05);
  --badge-neutral-bg: rgba(0, 0, 0, 0.06);

  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --success: #059669;
  --warning: #D97706;
  --danger: #DC2626;
  --accent: #7C3AED;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-panel: 0 4px 16px -2px rgba(0, 0, 0, 0.06);
  --shadow-modal: 0 20px 40px -5px rgba(0, 0, 0, 0.16);
  --modal-overlay-bg: rgba(15, 23, 42, 0.45);
}

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

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

.font-mono {
  font-family: 'JetBrains Mono', monospace;
}

/* App Wrapper: Sidebar + Main */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
  width: 250px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 24px 16px;
  transition: background-color 0.2s;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 24px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 20px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #1E40AF 0%, #3B82F6 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 0 14px rgba(59, 130, 246, 0.35);
}

.brand-info .brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-heading);
  letter-spacing: -0.02em;
}

.brand-info .brand-tag {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Sidebar Navigation */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease-in-out;
}

.nav-item:hover {
  background-color: var(--bg-panel-hover);
  color: var(--text-heading);
}

.nav-item.active {
  background-color: rgba(59, 130, 246, 0.12);
  color: var(--primary);
  font-weight: 600;
}

[data-theme="light"] .nav-item.active {
  background-color: #EFF6FF;
  color: #2563EB;
}

.nav-icon {
  stroke-width: 2;
  flex-shrink: 0;
}

/* Sidebar Footer */
.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

/* Main Area */
.app-main {
  flex: 1;
  min-width: 0;
  padding: 28px 36px 64px;
  overflow-y: auto;
}

.main-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.topbar-title-wrap h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-heading);
  letter-spacing: -0.02em;
}

/* Tab Switching */
.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
}

/* Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}

.metric-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  box-shadow: var(--shadow-panel);
  transition: transform 0.2s, border-color 0.2s;
}

.metric-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.16);
}

.metric-title {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.metric-value {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
  color: var(--text-heading);
}

.metric-footer {
  font-size: 0.72rem;
}

/* Guide Cards */
.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.guide-card {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.guide-step {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.guide-card h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 6px;
}

.guide-card p {
  line-height: 1.5;
  flex: 1;
}

/* Panels */
.panel-section {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-panel);
}

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

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

.panel-title-wrap h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-heading);
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover {
  background: var(--bg-panel-hover);
  border-color: rgba(255, 255, 255, 0.2);
}
[data-theme="light"] .btn-secondary:hover {
  border-color: rgba(0, 0, 0, 0.2);
}

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

.btn-block {
  width: 100%;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #F87171;
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1;
}

.badge-staging {
  background: rgba(245, 158, 11, 0.15);
  color: #FBBF24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34D399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}
[data-theme="light"] .badge-success { color: #059669; }

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #FBBF24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}
[data-theme="light"] .badge-warning { color: #D97706; }

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #F87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}
[data-theme="light"] .badge-danger { color: #DC2626; }

.badge-neutral {
  background: var(--badge-neutral-bg);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.badge-wildcard {
  background: rgba(139, 92, 246, 0.15);
  color: #A78BFA;
  border: 1px solid rgba(139, 92, 246, 0.3);
}
[data-theme="light"] .badge-wildcard { color: #7C3AED; }

.badge-provider {
  background: rgba(59, 130, 246, 0.12);
  color: #60A5FA;
  border: 1px solid rgba(59, 130, 246, 0.25);
  font-size: 0.72rem;
}
[data-theme="light"] .badge-provider { color: #2563EB; }

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

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

.data-table th {
  padding: 12px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-sub);
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 14px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.data-table tr:hover td {
  background-color: var(--bg-panel-hover);
}

.domain-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.domain-name-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.domain-main {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-heading);
}

.domain-sans {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.san-pill {
  font-size: 0.72rem;
  background: var(--bg-pill);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-muted);
}

.table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

/* Terminal / Log Viewer */
.terminal-container {
  background: var(--bg-terminal);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  height: 380px;
  overflow-y: auto;
  color: #D1D5DB;
}

.log-entry {
  display: flex;
  gap: 12px;
  margin-bottom: 6px;
  line-height: 1.4;
}

.log-time {
  color: var(--text-sub);
  white-space: nowrap;
}

.log-action {
  font-weight: 600;
  width: 140px;
  white-space: nowrap;
}

.log-action.issue { color: #60A5FA; }
.log-action.renew { color: #34D399; }
.log-action.deploy { color: #A78BFA; }
.log-action.rollback { color: #F87171; }
.log-action.create_dns_credential { color: #FBBF24; }

.log-status.success { color: #34D399; }
.log-status.failed { color: #F87171; }

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

.terminal-placeholder {
  color: var(--text-sub);
  text-align: center;
  padding: 60px 0;
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--modal-overlay-bg);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  animation: modalIn 0.2s ease-out;
}

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

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

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

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-heading);
}

.modal-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.modal-body {
  padding: 22px;
}

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

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

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

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.form-help {
  display: block;
  font-size: 0.72rem;
  color: var(--text-sub);
  margin-top: 4px;
}

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

.flex-1 { flex: 1; }

.checkbox-group {
  display: flex;
  align-items: center;
  padding-top: 22px;
}

.checkbox-label, .radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

.challenge-select-card, .issue-mode-card {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.code-block-wrapper {
  max-height: 380px;
  overflow-y: auto;
  border-radius: var(--radius-sm);
  background: var(--bg-terminal);
  border: 1px solid var(--border-color);
  padding: 14px;
}

.code-block {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  color: #A5B4FC;
  white-space: pre-wrap;
  word-break: break-all;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  font-size: 0.875rem;
  display: none;
  z-index: 2000;
  animation: toastIn 0.2s ease;
}

.toast.show { display: block; }
.toast.toast-success { border-color: var(--success); color: #34D399; }
.toast.toast-error { border-color: var(--danger); color: #F87171; }
.toast.toast-info { border-color: var(--primary); color: #60A5FA; }

@keyframes toastIn {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Theme toggle icons */
.theme-icon {
  display: inline-block;
  vertical-align: middle;
}

[data-theme="dark"] #theme-icon-sun { display: inline-block; }
[data-theme="dark"] #theme-icon-moon { display: none; }
[data-theme="light"] #theme-icon-sun { display: none; }
[data-theme="light"] #theme-icon-moon { display: inline-block; }

/* Helpers */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }
.text-muted { color: var(--text-muted); }
.text-white { color: var(--text-heading); }
.text-xs { font-size: 0.75rem; }
.py-6 { padding-top: 24px; padding-bottom: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mt-3 { margin-top: 12px; }
.mt-6 { margin-top: 24px; }
.font-medium { font-weight: 500; }

/* Welcome Banner */
.welcome-banner {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-panel);
}

.welcome-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-heading);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.welcome-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Scenario Cards (Competitor Plate Style) */
.scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.scenario-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px 22px 18px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.scenario-card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.12);
}

.scenario-card-header {
  position: relative;
  z-index: 1;
}

.scenario-card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 4px;
}

.scenario-card-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.scenario-card-graphic {
  position: absolute;
  top: 18px;
  right: 18px;
  opacity: 0.85;
  pointer-events: none;
}

.scenario-card-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Auto-Renew Server Agent Section */
.server-agent-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 16px;
  margin-bottom: 16px;
}

.server-agent-card {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 110px;
  transition: all 0.2s;
}

.server-agent-card:hover {
  border-color: var(--primary);
  background: var(--bg-tertiary);
}

.server-agent-icon {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.server-agent-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-heading);
}

/* Certificate Matrix & Copy Chip Styles (Competitor-style) */
.cert-matrix-table td {
  padding: 10px 14px;
  vertical-align: middle;
}

.btn-copy-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  color: var(--primary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-copy-chip:hover {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.btn-copy-chip:active {
  transform: translateY(0);
}

.link-download {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}

.link-download:hover {
  text-decoration: underline;
  color: var(--accent);
}

.cert-preview-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-secondary);
}

.cert-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
}

.cert-tab-nav {
  display: flex;
  gap: 6px;
}

.cert-tab-btn {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.cert-tab-btn:hover {
  color: var(--text-main);
}

.cert-tab-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
