:root {
  --bg: #0b1020;
  --panel: #121a2d;
  --muted: #7f8ca8;
  --text: #e8ecf5;
  --primary: #4c7dff;
  --danger: #d14545;
  --border: #25314f;
  --radius: 12px;
  --history-window-height: 40vh;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-user a {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
}

.topbar-user a.active {
  background: var(--primary);
  border-color: transparent;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  margin-left: auto;
  margin-right: 48px;
}

.topbar-admin-action {
  margin-left: 28px;
  margin-right: 28px;
}

.topbar-admin-action a {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
}

.topbar-admin-action a.active {
  background: var(--primary);
  border-color: transparent;
}

.topbar-actions a {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
}

.topbar-actions a.active {
  background: var(--primary);
  border-color: transparent;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 56px);
  align-items: stretch;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.history-list, .guide-list {
  margin: 0;
  padding-left: 18px;
}


.history-list a {
  color: var(--text);
  text-decoration: none;
  display: block;
  padding: 8px 0;
  border-radius: 8px;
  padding-left: 8px;
  padding-right: 8px;
}

.history-list a.active {
  background: #2a3244;
}

.history-list-window {
  height: var(--history-window-height);
  max-height: var(--history-window-height);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: #0f1729;
}

.prompt-criteria-align {
  margin-top: calc(var(--history-window-height) - 32vh + 5.4em);
}

.history-panel,
.right-column {
  min-height: calc(100vh - 88px);
  display: flex;
  flex-direction: column;
}

.history-guide-bottom {
  margin: 12px 0 12px 0;
  padding-top: 4px;
}

.history-search {
  margin-bottom: 12px;
}

.right-column > .panel.center {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.right-column .editor-form {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.prompt-builder-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr;
  gap: 12px;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
}

.prompt-builder-col {
  padding: 12px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.prompt-builder-col h3 {
  margin-top: 0;
}

.result-col {
  min-height: 0;
  overflow: auto;
}

.result-col textarea {
  min-height: 0;
  flex: 1 1 auto;
  width: 100%;
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  line-height: 1.35;
}

.result-col small {
  color: var(--muted);
}

.search-form, .editor-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.prompt-builder-col > .search-form {
  margin-top: 0;
  flex: 1 1 auto;
  min-height: 0;
}

.model-actions-row {
  display: flex;
  gap: 10px;
  margin-top: auto;
}

.model-actions-row button {
  flex: 1;
}

.result-actions-row {
  display: flex;
  gap: 10px;
  margin-top: auto;
}

.result-actions-row button {
  flex: 1;
}

.result-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.result-header-row h3 {
  margin: 0;
}

#user-result-btn {
  white-space: nowrap;
  padding: 6px 10px;
  font-size: 13px;
  line-height: 1.2;
  width: auto;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

#user-result-btn.is-user-active {
  background: var(--primary);
  border-color: transparent;
  color: #ffffff;
}

#user-result-btn.is-ia-active {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

#improve-prompt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#improve-prompt-btn .btn-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  display: none;
}

#improve-prompt-btn.is-loading .btn-spinner {
  display: inline-block;
  animation: btn-spin 0.8s linear infinite;
}

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

.model-readonly-note {
  margin: 10px 0 0;
  color: var(--muted);
}

.prompt-builder-col:first-child .search-form label {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 8px;
}

.prompt-builder-col:first-child .search-form label.model-name-label {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.prompt-builder-col:first-child .search-form label.model-step-label-first {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.criterion-input {
  min-height: calc(1.35em * 3 + 22px);
  max-height: calc(1.35em * 3 + 22px);
  resize: none;
  overflow-y: auto;
}

.criterion-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.criterion-block:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.criterion-map-select {
  text-align: left;
  text-align-last: left;
}


.centered-label {
  text-align: center;
}

.criteria-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border: 1px solid #2b3b61;
  border-radius: 10px;
  background: #0b1428;
  justify-content: flex-start;
}

.criteria-tab {
  text-decoration: none;
  text-align: center;
  border: 1px solid transparent;
  background: transparent;
  color: #aeb9d1;
  padding: 7px 6px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.01em;
  line-height: 1.1;
  transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  width: auto;
  min-width: 84px;
}

.criteria-tab:hover {
  color: #dbe6ff;
  background: rgba(76, 125, 255, 0.1);
}

.criteria-tab.active {
  background: linear-gradient(135deg, #4c7dff 0%, #5e97ff 100%);
  border-color: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(76, 125, 255, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.hidden-template-select {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

input, textarea, button, select {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1729;
  color: var(--text);
  padding: 10px;
}

#prompt-template-select {
  text-align: center;
  text-align-last: center;
}

#model-label-input,
select[name^="criterion_label_"],
select[id^="model-criterion-"] {
  text-align: left;
  text-align-last: left;
}

#model-label-input {
  text-align: center;
  text-align-last: center;
}

button {
  cursor: pointer;
  background: var(--primary);
  border: none;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: auto;
}

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

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 480px at 0% 0%, rgba(76, 125, 255, 0.18), transparent 60%),
    radial-gradient(900px 420px at 100% 100%, rgba(76, 125, 255, 0.12), transparent 60%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 22px 50px rgba(5, 10, 22, 0.45);
}

.auth-header {
  margin-bottom: 18px;
}

.auth-badge {
  display: inline-block;
  border: 1px solid #2b3b61;
  background: rgba(76, 125, 255, 0.12);
  color: #b7c8ff;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.02em;
  margin-bottom: 10px;
}

.auth-header h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.15;
}

.auth-header p {
  margin: 0;
  color: #a0acc6;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.auth-field label {
  font-size: 14px;
  font-weight: 600;
  color: #c7d2eb;
}

.auth-field input {
  height: 46px;
  border-radius: 10px;
  border: 1px solid #2b3b61;
  background: #0b1428;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.auth-field input::placeholder {
  color: #647492;
}

.auth-field input:focus {
  outline: none;
  border-color: #5f8cff;
  box-shadow: 0 0 0 3px rgba(95, 140, 255, 0.22);
}

.auth-field small {
  color: var(--muted);
  font-size: 12px;
}

.auth-form button {
  margin-top: 4px;
  height: 46px;
  border-radius: 10px;
  font-weight: 600;
  background: linear-gradient(135deg, #4c7dff 0%, #5e97ff 100%);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.auth-form button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(76, 125, 255, 0.35);
}

.auth-form button:active {
  transform: translateY(0);
}

.auth-card .alert {
  margin: 14px 0 16px;
  border: 1px solid rgba(209, 69, 69, 0.45);
  background: rgba(209, 69, 69, 0.18);
}

.auth-help-link {
  margin-top: 14px;
  margin-bottom: 0;
  text-align: center;
}

.auth-help-link a {
  color: #b7c8ff;
  text-decoration: none;
}

.auth-help-link a:hover {
  text-decoration: underline;
}

.alert {
  padding: 10px;
  border-radius: 8px;
  background: #3d1d1d;
  margin: 10px 0;
}

.alert-success {
  background: #1d3d28;
  border: 1px solid #2b6a42;
}

.link-btn {
  color: var(--text);
  text-decoration: none;
}

.logout-form {
  margin: 0;
}

.logout-btn {
  width: auto;
  background: transparent;
  border: 1px solid var(--border);
  padding: 8px 12px;
}

.tabs-nav {
  display: flex;
  gap: 10px;
  padding: 10px 16px;
}

.tabs-nav a {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
}

.tabs-nav a.active {
  background: var(--primary);
  border-color: transparent;
}

.users-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  padding: 16px;
}

.button-secondary {
  display: inline-block;
  background: #1c2742;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 8px;
}

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

.checkbox input {
  width: auto;
}

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

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

.users-table th, .users-table td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

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

.table-actions form {
  margin: 0;
}

.pagination {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.mfa-qr {
  width: 220px;
  height: 220px;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
  margin: 10px 0;
  background: #fff;
}

@media (max-width: 1100px) {
  .dashboard-grid,
  .users-layout {
    grid-template-columns: 1fr;
  }

  .prompt-builder-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .auth-page {
    padding: 14px;
  }

  .auth-card {
    padding: 20px;
    border-radius: 14px;
  }

  .auth-header h1 {
    font-size: 26px;
  }

  .criteria-tabs {
    justify-content: stretch;
  }

  .criteria-tab {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
  }
}
