:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-soft: #e8efff;
  --success: #15803d;
  --success-soft: #e7f6ec;
  --warning: #b45309;
  --warning-soft: #fdf3e2;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --neutral-soft: #eef1f5;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111a2e;
    --surface-2: #0f1729;
    --border: #1f2a40;
    --text: #e2e8f0;
    --muted: #8b9ab3;
    --primary: #5b8cff;
    --primary-soft: #1a2a50;
    --success: #4ade80;
    --success-soft: #12301f;
    --warning: #fbbf24;
    --warning-soft: #33270f;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --neutral-soft: #1b2438;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
  color: var(--primary);
}

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

/* Layout */

.layout {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  padding: 0 8px 18px;
}

.brand img {
  width: 28px;
  height: 28px;
}

.brand small {
  display: block;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 8px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.main {
  padding: 28px 32px 48px;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
  font-size: 22px;
}

.page-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

/* Components */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card h2,
.card h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.stats {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  margin-bottom: 16px;
}

.grid.cards {
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
}

.stat .label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat .value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 4px;
}

.stat .hint {
  color: var(--muted);
  font-size: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-2);
}

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

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

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

.btn.danger.solid {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn.small {
  padding: 4px 9px;
  font-size: 13px;
}

.btn.ghost {
  border-color: transparent;
  background: none;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--neutral-soft);
  color: var(--muted);
}

.badge.primary {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge.ativo {
  background: var(--success-soft);
  color: var(--success);
}

.badge.ocioso {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge.inativo,
.badge.erro {
  background: var(--danger-soft);
  color: var(--danger);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  background: var(--surface-2);
}

.chip .dot.ativo {
  color: var(--success);
}

.chip .dot.ocioso {
  color: var(--warning);
}

.chip .dot.inativo {
  color: var(--danger);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12.5px;
}

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

.row.between {
  justify-content: space-between;
}

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

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 14px 0 6px;
  font-weight: 600;
}

.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}

.error-text {
  color: var(--danger);
}

.remote-card header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.remote-card .name {
  font-weight: 700;
  font-size: 16px;
  word-break: break-all;
}

.remote-card footer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.quota {
  margin: 6px 0 2px;
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--neutral-soft);
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
}

.bar.warn > span {
  background: var(--warning);
}

.bar.full > span {
  background: var(--danger);
}

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 2px 12px;
  font-size: 12.5px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  word-break: break-all;
}

.spark {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 34px;
}

.spark span {
  flex: 1;
  background: var(--primary);
  opacity: 0.8;
  border-radius: 2px 2px 0 0;
  min-height: 2px;
}

.spark span.zero {
  background: var(--neutral-soft);
  opacity: 1;
}

/* Tables */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: var(--surface-2);
}

td.actions-cell {
  text-align: right;
  white-space: nowrap;
}

.file-name {
  display: flex;
  align-items: center;
  gap: 8px;
  word-break: break-all;
}

.file-name button {
  border: 0;
  background: none;
  padding: 0;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  text-align: left;
}

.file-name button:hover {
  color: var(--primary);
}

.file-name svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--muted);
}

.file-name svg.folder {
  color: var(--primary);
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  font-size: 13px;
}

.breadcrumb button {
  border: 0;
  background: none;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 6px;
  color: var(--primary);
}

.breadcrumb button:hover {
  background: var(--primary-soft);
}

.breadcrumb span.sep {
  color: var(--muted);
}

/* Forms */

label.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-weight: 600;
  font-size: 13px;
}

label.field .help {
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
  white-space: pre-line;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

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

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.provider-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  align-items: start;
  max-height: 52vh;
  overflow-y: auto;
  padding: 2px;
}

.provider-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
}

.provider-item:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.provider-item strong {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.provider-item span {
  font-size: 12px;
  color: var(--muted);
}

.steps {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.callout {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px 14px;
}

.callout.success {
  background: var(--success-soft);
  border-color: transparent;
}

.callout.warning {
  background: var(--warning-soft);
  border-color: transparent;
}

.secret-box {
  display: flex;
  gap: 6px;
  align-items: center;
}

.secret-box code {
  flex: 1;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  word-break: break-all;
}

pre.snippet {
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow-x: auto;
}

/* Modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px;
  z-index: 50;
  overflow-y: auto;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  border: 1px solid var(--border);
}

.modal.wide {
  max-width: 760px;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 17px;
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

/* Toasts */

#toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
}

.toast {
  background: var(--text);
  color: var(--surface);
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-width: 380px;
  font-size: 13px;
}

.toast.error {
  background: var(--danger);
  color: #fff;
}

/* Login */

.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login .card {
  width: 100%;
  max-width: 360px;
  padding: 28px;
}

.login .brand {
  justify-content: center;
  padding-bottom: 22px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  padding: 24px 4px;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
  }

  .brand {
    width: 100%;
    padding-bottom: 8px;
  }

  .sidebar-footer {
    width: 100%;
    margin-top: 8px;
  }

  .main {
    padding: 20px 16px 40px;
  }

  .grid.cards {
    grid-template-columns: 1fr;
  }
}
