/* CPM - Caddy Proxy Manager - Classic Theme */
/* ========================================= */

:root {
  /* Colors */
  --primary: #00ADD8;
  --primary-dark: #007D9C;
  --primary-light: #5DD3F3;
  
  --success: #10B981;
  --warning: #F59E0B;
  --error: #EF4444;
  --info: #3B82F6;
  
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;
  
  --bg: var(--gray-50);
  --bg-card: #FFFFFF;
  --text: var(--gray-900);
  --text-muted: var(--gray-500);
  --border: var(--gray-200);
  
  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  
  /* Border radius */
  --radius-sm: 0.25rem;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: var(--gray-800);
  color: white;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  margin-bottom: var(--space-6);
}

.sidebar-logo img {
  width: 40px;
  height: 40px;
}

.sidebar-logo span {
  font-size: 1.25rem;
  font-weight: 700;
}

.sidebar-nav {
  flex: 1;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  color: var(--gray-300);
  border-radius: var(--radius);
  transition: all 0.2s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: var(--gray-700);
  color: white;
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--primary);
}

.sidebar-footer {
  padding-top: var(--space-4);
  border-top: 1px solid var(--gray-700);
}

.main-content {
  flex: 1;
  padding: var(--space-6);
  overflow-y: auto;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--space-6);
  margin-bottom: var(--space-4);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}

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

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

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

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-200);
}

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

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

.btn-sm {
  padding: var(--space-1) var(--space-2);
  font-size: 0.75rem;
}

.btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: 1rem;
}

/* Forms */
.form-group {
  margin-bottom: var(--space-5);
}

.form-label,
label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 600;
  color: var(--gray-700);
  font-size: 0.875rem;
}

.form-input,
.form-select,
.form-textarea,
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="url"],
input[type="tel"],
input[type="date"],
input[type="time"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-lg);
  background: white;
  transition: all 0.2s ease;
  color: var(--gray-800);
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover,
input[type="text"]:hover,
input[type="password"]:hover,
input[type="email"]:hover,
input[type="number"]:hover,
input[type="url"]:hover,
input[type="tel"]:hover,
input[type="date"]:hover,
input[type="time"]:hover,
input[type="search"]:hover,
select:hover,
textarea:hover {
  border-color: var(--gray-300);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus,
input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="url"]:focus,
input[type="tel"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(0, 173, 216, 0.15);
}

.form-input::placeholder,
input::placeholder,
textarea::placeholder {
  color: var(--gray-400);
}

.form-textarea,
textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}

/* Inline input with label */
.form-inline {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.form-inline label {
  margin-bottom: 0;
  white-space: nowrap;
}

.form-inline input,
.form-inline select {
  flex: 1;
}

/* Checkboxes and Radio buttons */
.form-checkbox,
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  user-select: none;
  font-weight: 400;
}

input[type="checkbox"],
input[type="radio"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

/* Custom styled checkbox */
.checkbox-custom {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  padding: 0.5rem 0;
}

.checkbox-custom input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.checkbox-custom .checkmark {
  width: 1.375rem;
  height: 1.375rem;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.checkbox-custom:hover .checkmark {
  border-color: var(--primary);
}

.checkbox-custom input:checked + .checkmark {
  background: var(--primary);
  border-color: var(--primary);
}

.checkbox-custom input:checked + .checkmark::after {
  content: "✓";
  color: white;
  font-size: 0.875rem;
  font-weight: bold;
}

.checkbox-custom input:focus + .checkmark {
  box-shadow: 0 0 0 3px rgba(0, 173, 216, 0.2);
}

/* Form sections */
.form-section {
  background: var(--gray-50);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  border: 1px solid var(--gray-100);
}

.form-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-800);
  margin: 0 0 var(--space-4) 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Form row - side by side inputs */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

/* Input with icon */
.input-group {
  position: relative;
}

.input-group input {
  padding-left: 2.75rem;
}

.input-group-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  pointer-events: none;
}

/* Input with prefix text */
.input-group {
  display: flex;
  align-items: center;
}

.input-prefix {
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-right: none;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius) 0 0 var(--radius);
  color: var(--gray-600);
  font-weight: 500;
}

.input-group .input-prefix + input {
  border-radius: 0 var(--radius) var(--radius) 0;
  flex: 1;
}

/* Form hint/help text */
.form-hint {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-top: var(--space-2);
  line-height: 1.4;
}

/* Snippet checkboxes - inline pills */
.snippet-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.snippet-option {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.5rem 1rem;
  background: white;
  border: 2px solid var(--gray-200);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.875rem;
}

.snippet-option:hover {
  border-color: var(--primary-light);
  background: var(--gray-50);
}

.snippet-option input {
  width: 1rem;
  height: 1rem;
}

.snippet-option input:checked + span {
  color: var(--primary);
  font-weight: 600;
}

.snippet-option:has(input:checked) {
  border-color: var(--primary);
  background: rgba(0, 173, 216, 0.08);
}

/* Details/Summary accordion */
details {
  background: var(--gray-50);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  border: 1px solid var(--gray-200);
}

details > summary {
  padding: var(--space-4);
  cursor: pointer;
  font-weight: 600;
  color: var(--gray-700);
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

details > summary::-webkit-details-marker {
  display: none;
}

details > summary::before {
  content: "▶";
  font-size: 0.75rem;
  transition: transform 0.2s;
}

details[open] > summary::before {
  transform: rotate(90deg);
}

details[open] > summary {
  border-bottom: 1px solid var(--gray-200);
}

details > div,
details > .details-content {
  padding: var(--space-4);
}

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
  gap: var(--space-4);
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gray-800);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Settings sections */
.settings-section {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow);
}

.settings-section h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-800);
  margin: 0 0 var(--space-4) 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.settings-section h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
  margin: 0 0 var(--space-3) 0;
}

/* Tabs navigation */
.tabs-nav {
  display: flex;
  gap: var(--space-1);
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: var(--space-5);
}

.tabs-nav .tab {
  padding: var(--space-3) var(--space-5);
  font-weight: 500;
  color: var(--gray-500);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.tabs-nav .tab:hover {
  color: var(--gray-700);
  background: var(--gray-50);
}

.tabs-nav .tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: transparent;
}

/* Code editor textarea */
.code-editor {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Fira Code', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  background: var(--gray-800);
  color: var(--gray-100);
  border: none;
  padding: var(--space-4);
}

.code-editor:focus {
  box-shadow: 0 0 0 4px rgba(0, 173, 216, 0.2);
}

/* Alerts */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  margin-bottom: var(--space-4);
}

.alert-success {
  background: #D1FAE5;
  color: #065F46;
  border: 1px solid #A7F3D0;
}

.alert-warning {
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #FDE68A;
}

.alert-error {
  background: #FEE2E2;
  color: #991B1B;
  border: 1px solid #FECACA;
}

.alert-info {
  background: #DBEAFE;
  color: #1E40AF;
  border: 1px solid #BFDBFE;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  font-weight: 600;
  color: var(--gray-600);
  background: var(--gray-50);
}

.table tr:hover {
  background: var(--gray-50);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
}

.badge-success {
  background: #D1FAE5;
  color: #065F46;
}

.badge-warning {
  background: #FEF3C7;
  color: #92400E;
}

.badge-error {
  background: #FEE2E2;
  color: #991B1B;
}

.badge-info {
  background: #DBEAFE;
  color: #1E40AF;
}

.badge-gray {
  background: var(--gray-100);
  color: var(--gray-600);
}

/* Tags */
.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  font-size: 0.75rem;
  background: var(--gray-100);
  color: var(--gray-700);
  border-radius: var(--radius-sm);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Site cards */
.site-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}

.site-card:hover {
  box-shadow: var(--shadow-md);
}

.site-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-3);
}

.site-card-domain {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

.site-card-target {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-family: monospace;
}

.site-card-badges {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.site-card-actions {
  display: flex;
  gap: var(--space-2);
}

/* Grid layouts */
.grid {
  display: grid;
  gap: var(--space-4);
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1024px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
  
}

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-4);
}

.tab {
  padding: var(--space-3) var(--space-4);
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}

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

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

.modal-body {
  padding: var(--space-4);
}

.modal-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* Loading */
.loading {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Code */
pre, code {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.875rem;
}

pre {
  background: var(--gray-800);
  color: var(--gray-100);
  padding: var(--space-4);
  border-radius: var(--radius);
  overflow-x: auto;
}

code {
  background: var(--gray-100);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}

/* Utilities */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error { color: var(--error); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }

.hidden { display: none; }

/* HTMX loading indicator */
.htmx-request .htmx-indicator {
  display: inline-flex;
}

.htmx-indicator {
  display: none;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--gray-300);
  transition: 0.3s;
  border-radius: 28px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--primary);
}

.toggle-switch input:focus + .toggle-slider {
  box-shadow: 0 0 0 3px rgba(0, 173, 216, 0.2);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(24px);
}

.toggle-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  cursor: pointer;
}

.toggle-label .toggle-text {
  font-weight: 500;
}

/* Snippet option improvements */
.snippet-option {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--gray-100);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
  user-select: none;
}

.snippet-option:hover {
  background: var(--gray-200);
}

.snippet-option input:checked + span {
  font-weight: 600;
}

.snippet-option:has(input:checked) {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.snippet-option input {
  accent-color: var(--primary);
}

/* Details/Summary improvements */
details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: var(--space-4);
}

details summary {
  padding: var(--space-4);
  cursor: pointer;
  font-weight: 600;
  background: var(--gray-50);
  border-radius: var(--radius);
  user-select: none;
}

details summary:hover {
  background: var(--gray-100);
}

details[open] summary {
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

details .details-content {
  padding: var(--space-4);
}

/* Form section styling */
.form-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-4);
}

.form-section-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

/* Badge styles */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius);
  background: var(--gray-200);
  color: var(--gray-700);
}

.badge-wildcard {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: white;
  font-size: 1rem;
  padding: 0.25rem;
  border-radius: 50%;
}

.snippet-badge-tls {
  background: linear-gradient(135deg, #10B981, #059669);
  color: white;
}

/* Site card improvements */
.site-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.site-card-badges {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
  margin-right: var(--space-2);
}

.site-card-actions {
  display: flex;
  gap: var(--space-2);
}

/* Code block in alerts */
.code-block {
  background: var(--gray-800);
  color: var(--gray-100);
  padding: var(--space-3);
  border-radius: var(--radius);
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: var(--space-2);
  max-height: 300px;
  overflow-y: auto;
}

details.mt-2 {
  margin-top: var(--space-2);
}

details.mt-2 summary {
  cursor: pointer;
  font-weight: 500;
  padding: var(--space-2);
  background: var(--gray-100);
  border-radius: var(--radius-sm);
}

/* Off-canvas navigation (below 768px the sidebar becomes a drawer opened
   from a slim top bar; previously it was simply hidden on phones) */
.mobile-topbar, .nav-backdrop { display: none; }
.nav-backdrop[hidden] { display: none !important; }

@media (max-width: 767px) {
  .main-content { padding: var(--space-4); }
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    position: sticky;
    top: 0;
    z-index: 40;
    padding: var(--space-2) var(--space-3);
    padding-top: calc(var(--space-2) + env(safe-area-inset-top, 0px));
    background: var(--gray-800);
    color: white;
  }
  .mobile-topbar-logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
  }
  .mobile-topbar-logo:hover { text-decoration: none; }
  .mobile-topbar-logo img { width: 30px; height: 30px; }

  .nav-toggle {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--gray-600);
    border-radius: var(--radius);
    background: transparent;
    color: white;
    cursor: pointer;
  }
  .nav-toggle:focus-visible { outline: 2px solid var(--primary-light); outline-offset: 2px; }
  .nav-toggle-icon, .nav-toggle-icon::before, .nav-toggle-icon::after {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    transition: transform 0.2s;
  }
  .nav-toggle-icon { position: relative; }
  .nav-toggle-icon::before, .nav-toggle-icon::after { content: ""; position: absolute; left: 0; }
  .nav-toggle-icon::before { top: -6px; }
  .nav-toggle-icon::after { top: 6px; }
  .nav-open .nav-toggle-icon { background: transparent; }
  .nav-open .nav-toggle-icon::before { transform: translateY(6px) rotate(45deg); }
  .nav-open .nav-toggle-icon::after { transform: translateY(-6px) rotate(-45deg); }

  .app-container { display: block; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 60;
    width: min(270px, 85vw);
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    padding-top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
  }
  .nav-open .sidebar { transform: none; visibility: visible; transition: transform 0.22s ease; }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgb(0 0 0 / 0.4);
  }
  .nav-open { overflow: hidden; }
}

/* Settings tabs scroll sideways instead of being clipped */
@media (max-width: 1023px) {
  .tabs-nav { overflow-x: auto; }
  .tabs-nav .tab { white-space: nowrap; flex: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .nav-toggle-icon, .nav-toggle-icon::before, .nav-toggle-icon::after { transition: none !important; }
}

/* Settings: list–detail on phones */
.settings-index, .settings-detail-header { display: none; }
@media (max-width: 767px) {
  .tabs-container > .tabs-nav { display: none; }
  .settings-is-index > .tab-content { display: none; }
  .settings-index {
    display: flex;
    flex-direction: column;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }
  .settings-index-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    min-height: 56px;
    color: var(--gray-800);
    text-decoration: none;
    border-bottom: 1px solid var(--gray-200);
  }
  .settings-index-item:last-child { border-bottom: none; }
  .settings-index-item:active, .settings-index-item:hover { background: var(--gray-50); text-decoration: none; }
  .settings-index-icon { font-size: 1.25rem; flex: none; width: 1.6em; text-align: center; }
  .settings-index-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
  .settings-index-title { font-weight: 600; }
  .settings-index-desc { color: var(--gray-500); font-size: 0.85rem; margin-top: 2px; }
  .settings-index-chevron { color: var(--gray-400); font-size: 1.4rem; flex: none; }
  .settings-detail .settings-page-title { display: none; }
  .settings-detail-header { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
  .settings-detail-header h1 { margin: 0; min-width: 0; overflow-wrap: anywhere; }
  .settings-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    background: white;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    color: var(--gray-700);
    font-size: 1.7rem;
    line-height: 1;
    text-decoration: none;
  }
  .settings-back span { margin-top: -3px; }
  .settings-back:hover, .settings-back:active { background: var(--gray-50); color: var(--primary); text-decoration: none; }
  .settings-back:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
  .table-container { overflow-x: auto; }
  input[type="file"] { max-width: 100%; }
}

/* Settings → Modules */
.module-card h2 { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.module-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
/* The second .badge rule above overrides the colour variants; restore them. */
.badge.badge-success { background: #D1FAE5; color: #065F46; }
.badge.badge-warning { background: #FEF3C7; color: #92400E; }
.badge.badge-error { background: #FEE2E2; color: #991B1B; }
.badge.badge-info { background: #DBEAFE; color: #1E40AF; }

/* Rule notes (#16) */
.site-card-note {
    color: #555;
    margin: 6px 0;
    font-size: .85rem;
    white-space: pre-line;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.site-note { white-space: pre-line; overflow-wrap: anywhere; }
.badge-note { cursor: help; }
