﻿:root,
[data-theme="light"] {
  --primary: #4f84e2;
  --primary-hover: rgba(79, 132, 226, 0.8);
  --row-hover: #4f84e20f;
  --row-selected: #4f84e21f;
  --page-bg: #f7f8fa;
  --paper: #ffffff;
  --tinted: #f7f8fa;
  --text: #080808;
  --text-secondary: #858585;
  --divider: #e0e0e0;
  --success: #64d9a9;
  --warning: #ffc72e;
  --warning-bg: #fff8e1;
  --error: #f7443c;
  --error-bg: rgba(247, 68, 60, 0.1);
  --overlay: rgba(8, 8, 8, 0.25);
  --shadow: 0 0 8px #0000001a;
  --sidebar-bg: #ffffff;
  --sidebar-border: #e0e0e0;
  --input-bg: #ffffff;
  --chip-bg: #eef3fb;
  --chip-text: #3a5fa8;
  --radius: 4px;
  --radius-panel: 6px;
  --font: "Source Sans 3", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --space: 20px;
}

[data-theme="dark"] {
  --page-bg: #1a1c1f;
  --paper: #232528;
  --tinted: #2c2e30;
  --text: #ffffff;
  --text-secondary: #858585;
  --divider: #35373a;
  --sidebar-bg: #2c2e30;
  --sidebar-border: #35373a;
  --input-bg: #232528;
  --chip-bg: #35373a;
  --chip-text: #c2d4f5;
  --warning-bg: rgba(255, 199, 46, 0.12);
  --error-bg: rgba(247, 68, 60, 0.15);
  --overlay: rgba(0, 0, 0, 0.55);
  --shadow: 0 0 12px #00000066;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  font-weight: 300;
  font-size: 15px;
  color: var(--text);
  background: var(--page-bg);
  line-height: 1.45;
}

.login-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--page-bg);
}
.login-card {
  width: min(420px, 100%);
  margin: 0;
  padding: 36px 40px;
}
.login-brand {
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 18px;
}
.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
}
.login-label {
  display: block;
  margin: 18px 0 8px;
  font-weight: 400;
}
.login-submit {
  width: 100%;
  margin-top: 18px;
}
.login-error {
  margin-top: 10px;
  color: var(--error);
  font-size: 13px;
}
.login-foot {
  display: flex;
  gap: 14px;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--divider);
}

button, input, select { font: inherit; }
a { color: var(--primary); text-decoration: none; }
.hidden { display: none !important; }

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 24px 0 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  font-weight: 700;
  font-size: 18px;
  padding: 0 20px 20px;
  color: var(--text);
}

.sidebar-section-label {
  padding: 8px 20px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 400;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.nav-item {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 300;
}
.nav-item:hover { background: var(--row-hover); }
.nav-item.active {
  color: var(--primary);
  background: var(--row-selected);
  font-weight: 600;
}
.nav-item[tabindex="-1"]:not(.active) { opacity: 0.55; pointer-events: none; }

.sidebar-foot {
  margin-top: auto;
  padding: 16px 20px;
  display: flex;
  gap: 12px;
  border-top: 1px solid var(--divider);
}
.linkish {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  font-size: 13px;
}
.linkish:hover { color: var(--primary); }

.main {
  padding: 28px 36px 40px;
  max-width: none;
  width: 100%;
  min-width: 0;
}

.page-header { margin-bottom: 24px; }
.page-header h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-weight: 300;
  font-size: 15px;
}

.paper {
  background: var(--paper);
  border-radius: var(--radius-panel);
  padding: 24px 28px;
  margin-bottom: 20px;
}

.section-head h2 {
  margin: 0 0 18px;
  font-size: 17px;
  font-weight: 700;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(180px, 28%) minmax(220px, 1fr) minmax(160px, 220px);
  gap: 16px 24px;
  align-items: start;
  padding: 14px 0;
  border-bottom: 1px solid var(--divider);
}
.form-row:last-child { border-bottom: none; }
.form-row.compact {
  grid-template-columns: 1fr auto;
  border-bottom: none;
  padding: 10px 0;
}
.form-row.token-row {
  grid-template-columns: minmax(180px, 28%) minmax(280px, 1fr);
}
.form-row.token-row .form-help {
  grid-column: 2;
  padding-top: 0;
}
.form-label { font-weight: 400; padding-top: 6px; }
.form-help {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 300;
  padding-top: 6px;
}
.form-control { min-width: 0; }

.input {
  height: 35px;
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--input-bg);
  color: var(--text);
  width: 100%;
  outline: none;
}
.input:focus { border-color: var(--primary); }
.input.readonly { color: var(--text); background: var(--tinted); }
.input.select { width: auto; min-width: 140px; }
.input.search { max-width: 280px; }

.url-row { display: flex; gap: 10px; align-items: center; }

.btn {
  height: 35px;
  min-width: 120px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  background: transparent;
  color: var(--text);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  color: #fff;
  min-width: 160px;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-outline {
  border-color: var(--divider);
  background: var(--paper);
  min-width: 0;
}
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-danger { color: var(--error); border-color: var(--error); background: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--error-bg); }
.btn-text {
  border: none;
  background: none;
  color: var(--primary);
  min-width: 0;
  height: auto;
  padding: 4px 8px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: #cfcfcf;
  border-radius: 22px;
  cursor: pointer;
  transition: 0.15s;
}
.slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.15s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.status-strip {
  margin-top: 18px;
  background: var(--tinted);
  border-radius: var(--radius-panel);
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  font-size: 14px;
}
.status-strip .label { color: var(--text-secondary); margin-right: 6px; }
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius);
}
.badge.active { color: #1f7a57; background: rgba(100, 217, 169, 0.25); }
.badge.inactive { color: var(--text-secondary); background: rgba(133, 133, 133, 0.15); }
.badge.error { color: var(--error); background: var(--error-bg); }
.badge.warning { color: #9a7400; background: var(--warning-bg); }

.token-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.token-masked {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}
.token-reveal {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}
.token-warning {
  background: var(--error-bg);
  color: var(--error);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 400;
}
.token-field-row { display: flex; gap: 10px; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 28px;
  align-items: start;
  width: 100%;
}

.content-main {
  min-width: 0;
}

.tab-panel,
.connection.paper {
  width: 100%;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 0;
  background: transparent;
}
.tab {
  border: none;
  background: none;
  padding: 12px 16px;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 400;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary);
  font-weight: 600;
  border-bottom-color: var(--primary);
}

.tab-panel {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  margin-top: 0;
}

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  align-items: center;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--divider);
  background: var(--tinted);
}
table.data td {
  padding: 12px;
  border-bottom: 1px solid var(--divider);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: var(--row-hover); }
table.data .mono {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-secondary);
  word-break: break-all;
}

.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--text-secondary);
  font-weight: 300;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: var(--radius);
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: 12px;
  font-weight: 600;
}
.chip-add {
  width: 24px;
  height: 24px;
  border-radius: var(--radius);
  border: 1px dashed var(--divider);
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  padding: 0;
}
.chip-add:hover { border-color: var(--primary); background: var(--row-hover); }

.aside-card {
  background: var(--paper);
  border-radius: var(--radius-panel);
  padding: 16px;
  margin-bottom: 14px;
}
.aside-card.tinted { background: var(--tinted); }
.aside-card h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
}
.how-list {
  margin: 0;
  padding-left: 18px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 300;
}
.how-list li { margin-bottom: 8px; }
.stat-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 6px;
}
.stat-line span:last-child { font-weight: 600; }
.demo-note {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 300;
}

.grid-title {
  margin: 8px 0 14px;
  font-size: 16px;
  font-weight: 700;
}

.sync-settings {
  border-bottom: 1px solid var(--divider);
  margin-bottom: 16px;
  padding-bottom: 8px;
}

.banner {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--warning-bg);
  color: #7a5c00;
  font-size: 14px;
}
.banner.error { background: var(--error-bg); color: var(--error); }

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay);
}
.modal {
  position: relative;
  width: min(520px, 100%);
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 44px 28px;
}
.modal h2 {
  margin: 0 0 16px;
  font-size: 28px;
  font-weight: 700;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 28px;
}
.check-list {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--divider);
  border-radius: var(--radius);
}
.check-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--divider);
}
.check-item:last-child { border-bottom: none; }
.check-item:hover { background: var(--row-hover); }

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; border-right: none; border-bottom: 1px solid var(--sidebar-border); }
  .content-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; gap: 8px; }
  .form-help { order: 3; }
}
