:root {
  color-scheme: light;
  font-family: "Segoe UI", system-ui, sans-serif;
  line-height: 1.4;
  background: #f3f4f6;
  color: #111827;
}

* { box-sizing: border-box; }

body {
  margin: 0;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.side {
  background: #111827;
  color: #f9fafb;
  padding: 22px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: 0 10px;
}

h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.brand p, .muted {
  margin: 4px 0 0;
  color: #9ca3af;
  font-size: 13px;
}

.side-note {
  margin: auto 0 0;
  padding: 0 10px;
  color: #6b7280;
  font-size: 12px;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

button {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 12px;
  background: #e5e7eb;
  cursor: pointer;
}

nav .tab {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #d1d5db;
  border-color: transparent;
  border-radius: 8px;
  padding: 10px 12px;
}

nav .tab:hover {
  background: #1f2937;
  color: #fff;
}

nav .tab.active {
  background: #1e3a5f;
  color: #fff;
}

nav .tab.logout {
  margin-top: 12px;
  color: #fca5a5;
}

main {
  min-width: 0;
  padding: 24px 28px 48px;
}

body.gate {
  background:
    radial-gradient(ellipse at 50% 0%, #ffffff 0%, transparent 55%),
    #e7ebf0;
}

body.gate .side { display: none; }

body.gate .shell { grid-template-columns: 1fr; }

body.gate main {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-frame {
  width: min(380px, 100%);
  margin: 0;
  background: #fff;
  border: 1px solid #e6e8ec;
  border-radius: 18px;
  padding: 28px 26px 24px;
  box-shadow: 0 18px 50px rgba(17, 24, 39, 0.08);
}

.login-frame form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-frame label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
}

.login-frame input {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid #d5d8de;
  border-radius: 10px;
  background: #f8fafc;
}

.login-frame input:focus {
  outline: none;
  border-color: #2563eb;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.login-frame button.primary {
  width: 100%;
  margin-top: 4px;
  padding: 12px 14px;
  border-radius: 10px;
  font-weight: 600;
}

.login-frame button.primary:hover:not(:disabled) {
  background: #1e40af;
}

.login-frame .banner {
  margin: 0;
}

.panel {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
}

.toolbar, .row-actions, .form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.form-actions { margin-top: 10px; }

.toolbar {
  margin-bottom: 12px;
}

.grow { margin-left: auto; }

button.primary { background: #1d4ed8; color: #fff; }
button.danger { background: #b91c1c; color: #fff; }
button.ghost { background: #fff; border-color: #d1d5db; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

label.inline {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 14px;
}

select, input[type="text"], input[type="number"], input[type="email"], input[type="password"], textarea {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 7px 8px;
  background: #fff;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
}

th {
  background: #f9fafb;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #4b5563;
}

td.clip {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

td.stack {
  white-space: normal;
  min-width: 140px;
}

td.stack .meta { display: block; }

td.stack.clip-lines {
  max-width: 280px;
}

td.stack.clip-lines div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

td.actions, th.actions {
  position: sticky;
  right: 0;
  white-space: nowrap;
  background: #fff;
  z-index: 1;
}

th.actions {
  background: #f9fafb;
  z-index: 2;
}

tr.fresh td.actions { background: #fef3c7; }

tr.fresh, .task.fresh { animation: flash 1.6s ease; }

@keyframes flash {
  from { background: #fef3c7; }
  to { background: transparent; }
}

.banner {
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 14px;
}

.banner.ok { background: #ecfdf3; color: #166534; }
.banner.error { background: #fef2f2; color: #991b1b; }

.form-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 8px 12px;
  align-items: start;
  margin: 12px 0;
}

.form-grid textarea {
  width: 100%;
  min-height: 90px;
  resize: vertical;
}

.editor h2, .panel h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.meta {
  color: #6b7280;
  font-size: 13px;
}

.config-box {
  width: 100%;
  min-height: 480px;
  font-family: Consolas, ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.45;
}

.help {
  font-size: 14px;
  color: #374151;
}

.help code {
  font-family: Consolas, ui-monospace, monospace;
  font-size: 12px;
}

.history-item {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #e5e7eb;
  font-size: 14px;
  align-items: start;
}

.task {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid #e5e7eb;
}

.task .json { grid-column: 1 / -1; margin: 0; }

pre.json {
  margin: 6px 0 0;
  padding: 8px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-family: Consolas, ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-x: auto;
}

.empty {
  padding: 18px 8px;
  color: #6b7280;
}

footer.note {
  color: #6b7280;
  font-size: 12px;
  margin-top: 8px;
}

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: static;
    height: auto;
    padding: 16px 14px 12px;
    gap: 12px;
  }
  nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .side-note { margin-top: 4px; }
  main { padding: 16px 14px 32px; }
  .form-grid, .history-item, .task { grid-template-columns: 1fr; }
  .grow { margin-left: 0; }
}
