:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-text: #ffffff;
  --success: #34c759;
  --danger: #ff3b30;
  --warning: #ff9500;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.06), 0 1px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.1), 0 4px 12px rgba(0, 0, 0, 0.05);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

input,
select,
textarea,
button {
  font: inherit;
  color: inherit;
}

/* ---- Layout ---- */
.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.hidden {
  display: none !important;
}

/* ---- Card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 150ms ease;
}

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

/* ---- Buttons ---- */
button {
  border: 0;
  cursor: pointer;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 1px 2px rgba(0, 113, 227, 0.3);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 2px 6px rgba(0, 113, 227, 0.35);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-ghost:hover {
  background: rgba(0, 0, 0, 0.03);
}

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

.wide {
  width: 100%;
}

.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.04);
  border: 0;
  font-size: 18px;
  color: var(--text-secondary);
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text);
}

/* ---- Form fields ---- */
label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

label.field > input,
label.field > select,
label.field > textarea {
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

label.field > input:focus,
label.field > select:focus,
label.field > textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
}

label.checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* ---- Text styles ---- */
.muted {
  color: var(--text-secondary);
}

.caption {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 8px;
}

/* ---- Login ---- */
.login-card {
  max-width: 380px;
  margin: 10vh auto 0;
  padding: 40px 32px 32px;
  text-align: center;
}

.login-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #42a5f5);
  display: grid;
  place-items: center;
  font-size: 24px;
  margin: 0 auto 16px;
  box-shadow: 0 4px 12px rgba(0, 113, 227, 0.25);
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-card .muted {
  margin: 4px 0 0;
  font-size: 14px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}

.login-form input {
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.topbar-left h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.topbar-tagline {
  font-size: 13px;
  margin-top: 2px;
  display: block;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ---- Workspace ---- */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
}

.main-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: 2px;
  padding: 4px;
  flex-wrap: wrap;
}

.tab-button {
  position: relative;
  padding: 6px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  transition: color 150ms ease, background 150ms ease;
}

.tab-button:hover {
  background: rgba(0, 0, 0, 0.03);
  color: var(--text);
}

.tab-button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
}

.toolbar h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

/* ---- Provider list ---- */
.provider-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.provider-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 150ms ease, transform 150ms ease;
  cursor: grab;
}

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

.provider-card.dragging {
  opacity: 0.6;
  transform: rotate(1deg);
}

.provider-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

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

.priority {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(0, 113, 227, 0.08);
  color: var(--accent);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.provider-title h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.provider-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-secondary);
  border: 1px solid transparent;
}

.badge.on {
  background: rgba(52, 199, 89, 0.1);
  color: #0a7f2e;
  border-color: rgba(52, 199, 89, 0.15);
}

.badge.off {
  background: rgba(255, 59, 48, 0.08);
  color: #c41e14;
  border-color: rgba(255, 59, 48, 0.12);
}

.handle {
  color: var(--text-secondary);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  cursor: grab;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.03);
}

.config-preview {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f5f6f8;
  border: 1px solid var(--border);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--text-secondary);
}

.provider-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.provider-actions button {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 6px;
}

/* ---- Side cards ---- */
.side-card {
  padding: 16px;
}

.side-card h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
}

.service-status {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-radius: 8px;
  background: #f5f6f8;
  border: 1px solid var(--border);
  font-size: 13px;
}

.status-row strong {
  font-weight: 600;
  font-size: 12px;
}

.activity-log {
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  background: #f5f6f8;
  border: 1px solid var(--border);
  min-height: 80px;
  max-height: 200px;
  overflow: auto;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* ---- Modal sheet (macOS-style) ---- */
.modal-sheet {
  width: min(480px, calc(100vw - 40px));
  border: 0;
  border-radius: var(--radius-xl);
  padding: 0;
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-sheet::backdrop {
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(6px);
}

.modal-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-row:has(label.full) {
  grid-template-columns: 1fr;
}

.config-block {
  padding: 14px;
}

.config-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.config-head .muted {
  font-size: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

/* ---- Responsive ---- */
@media (max-width: 880px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-stack {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 600px) {
  .shell {
    padding: 12px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .provider-top {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .side-stack {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .toolbar-actions {
    justify-content: flex-end;
  }
}
