:root {
  color-scheme: dark;
  --background: #0f1419;
  --panel: #1a2029;
  --subtle: #232b36;
  --border: #2a3340;
  --text: #e6edf3;
  --muted: #a5b0bd;
  --accent: #5b9dff;
  --accent-hover: #7eb3ff;
  --accent-text: #0f1419;
  --danger: #ff9292;
  --danger-solid: #b42639;
}

:root[data-theme="light"] {
  color-scheme: light;
  --background: #f5f7fa;
  --panel: #fff;
  --subtle: #eef2f7;
  --border: #d8dfe7;
  --text: #1a2029;
  --muted: #5b6877;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-text: #fff;
  --danger: #b42639;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font: 1rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

button, input, select, textarea { font: inherit; }
button {
  min-height: 2.5rem;
  padding: .45rem .8rem;
  border: 1px solid transparent;
  border-radius: .45rem;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}

button:hover { background: var(--accent-hover); }
button:disabled { opacity: .6; cursor: default; }
.secondary { background: var(--panel); border-color: var(--border); color: var(--text); }
.secondary:hover { background: var(--subtle); }
.danger-text { color: var(--danger); }
.danger { background: var(--danger-solid); color: #fff; }
.danger:hover { background: #951c2c; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem 1.5rem;
  padding: .85rem clamp(1rem, 3vw, 2rem);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand, .actions { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
.brand { gap: .7rem; font-weight: 700; }
.brand-section {
  border-left: 1px solid var(--border);
  color: var(--muted);
  padding-left: .7rem;
  font-size: .9rem;
  font-weight: 500;
}

.startup { margin: 2rem auto; padding: 0 1rem; text-align: center; }
.login-panel {
  width: min(28rem, calc(100% - 2rem));
  margin: clamp(2rem, 10vh, 7rem) auto 2rem;
  padding: clamp(1rem, 5vw, 2rem);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: .65rem;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.4rem, 3vw, 1.8rem); line-height: 1.25; }
h2 { font-size: 1.25rem; line-height: 1.3; }
.login-panel form, #editor-fields { display: grid; gap: 1rem; margin-top: 1.25rem; }
label { display: grid; gap: .3rem; font-size: .9rem; font-weight: 600; }
input, select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 2.65rem;
  padding: .5rem .65rem;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: .4rem;
  color: var(--text);
  font-size: 1rem;
}
textarea { resize: vertical; }
.field-hint { font-weight: 400; }
.muted { color: var(--muted); }
.error { color: var(--danger); overflow-wrap: anywhere; }
.section-header p, .dialog-body > p { margin-top: .5rem; }

.workspace { display: grid; grid-template-columns: 14rem minmax(0, 1fr); min-height: calc(100dvh - 4.3rem); }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 1.25rem .75rem; }
.sidebar nav { display: grid; gap: .3rem; }
.sidebar button {
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-weight: 500;
}
.sidebar button:hover { color: var(--text); background: var(--subtle); }
.sidebar button[aria-current="page"] { color: var(--accent); background: var(--subtle); }
.content { max-width: 100rem; width: 100%; padding: 1.75rem clamp(1rem, 3vw, 2rem); }
.section-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; margin-bottom: 1.25rem; }
#status, #list-error { margin: .85rem 0; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: .55rem; }
table { width: 100%; border-collapse: collapse; background: var(--panel); text-align: left; }
th, td { padding: .75rem .85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--subtle); font-size: .9rem; white-space: nowrap; }
td { max-width: 24rem; font-size: .9rem; overflow-wrap: anywhere; }
tr:last-child td { border-bottom: 0; }
td:last-child { width: 1%; }
td .actions { flex-wrap: nowrap; white-space: nowrap; }
td .actions button { font-size: .875rem; }
.empty { padding: 1rem; border: 1px solid var(--border); border-radius: .55rem; color: var(--muted); }
.theme-form { display: grid; justify-items: start; gap: .85rem; max-width: 24rem; }
.theme-form label { width: 100%; }

dialog {
  width: min(35rem, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: .65rem;
}
dialog::backdrop { background: rgb(0 0 0 / 60%); }
.dialog-body { padding: 1.25rem; }
.dialog-actions { justify-content: flex-end; padding: .85rem 1.25rem; border-top: 1px solid var(--border); }
#editor-fields:empty { display: none; }

@media (max-width: 48rem) {
  .topbar { flex-wrap: wrap; }
  .workspace { grid-template-columns: minmax(0, 1fr); min-height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); padding: .55rem 1rem; }
  .sidebar nav { display: flex; overflow: auto; padding: .25rem; }
  .sidebar button { white-space: nowrap; }
  .content { padding-top: 1.25rem; }
}
