:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #1f2d3d;
  --muted: #66788a;
  --line: #d9e1e8;
  --primary: #1967d2;
  --primary-dark: #0f4ea3;
  --danger: #c0392b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

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

button {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  background: var(--primary-dark);
}

button.secondary {
  background: #eef3f8;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.danger {
  background: var(--danger);
}

button.active {
  background: var(--primary);
  color: #fff;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
}

select[multiple] {
  min-height: 180px;
  padding: 6px;
}

select[multiple] option {
  padding: 7px 8px;
  border-radius: 4px;
}

.field-hint {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.35;
  text-transform: none;
}

textarea {
  min-height: 260px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

textarea.maturity-textarea {
  min-height: 140px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.hidden {
  display: none !important;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(31, 45, 61, 0.52);
}

.loading-box {
  width: min(420px, 100%);
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 44px rgba(15, 35, 55, 0.24);
  text-align: center;
}

.loading-box h2 {
  margin: 4px 0 0;
  font-size: 18px;
}

.loading-box p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #dce6f1;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

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

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(380px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-box h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 20px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  background: #eaf0f6;
  border-bottom: 1px solid var(--line);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(150px, auto) auto auto auto auto;
  gap: 10px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  align-items: center;
}

.checkbox-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-transform: none;
  white-space: nowrap;
}

.checkbox-filter input {
  width: auto;
  margin: 0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 36%) 1fr;
  gap: 16px;
  padding: 16px 24px 24px;
  align-items: start;
}

.list-panel,
.editor-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 300px;
}

.list-panel h2,
.panel-head {
  margin: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

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

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

.panel-head h2 {
  margin: 0;
  font-size: 16px;
}

.list {
  display: grid;
  gap: 1px;
  max-height: calc(100vh - 235px);
  overflow: auto;
}

.list.compact {
  max-height: 360px;
}

.item-row {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-bottom: 1px solid #edf1f5;
  background: #fff;
  cursor: pointer;
}

.item-row:hover {
  background: #f8fbff;
}

.item-row.deleted-row {
  background: #fff9f8;
}

.item-row.deleted-row:hover {
  background: #fff2ef;
}

.item-row strong {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
}

.item-code {
  flex: 0 0 auto;
  color: var(--primary);
  font-weight: 800;
}

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

.status-pill {
  width: fit-content;
  padding: 2px 7px;
  border-radius: 999px;
  background: #fdecea;
  color: var(--danger) !important;
  font-weight: 700;
}

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

.form-grid .wide {
  grid-column: 1 / -1;
}

.html-editor {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: stretch;
}

.html-editor label {
  min-width: 0;
}

.html-preview {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.preview-title {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #f7f9fb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.html-preview iframe {
  width: 100%;
  height: 100%;
  min-height: 380px;
  border: 0;
  background: #fff;
}

.compact-form {
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 900px) {
  .toolbar,
  .workspace,
  .form-grid,
  .compact-form,
  .html-editor {
    grid-template-columns: 1fr;
  }

  .topbar,
  .tabs {
    flex-wrap: wrap;
  }
}
