/* Приказной порядок — современный UI */

:root {
  --bg-0: #e8eef4;
  --bg-1: #f3f6f9;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --ink: #152033;
  --ink-soft: #3d4a5c;
  --muted: #6b7788;
  --brand: #1a5f8a;
  --brand-hover: #154e72;
  --brand-soft: #e6f1f7;
  --brand-ring: rgba(26, 95, 138, 0.28);
  --accent: #c45c26;
  --border: #d5dee8;
  --border-soft: #e4ebf2;
  --shadow-sm: 0 1px 2px rgba(21, 32, 51, 0.04);
  --shadow-md: 0 8px 24px rgba(21, 32, 51, 0.07);
  --radius: 12px;
  --radius-sm: 8px;
  --soglas: #1f7a4d;
  --oznak: #5b4a9e;
  --rassa: #b85a1a;
  --list-hover: #f0f5f9;
  --list-selected: #dcecf5;
  --list-alt: #f8fafc;
  --font: "Manrope", "Segoe UI", sans-serif;
  --font-display: "Source Serif 4", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  position: relative;
  background: var(--bg-1);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1200px 600px at 8% -10%, rgba(26, 95, 138, 0.14), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(196, 92, 38, 0.08), transparent 50%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 45%, #eef2f6 100%);
}

.app-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(21, 32, 51, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 32, 51, 0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.45), transparent 75%);
  pointer-events: none;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 18px 18px;
}

/* ===== Header ===== */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 4px 14px;
  gap: 16px;
}

.app-user {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.app-user-text {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  min-width: 0;
}

.app-user-name {
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--ink);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.app-user-phone {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.app-btn-logout {
  padding: 8px 12px !important;
  flex-shrink: 0;
}

body.login-page .app-shell {
  max-width: 520px;
  justify-content: center;
}

body.login-page .app-header {
  padding-bottom: 8px;
}

body.login-page .app-main {
  flex: 0 0 auto;
}

.login-card {
  margin: 0;
  padding: 22px 22px 24px;
}

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

.login-hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.login-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #fdecea;
  border: 1px solid #f5c6c0;
  color: #8a2b22;
  font-weight: 600;
  font-size: 0.86rem;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.app-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(145deg, #ffffff, #e8f1f7);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-sm);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.app-logo img {
  display: block;
  border-radius: 4px;
}

.app-brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.app-brand-name {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.15;
}

.app-brand-sub {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#toast-area {
  z-index: 2100;
}

#toast-area .toast {
  min-width: 280px;
  max-width: 380px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-family: var(--font);
}

/* ===== Main tabs ===== */

.main-tabs-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 520px;
  min-width: 0;
  gap: 12px;
}

.main-nav {
  flex-shrink: 0;
}

.main-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  border-bottom: none;
  margin: 0;
}

.main-tabs .nav-item {
  min-width: 0;
}

.main-tabs .nav-link {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-soft);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  text-align: left;
  border: 1px solid transparent;
  margin-bottom: 0;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.main-tabs .nav-link:hover {
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  border-color: var(--border-soft);
}

.main-tabs .nav-link.active {
  background: var(--surface-solid);
  color: var(--brand);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.tab-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.main-tabs .nav-link.active .tab-icon {
  background: var(--brand);
  color: #fff;
}

.tab-label {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.tab-title {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}

.tab-desc {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-tabs .nav-link.active .tab-desc {
  color: #6f8798;
}

.main-tab-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 16px;
  padding: 16px;
  min-height: 0;
  box-shadow: var(--shadow-md);
}

.main-tab-pane > .tab-pane {
  flex: 1;
  min-height: 0;
}

.main-tab-pane > .tab-pane.active {
  display: flex !important;
  flex-direction: column;
}

/* ===== Panels ===== */

.panel {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin: 0 0 12px;
  padding: 14px 16px;
  background: var(--surface-solid);
  min-width: 0;
  box-shadow: var(--shadow-sm);
}

.panel-compact {
  padding-top: 12px;
  padding-bottom: 12px;
  margin-bottom: 10px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-bottom: 10px;
}

.panel-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.panel-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.badge-soft {
  margin-left: auto;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-soft);
  border: 1px solid #c9dfec;
  border-radius: 6px;
  padding: 3px 8px;
}

.app-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 0;
}

.field-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

/* ===== Inputs / textareas ===== */

.app-input,
.app-textarea,
.form-control.app-input,
.form-control.app-textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: var(--font);
  background: #fff;
  color: var(--ink);
  box-shadow: none !important;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.app-textarea,
.form-control.app-textarea {
  padding: 12px;
  font-size: 0.92rem;
  line-height: 1.55;
  resize: none;
}

.app-input:focus,
.app-textarea:focus,
.form-control.app-input:focus,
.form-control.app-textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring) !important;
  outline: none;
}

.app-input:disabled {
  background: #f1f4f7;
  color: var(--muted);
}

.app-textarea.grow {
  flex: 1;
  min-height: 160px;
  height: 100%;
}

.app-textarea[readonly] {
  background: #f7f9fb;
  color: var(--ink-soft);
}

.search-wrap {
  position: relative;
  margin-bottom: 10px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-wrap .app-input {
  padding-left: 38px;
}

/* ===== Check chips ===== */

.checks-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.check-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #f8fafc;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-soft);
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.check-chip:hover {
  background: #fff;
  border-color: #b9cad8;
}

.check-chip:has(input:checked) {
  background: var(--brand-soft);
  border-color: #9fc4d9;
  color: var(--brand);
}

.check-chip .form-check-input {
  width: 16px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
}

.form-check-input:checked {
  background-color: var(--brand);
  border-color: var(--brand);
}

/* ===== Buttons ===== */

.app-btn {
  border: none !important;
  border-radius: var(--radius-sm) !important;
  padding: 10px 18px !important;
  font-weight: 700 !important;
  font-size: 0.88rem !important;
  font-family: var(--font) !important;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.12s ease !important;
}

.app-btn:active {
  transform: translateY(1px);
}

.app-btn-primary {
  background: var(--brand) !important;
  color: #fff !important;
}

.app-btn-primary:hover {
  background: var(--brand-hover) !important;
  color: #fff !important;
}

.app-btn-secondary {
  background: #eef3f7 !important;
  color: var(--ink) !important;
  border: 1px solid var(--border) !important;
}

.app-btn-secondary:hover {
  background: #e4ebf2 !important;
  color: var(--ink) !important;
}

.app-btn-outline {
  background: #fff !important;
  color: var(--brand) !important;
  border: 1px solid var(--brand) !important;
  text-decoration: none !important;
}

.app-btn-outline:hover {
  background: var(--brand-soft) !important;
  color: var(--brand) !important;
}

/* legacy class used in JS download link */
.app-btn:not(.app-btn-primary):not(.app-btn-secondary):not(.app-btn-outline) {
  background: var(--brand) !important;
  color: #fff !important;
}

.doc-type-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.doc-type-btn {
  padding: 8px 14px !important;
  font-size: 0.86rem !important;
  border-radius: var(--radius-sm) !important;
  font-weight: 700 !important;
  background: #f1f5f8 !important;
  color: var(--ink-soft) !important;
  border: 1px solid var(--border) !important;
  line-height: 1.2;
  min-width: 0;
}

.btn-check:checked + .doc-type-btn {
  background: var(--brand) !important;
  color: #fff !important;
  border-color: var(--brand-hover) !important;
}

.btn-check:focus-visible + .doc-type-btn {
  box-shadow: 0 0 0 3px var(--brand-ring);
}

/* ===== Shared layouts ===== */

.file-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.file-row .app-input {
  flex: 1;
}

.file-drop {
  border: 1.5px dashed #b7c8d6;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #f8fbfd, #f3f7fa);
  padding: 12px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.file-drop.is-dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.texts-row {
  display: flex;
  gap: 12px;
  flex: 1;
  min-height: 220px;
}

.texts-row > .panel {
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
  flex: 1;
}

.text-panel .app-textarea {
  border-color: var(--border-soft);
}

.bottom-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.tab2-actions {
  margin-top: 0;
  padding: 12px 4px 2px;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.7));
}

.letter-box {
  min-height: auto;
}

.letter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  align-items: start;
}

.letter-kontakt {
  min-height: 70px !important;
  max-height: 90px;
  height: 80px;
}

.texts-row-generate {
  min-height: 200px;
  margin-bottom: 12px;
}

.text-box-min {
  min-height: 200px;
}

/* ===== Tab layouts ===== */

.tab-upload-layout,
.tab-free-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 0;
  padding: 2px;
}

.tab-generate-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.tab-generate-scroll {
  flex: 1;
  overflow: auto;
  padding: 2px 2px 8px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: #c5d0db transparent;
}

.people-splitter {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 240px;
  margin-bottom: 4px;
}

.people-box,
.roles-box {
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
  min-height: 0;
}

.people-box {
  align-self: start;
}

.people-list,
.role-list {
  list-style: none;
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  flex: 1;
  min-height: 120px;
  scrollbar-width: thin;
}

.people-list {
  flex: 0 0 auto;
  min-height: 0;
  max-height: calc(5 * 56px + 8px);
}

.role-list-executor {
  min-height: 86px;
  max-height: 96px;
  flex: 0 0 auto;
}

.role-list-signature {
  min-height: 100px;
}

.people-list li,
.role-list li {
  padding: 10px 12px;
  border-radius: 8px;
  border-bottom: none;
  margin-bottom: 2px;
  cursor: pointer;
  line-height: 1.3;
  font-size: 0.88rem;
  transition: background 0.12s ease;
}

.people-list li:nth-child(even),
.role-list li:nth-child(even) {
  background: var(--list-alt);
}

.people-list li:hover,
.role-list li:hover {
  background: var(--list-hover);
}

.people-list li:active,
.role-list li:active,
.people-list li.selected,
.role-list li.selected {
  background: var(--list-selected);
  color: var(--brand);
}

.people-list li .fio,
.role-list li .fio {
  font-weight: 700;
  display: block;
}

.people-list li .pos,
.role-list li .pos {
  color: var(--muted);
  font-size: 0.78rem;
  display: block;
  margin-top: 2px;
}

.people-list li.empty-hint {
  color: var(--muted);
  cursor: default;
  background: transparent !important;
  padding: 16px 12px;
}

/* Role tabs */

.role-tabs {
  border-bottom: none;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.role-tabs .nav-link {
  min-width: 0;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--muted);
  background: #f1f5f8;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  text-align: center;
}

.role-tabs .nav-link:hover {
  background: #e7eef4;
  color: var(--ink-soft);
}

.role-tabs .nav-link.active {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: #b7d2e3;
}

.role-tab-content {
  padding-top: 2px;
}

.role-hint {
  font-weight: 700;
  font-size: 0.78rem;
  margin-bottom: 8px;
}

.role-hint-executor { color: var(--brand); }
.role-hint-soglas { color: var(--soglas); }
.role-hint-oznak { color: var(--oznak); }
.role-hint-rassa { color: var(--rassa); }

.hidden {
  display: none !important;
}

/* ===== Loading ===== */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(232, 238, 244, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-overlay.show {
  display: flex;
}

.spinner-box {
  background: #fff;
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 1.15rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-md);
  min-width: 240px;
}

.spinner-ring {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid #d7e4ee;
  border-top-color: var(--brand);
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

.spinner-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.spinner-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink);
}

#loading-text {
  font-size: 0.8rem;
  color: var(--muted);
}

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

/* ===== Responsive ===== */

@media (max-width: 992px) {
  .texts-row,
  .people-splitter {
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .letter-grid {
    grid-template-columns: 1fr;
  }

  .main-tabs {
    grid-template-columns: 1fr;
  }

  .tab-desc {
    white-space: normal;
  }

  .app-shell {
    max-width: 100%;
    padding: 0 12px 12px;
  }

  .main-tab-pane {
    padding: 12px;
  }
}

@media (max-width: 640px) {
  .app-brand-sub {
    display: none;
  }

  .app-user-name {
    max-width: 160px;
  }

  .file-row {
    flex-direction: column;
    align-items: stretch;
  }

  .bottom-actions {
    justify-content: stretch;
  }

  .bottom-actions .btn,
  .bottom-actions a.btn {
    flex: 1 1 auto;
    text-align: center;
  }
}

@media (min-width: 993px) {
  .app-shell {
    min-height: 900px;
  }
}

/* Compatibility: old group-box class if referenced elsewhere */
.group-box {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin: 0 0 12px;
  padding: 14px 16px;
  background: var(--surface-solid);
}

.group-box > legend {
  float: none;
  width: auto;
  padding: 0;
  margin: 0 0 8px;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
}

.inline-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.inline-field .app-input {
  flex: 1;
}
