/* ============================================================
   Proxy API Manager — DSM-style UI
   ============================================================ */

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

:root {
  --sidebar-bg:       #1c2331;
  --sidebar-text:     #9bacc2;
  --sidebar-hover:    #253044;
  --sidebar-active:   #0088cc;
  --sidebar-width:    220px;

  --topbar-bg:        #ffffff;
  --topbar-border:    #e0e4ea;
  --topbar-height:    52px;

  --body-bg:          #f0f2f5;
  --card-bg:          #ffffff;
  --card-shadow:      0 1px 4px rgba(0,0,0,0.10);
  --card-radius:      8px;

  --text-primary:     #1a1f2e;
  --text-secondary:   #6b7280;
  --text-muted:       #9ca3af;

  --border:           #e5e7eb;
  --input-border:     #d1d5db;
  --input-focus:      #0088cc;

  --blue:             #0088cc;
  --blue-hover:       #006fa8;
  --blue-light:       #e6f3fa;

  --green:            #28a745;
  --green-light:      #d4edda;
  --red:              #dc3545;
  --red-light:        #f8d7da;
  --yellow:           #e6a817;
  --yellow-light:     #fff3cd;
  --gray:             #6c757d;
  --gray-light:       #e9ecef;

  --font:             -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono:        "SF Mono", "Fira Code", "Consolas", monospace;
  --radius:           6px;
  --transition:       0.15s ease;
}

body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--body-bg);
  height: 100vh;
  overflow: hidden;
}

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

.layout {
  display: flex;
  height: 100vh;
}

/* ============================================================
   Sidebar
   ============================================================ */

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.app-icon {
  width: 32px;
  height: 32px;
  background: var(--blue);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-icon svg {
  width: 18px;
  height: 18px;
  stroke: #fff;
}

.app-title {
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  line-height: 1.2;
}

.nav-list {
  list-style: none;
  padding: 10px 0;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  color: var(--sidebar-text);
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  font-size: 13px;
  font-weight: 500;
  user-select: none;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #ffffff;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #ffffff;
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

/* ============================================================
   Main area
   ============================================================ */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  flex-shrink: 0;
  gap: 16px;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

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

.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ============================================================
   Cards
   ============================================================ */

.card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 14px;
}

/* Summary stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.stat-card.green  .stat-value { color: var(--green); }
.stat-card.red    .stat-value { color: var(--red); }
.stat-card.yellow .stat-value { color: var(--yellow); }
.stat-card.blue   .stat-value { color: var(--blue); }

/* ============================================================
   Tables
   ============================================================ */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  background: var(--card-bg);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: #f7f9fc;
}

tbody td {
  padding: 10px 14px;
  color: var(--text-primary);
  vertical-align: middle;
}

.td-mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.td-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Disabled proxy rows */
tr.row-disabled td {
  opacity: 0.55;
}

tr.row-disabled:hover {
  background: #f5f6f8;
}

.row-disabled-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--gray-light);
  border-radius: 3px;
  padding: 1px 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
}

.empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 14px;
  font-style: italic;
}

/* ============================================================
   Status badges
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-running    { background: var(--green-light); color: #1a7a30; }
.badge-stopped    { background: var(--gray-light);  color: #495057; }
.badge-error      { background: var(--red-light);   color: #842029; }
.badge-restarting { background: var(--yellow-light); color: #856404; }
.badge-disabled   { background: var(--gray-light);  color: #6c757d; }

/* HTTP status colors */
.status-2xx { color: var(--green); font-weight: 600; }
.status-3xx { color: var(--blue);  font-weight: 600; }
.status-4xx { color: var(--yellow); font-weight: 600; }
.status-5xx { color: var(--red);   font-weight: 600; }

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background var(--transition), opacity var(--transition);
  white-space: nowrap;
  text-decoration: none;
  font-family: var(--font);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary   { background: var(--blue);    color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--blue-hover); }
.btn-success   { background: var(--green);   color: #fff; }
.btn-success:hover:not(:disabled)  { background: #218838; }
.btn-danger    { background: var(--red);     color: #fff; }
.btn-danger:hover:not(:disabled)   { background: #b02a37; }
.btn-warning   { background: var(--yellow);  color: #fff; }
.btn-warning:hover:not(:disabled)  { background: #c88c00; }
.btn-secondary { background: #e9ecef;        color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled){ background: #dee2e6; }
.btn-ghost     { background: transparent;    color: var(--blue); padding: 4px 8px; }
.btn-ghost:hover:not(:disabled)    { background: var(--blue-light); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px;  font-size: 11px; }

/* ============================================================
   Forms
   ============================================================ */

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

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

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-control {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  color: var(--text-primary);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(0,136,204,0.12);
}

.form-control.error {
  border-color: var(--red);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
  font-family: var(--font-mono);
  font-size: 12px;
}

select.form-control {
  cursor: pointer;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Toggle switch */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
}

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

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 22px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  left: 3px;
  top: 3px;
  transition: transform var(--transition);
}

.toggle input:checked + .toggle-slider { background: var(--blue); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ============================================================
   Code editor
   ============================================================ */

.editor-wrap {
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.editor-wrap:focus-within {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(0,136,204,0.12);
}

.CodeMirror {
  height: 400px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
}

/* ============================================================
   Filter bar
   ============================================================ */

.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  background: var(--card-bg);
  padding: 16px 20px;
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  margin-bottom: 20px;
}

.filter-bar .form-group {
  margin-bottom: 0;
  min-width: 140px;
}

.filter-bar .form-group.wide {
  min-width: 200px;
  flex: 1;
}

/* ============================================================
   Status worker cards
   ============================================================ */

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.status-card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: 18px 20px;
  border-left: 4px solid var(--gray);
}

.status-card.running    { border-left-color: var(--green); }
.status-card.stopped    { border-left-color: var(--gray); }
.status-card.error      { border-left-color: var(--red); }
.status-card.restarting { border-left-color: var(--yellow); }

.status-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.status-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.status-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.meta-value {
  font-size: 12px;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

/* ============================================================
   Modal
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  min-width: 360px;
  max-width: 480px;
  width: 100%;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}

.modal-close:hover { background: var(--gray-light); }

.modal-body {
  padding: 18px 20px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Toast notifications
   ============================================================ */

#toastContainer {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  animation: toastIn 0.2s ease;
  max-width: 320px;
}

.toast-success { background: var(--green); }
.toast-error   { background: var(--red); }
.toast-info    { background: var(--blue); }

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

/* ============================================================
   Loading / empty states
   ============================================================ */

.loading-spinner {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  font-size: 14px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state p {
  margin-bottom: 16px;
  font-size: 14px;
}

/* ============================================================
   Scrollbar
   ============================================================ */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c8d0dc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9bacc2; }

/* ============================================================
   Misc utilities
   ============================================================ */

.text-muted    { color: var(--text-muted); }
.text-mono     { font-family: var(--font-mono); font-size: 12px; }
.text-red      { color: var(--red); }
.text-green    { color: var(--green); }
.flex-gap      { display: flex; gap: 8px; align-items: center; }
.mb-0          { margin-bottom: 0; }
.mt-4          { margin-top: 4px; }
.mt-8          { margin-top: 8px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
