:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-subtle: #efece4;
  --border: #dcd6ca;
  --text: #191a1d;
  --text-muted: #585c66;
  --accent: #c43625;
  --accent-hover: #a62b1c;
  --accent-ink: #ffffff;
  --ok: #1f7a4c;
  --warn: #a66314;
  --danger: #b42318;
  --focus: #c43625;
  --radius-sm: 4px;
  --radius-md: 8px;
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #111214;
  --surface: #181a1f;
  --surface-subtle: #20232a;
  --border: #2c303a;
  --text: #eeece6;
  --text-muted: #9aa0ac;
  --accent: #e05240;
  --accent-hover: #f06554;
  --accent-ink: #ffffff;
  --ok: #3fb978;
  --warn: #e0a03a;
  --danger: #f06259;
  --focus: #e05240;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.015em;
}

h2 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1rem;
}

p {
  margin: 0;
}

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

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

.stack-xs { display: flex; flex-direction: column; gap: 6px; }
.stack-sm { display: flex; flex-direction: column; gap: 12px; }
.stack-md { display: flex; flex-direction: column; gap: 18px; }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* Seal & Brand */
.seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 18px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.seal-sm {
  width: 28px;
  height: 28px;
  font-size: 14px;
}

/* Login */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-name {
  font-size: 1.3rem;
}

.brand-sub {
  font-size: 13px;
  color: var(--text-muted);
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-inline {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-wordmark {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.health-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.is-ok { background: var(--ok); }
.status-dot.is-err { background: var(--danger); }

.nav-tabs {
  display: flex;
  align-items: stretch;
  gap: 4px;
  overflow-x: auto;
  max-width: 100%;
}

.nav-tab {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  padding: 18px 12px 16px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
}

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

.nav-tab.is-active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

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

/* Workspace */
.workspace {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Cards & Forms */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
}

.align-end {
  justify-content: flex-end;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
select,
textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-family: inherit;
  font-size: 13.5px;
  min-height: 40px;
}

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

.mono-input {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
}

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

.checkbox-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

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

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-subtle);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-subtle);
}

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

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #ffffff;
}

.btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12.5px;
}

.btn-full {
  width: 100%;
}

/* Playground */
.control-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.inline-field {
  min-width: 160px;
}

.split-editor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.editor-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 600;
  font-size: 13px;
}

.pane-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
}

.glossary-drawer summary {
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 4px 0;
}

.glossary-drawer textarea {
  margin-top: 8px;
}

/* Minecraft Preview */
.mc-preview-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mc-canvas {
  background: #14161a;
  color: #f0f0f0;
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.7;
  min-height: 76px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-x: auto;
}

.mc-line {
  white-space: pre-wrap;
  word-break: break-word;
}

.mc-icon-chip {
  display: inline-block;
  background: #2b313d;
  border: 1px solid #495264;
  color: #e2e8f0;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11.5px;
  vertical-align: middle;
  margin: 0 2px;
}

/* Dropzone */
.dropzone {
  border: 1px dashed var(--border);
  background: var(--surface-subtle);
  border-radius: var(--radius-md);
  padding: 24px;
  text-align: center;
  position: relative;
  cursor: pointer;
}

.dropzone.is-dragover {
  border-color: var(--accent);
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* Tables */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  background: var(--surface-subtle);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
}

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

.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 28px 14px !important;
}

.truncate {
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Status labels (functional only) */
.state-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
}

.state-ok { color: var(--ok); border-color: var(--ok); }
.state-warn { color: var(--warn); border-color: var(--warn); }
.state-err { color: var(--danger); border-color: var(--danger); }

.progress-bar {
  width: 110px;
  height: 7px;
  background: var(--surface-subtle);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
}

/* Providers */
.provider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.provider-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.provider-test-result {
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}

/* Metrics strip */
.metrics-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
  margin: 0;
}

.metric-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.metric-item dt {
  font-size: 12px;
  color: var(--text-muted);
}

.metric-item dd {
  margin: 6px 0 0;
  font-size: 1.45rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Modal */
.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  max-width: 560px;
  width: calc(100% - 32px);
  padding: 0;
}

.modal::backdrop {
  background: rgba(10, 12, 16, 0.55);
}

.modal-body {
  padding: 22px;
}

.secret-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  word-break: break-all;
}

.code-block {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0;
}

.form-error {
  color: var(--danger);
  font-size: 13px;
}

.form-note {
  color: var(--ok);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--text);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  z-index: 50;
}

@media (max-width: 820px) {
  .split-editor {
    grid-template-columns: 1fr;
  }

  .topbar-inner {
    padding: 8px 14px;
  }

  .nav-tab {
    padding: 12px 10px;
  }
}
