/* Цифровой Технолог — frontend */
:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --sidebar-w: 280px;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(139, 156, 179, 0.22);
  --scrollbar-thumb-hover: rgba(139, 156, 179, 0.38);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

*::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
  background-clip: padding-box;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header {
  flex-shrink: 0;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 0.95rem;
  margin: 0 0 0.75rem;
  font-weight: 600;
}

/* Заголовок приложения — ссылка на главную без визуального выделения */
.sidebar-header h1 a {
  color: inherit;
  text-decoration: none;
  font: inherit;
}

.btn-home {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-home-icon {
  flex-shrink: 0;
}

.session-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.preview img.preview-drawing {
  max-width: 100%;
  max-height: 420px;
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
  margin-top: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

/* Увеличенное превью чертежа — не более 80% окна */
.preview-lightbox {
  z-index: 210;
  cursor: zoom-out;
}

.preview-lightbox-img {
  max-width: 80vw;
  max-height: 80vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  cursor: zoom-out;
}

.session-item {
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  border: 1px solid transparent;
}

.session-item:hover {
  background: rgba(59, 130, 246, 0.12);
}

.session-item.active {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--accent);
}

.session-item .title {
  font-size: 0.875rem;
  font-weight: 500;
}

.session-item .session-date {
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.75;
  margin-top: 1px;
}

.session-item .meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 4px;
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toolbar {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.content {
  padding: 1.25rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

button,
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

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

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

select,
input[type="text"],
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.875rem;
}

textarea {
  width: 100%;
  min-height: 80px;
  resize: vertical;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
}

.dropzone.disabled {
  opacity: 0.6;
  pointer-events: none;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

/* Главная (когда сессия не выбрана) */
.home-hero-card {
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.10), var(--panel));
}

.home-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.home-intro {
  margin-bottom: 1.25rem;
}

.home-intro p {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.home-intro p:last-child {
  margin-bottom: 0;
}

.home-steps-heading {
  margin: 0 0 0.85rem;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--text);
}

.home-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

@media (max-width: 900px) {
  .home-steps {
    grid-template-columns: 1fr;
  }
}

/* Блок «Последние обновления» на главной */
.home-changelog-title {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.home-release {
  padding: 0.85rem 0;
  border-top: 1px solid var(--border);
}

.home-release:first-of-type {
  border-top: none;
  padding-top: 0;
}

.home-release-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.55rem;
}

.home-release-date {
  color: var(--muted);
  font-size: 0.85rem;
}

.home-release-ver {
  font-size: 0.78rem;
  font-weight: 650;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: var(--text);
}

.home-release-list {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.home-release-list li {
  margin-bottom: 0.35rem;
}

.home-release-list li:last-child {
  margin-bottom: 0;
}

.home-step {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.75rem;
  border: 1px solid rgba(45, 58, 79, 0.8);
  border-radius: 12px;
  background: rgba(26, 35, 50, 0.65);
}

.home-step-num {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59, 130, 246, 0.18);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: var(--text);
  font-weight: 700;
  flex-shrink: 0;
}

.home-step-title {
  font-weight: 650;
  font-size: 0.92rem;
  margin: 0;
}

.home-step-text {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
  margin-top: 0.15rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.passport-section {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.passport-section:last-child {
  border-bottom: none;
}

.passport-section .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.passport-section .value {
  margin-top: 0.25rem;
}

.passport-section .value.prewrap {
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 0.9rem;
}

.passport-section.missing .value {
  color: var(--warn);
  font-style: italic;
}

.technology-text {
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

.tech-route-step {
  margin: 0.5rem 0 0.75rem;
  padding: 0.5rem 0 0.5rem 0.75rem;
  border-left: 3px solid var(--accent, #3b82f6);
}

.tech-route-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.passport-section.nested {
  margin-left: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: none;
}

.passport-section.nested .label {
  font-size: 0.75rem;
}

table.tech-ops {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

table.tech-ops th,
table.tech-ops td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.5rem;
  text-align: left;
  vertical-align: top;
}

table.tech-ops th {
  background: var(--panel);
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  margin-bottom: 1rem;
}

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  background: var(--border);
}

.status-badge.analyzing,
.status-badge.generating_technology {
  background: rgba(59, 130, 246, 0.3);
}

.status-badge.completed {
  background: rgba(34, 197, 94, 0.3);
}

.status-badge.passport_failed,
.status-badge.technology_failed,
.status-badge.failed {
  background: rgba(239, 68, 68, 0.25);
}

.ai-busy-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  margin-bottom: 1rem;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.inline-busy {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.review-actions {
  align-items: center;
  flex-wrap: wrap;
}

.loader {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 0.5rem;
}

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

.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  padding: 0.75rem 1rem;
  background: var(--danger);
  border-radius: 8px;
  max-width: 360px;
  z-index: 100;
  display: none;
}

.toast.show {
  display: block;
}

.toast.info {
  background: var(--panel);
  border: 1px solid var(--border);
}

.hidden {
  display: none !important;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}

.stat-box {
  background: var(--bg);
  padding: 0.75rem;
  border-radius: 8px;
  text-align: center;
}

.stat-box .num {
  font-size: 1.5rem;
  font-weight: 600;
}

.stat-box .lbl {
  font-size: 0.7rem;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-backdrop.show {
  display: flex;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  max-width: 400px;
  width: 90%;
}

.modal p {
  margin: 0 0 1rem;
}

.modal .actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.modal-reset-pwd {
  max-width: 440px;
}

.modal-reset-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.modal-reset-pwd-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.modal-reset-pwd-value {
  flex: 1;
  padding: 0.5rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  word-break: break-all;
}

.modal-reset-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 1rem !important;
}

.btn-copy {
  flex-shrink: 0;
  padding: 0.4rem 0.55rem;
  font-size: 1rem;
  line-height: 1;
}

/* Вход */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
}

.login-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.login-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 1rem;
}

.login-card label {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

.login-card input {
  width: 100%;
  margin-top: 4px;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.login-foot {
  font-size: 0.7rem;
  color: var(--muted);
  margin: 1rem 0 0;
}

.login-foot code {
  color: var(--accent);
}

.user-profile-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  width: 100%;
  margin: 0 0 0.75rem;
  padding: 0.35rem 0.4rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
}

.user-profile-btn:hover {
  border-color: var(--border);
  background: var(--bg);
  color: var(--text);
}

.user-profile-icon {
  flex-shrink: 0;
  font-size: 0.9rem;
  opacity: 0.85;
}

.user-profile-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.profile-section h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.profile-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 360px;
}

.profile-form label {
  font-size: 0.8rem;
  color: var(--muted);
}

.profile-form input {
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.admin-table input,
.admin-table select {
  padding: 0.25rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.75rem;
  max-width: 140px;
}

.admin-table .cell-actions {
  white-space: nowrap;
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.admin-section {
  margin-bottom: 1.5rem;
}

.admin-section h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.admin-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.admin-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-right: 0.5rem;
}

.prompt-team-row {
  margin-bottom: 1rem;
  align-items: center;
}

.prompt-editor {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.prompt-editor textarea {
  width: 100%;
  min-height: 140px;
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  resize: vertical;
}

.prompt-versions {
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

.prompt-versions ul {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}

.prompt-versions li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.prompt-versions li.active-ver {
  color: var(--success);
}

.ver-preview {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: pre-wrap;
  margin: 0.25rem 0 0;
}

.model-endpoint-block {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.model-endpoint-block h4 {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
}

.model-fields input {
  min-width: 200px;
}

.key-hint.ok {
  color: var(--success);
  font-size: 0.75rem;
}

.key-hint.warn {
  color: var(--warn);
  font-size: 0.75rem;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.admin-table th,
.admin-table td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.5rem;
  text-align: left;
}

.admin-table td.mono {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.72rem;
  word-break: break-all;
}

.analytics-sessions-table {
  display: block;
  overflow-x: auto;
}

.analytics-sort-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.analytics-sort-th:hover {
  background: rgba(255, 255, 255, 0.04);
}

.analytics-sort-th.active {
  color: var(--accent, #5b9fd4);
}

.admin-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: flex-end;
}

.btn-sm {
  padding: 0.2rem 0.45rem;
  font-size: 0.7rem;
}

.admin-form input,
.admin-form select {
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.op-subhead {
  font-size: 0.9rem;
  margin: 1rem 0 0.5rem;
}

.op-selected-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.op-selected-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.65rem;
  margin-bottom: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.op-selected-label {
  flex: 1;
  font-size: 0.9rem;
}

.op-remove-btn {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.15rem 0.35rem;
  line-height: 1;
}

.op-combobox {
  position: relative;
  margin-bottom: 0.5rem;
}

.op-search-row {
  position: relative;
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.op-search-input {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 0.5rem 2rem 0.5rem 0.65rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.875rem;
}

.op-search-input:focus {
  outline: none;
}

/* Стрелка внутри поля; без наследования синего button:hover */
.op-picker-toggle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 2rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0 8px 8px 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

.op-picker-toggle:hover,
.op-picker-toggle:focus,
.op-picker-toggle:active,
.op-picker-toggle.is-open {
  background: transparent;
  color: var(--muted);
  border: none;
  outline: none;
  box-shadow: none;
}

.op-picker-chevron {
  display: inline-block;
  font-size: 0.65rem;
  line-height: 1;
  transition: transform 0.15s ease;
}

.op-picker-toggle.is-open .op-picker-chevron {
  transform: rotate(180deg);
}

.op-dropdown-panel {
  display: none;
  position: absolute;
  z-index: 50;
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.op-combobox.open .op-dropdown-panel {
  display: block;
}

.op-dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.875rem;
}

.op-dropdown-item:hover:not(:disabled) {
  background: rgba(59, 130, 246, 0.12);
}

.op-dropdown-item.is-picked,
.op-dropdown-item:disabled {
  opacity: 0.45;
  cursor: default;
}

.op-dropdown-empty {
  padding: 0.65rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.op-cat-operation,
.op-cat-equipment {
  width: 100%;
  min-width: 120px;
}

/* FinOps — вкладка «Аналитика» (superuser) */
.analytics-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.analytics-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.analytics-filters select {
  min-width: 140px;
  padding: 0.35rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
}

.analytics-section h4 {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.95rem;
}
