/* Admin page. Builds on style.css (tokens, .brand, .field, .btn-solid, .link-btn, .side-link) and
   keeps its AAA rules: text >= 7:1, control borders >= 3:1, targets >= 44 px. */

.admin-denied {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  font-size: 16px;
  color: var(--mist);
  text-align: center;
}

.admin-denied h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 400;
}

.admin-shell {
  min-height: 100vh;
}

/* The site's nav: lockup left, secondary links and the account right. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--navy-line);
  background: var(--navy);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1120px;
  height: 72px;
  margin: 0 auto;
  padding: 0 32px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.user-menu .user-name {
  padding: 0 8px 0 12px;
  border-left: 1px solid var(--navy-line);
}

.admin-main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 56px 32px 96px;
  display: flex;
  flex-direction: column;
  gap: 64px;
}

.admin-main:focus {
  outline: none;
}

.admin-intro h1 {
  margin: 0;
  font-size: clamp(2.25rem, 4vw, 3rem);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.admin-summary {
  margin: 14px 0 0;
  font-size: 17px;
  line-height: 1.6;
  color: var(--slate);
}

/* This month's questions against the package (app/package_quota.py), under the summary; absent without a package. */
.usage-line {
  margin-top: 4px;
}

/* Lynks's package choice under the tier switch: the select and its button on one line. */
.package-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 16px;
  margin-top: 24px;
}

.package-form .field {
  margin: 0;
  min-width: 16rem;
}

.package-form .btn-solid {
  margin: 0;
}

.extra-package-count {
  margin: 0;
  align-self: center;
}

.section-head {
  margin-bottom: 20px;
}

.section-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.section-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.admin-hint {
  margin: 8px 0 0;
  max-width: 68ch;
  font-size: 15px;
  line-height: 1.6;
  color: var(--slate);
}

.admin-empty {
  margin: 0;
  padding: 20px 0;
  border-top: 1px solid var(--navy-line);
  font-size: 15px;
  color: var(--slate);
}

/* The one boxed block: adding a document is a form, not a list. */
.admin-upload {
  padding: 28px;
  border: 1px solid var(--navy-line);
  border-radius: 16px;
  background: var(--navy-2);
}

/* On Google Drive the box holds only this note (admin.js storeView); a store not set up shows it as an error. */
#store-note.status-msg {
  margin: 8px 0 0;
  max-width: 68ch;
}

/* Why deleted documents are not being removed, or a large removal waiting for confirmation (admin.js indexHealthView). */
#index-health p {
  margin: 0;
  max-width: 68ch;
}

#index-health .btn-solid {
  margin-top: 12px;
}

.upload-form {
  display: grid;
  grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr) auto;
  align-items: end;
  gap: 16px;
}

.upload-form .field {
  margin: 0;
}

.upload-form .btn-solid {
  margin: 0;
}

.field select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23aabbc8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.file-picker {
  position: relative;
  display: flex;
  align-items: stretch;
  min-height: 48px;
  border: 1px solid var(--field-line);
  border-radius: 10px;
  background: var(--navy);
  overflow: hidden;
}

.file-picker input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  min-height: 0;
  opacity: 0;
  cursor: pointer;
}

.file-picker:hover {
  border-color: var(--slate);
}

.file-picker:focus-within {
  outline: 2px solid var(--cyan);
  border-color: var(--cyan);
}

.file-btn {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0 16px;
  border-right: 1px solid var(--field-line);
  background: var(--navy-3);
  font-size: 15px;
  font-weight: 500;
  color: var(--mist);
}

.file-name {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 0 14px;
  font-size: 15px;
  color: var(--slate);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-name.chosen {
  color: var(--mist);
}

.status-msg {
  margin-bottom: 20px;
  padding: 12px 16px;
  border: 1px solid var(--navy-line);
  border-left-width: 3px;
  border-radius: 10px;
  background: var(--navy);
  font-size: 15px;
  line-height: 1.5;
}

.status-msg.ok {
  border-left-color: var(--ok);
  color: var(--mist);
}

.status-msg.error {
  border-color: var(--danger);
  color: var(--danger);
}

/* Tables sit on the page, not in boxes. They scroll sideways on a phone. */
.table-wrap {
  overflow-x: auto;
}

.table-wrap:focus-visible {
  outline-offset: 4px;
}

.doc-table {
  width: 100%;
  min-width: 40rem;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.5;
}

.doc-table th {
  padding: 0 14px 12px 0;
  border-bottom: 1px solid var(--field-line);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  color: var(--slate);
  white-space: nowrap;
}

.doc-table td {
  padding: 14px 14px 14px 0;
  border-bottom: 1px solid var(--navy-line);
  vertical-align: top;
  color: var(--mist);
}

.doc-table th:last-child,
.doc-table td:last-child {
  padding-right: 0;
}

.doc-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.doc-table td.muted {
  color: var(--slate);
}

.doc-table td.nowrap {
  white-space: nowrap;
}

.doc-table tbody tr:hover td {
  background: var(--navy-2);
}

.doc-name {
  font-weight: 500;
  overflow-wrap: anywhere;
}

/* A dot plus a word: the word carries the meaning, the dot lets you scan the column. */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--slate);
}

.status-pill.ingested::before {
  background: var(--ok);
}

.status-pill.pending::before {
  background: var(--gold);
}

.status-pill.failed {
  color: var(--danger);
}

.status-pill.failed::before {
  background: var(--danger);
}

/* ---------- L2: data sources ----------
   A department is a heading, its sources are rows with one sentence of state (not cards). The mapping editor is
   the page's second boxed block: like "Dodaj dokument" it is a form. Cyan means "linked to Atlas": the tag a
   chosen column carries in the preview and the line beside its cells. */

.dept + .dept {
  margin-top: 40px;
}

.dept-name {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 600;
  color: var(--slate);
}

.source-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.source {
  padding: 20px 0;
  border-bottom: 1px solid var(--navy-line);
}

.source-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.source-name {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
}

/* The status sentence reuses the status dot, but wraps: it is a sentence, not a label. */
.source-status {
  margin: 6px 0 0;
  max-width: 72ch;
  font-size: 15px;
  line-height: 1.55;
  color: var(--slate);
  white-space: normal;
  align-items: baseline;
}

.source-status::before {
  flex-shrink: 0;
  transform: translateY(-1px);
}

.source-status.failed {
  color: var(--danger);
}

.status-pill.muted::before {
  background: var(--field-line);
}

.source > .status-msg {
  margin: 16px 0 0;
}

.mapper {
  margin-top: 20px;
  padding: 24px;
  border: 1px solid var(--navy-line);
  border-radius: 16px;
  background: var(--navy-2);
}

.mapper-empty {
  margin: 0;
  max-width: 68ch;
  font-size: 15px;
  line-height: 1.6;
  color: var(--mist);
}

.mapper-controls {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1.2fr) minmax(9rem, 1fr);
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--navy-line);
}

.mapper-controls .field {
  margin: 0;
}

.mapper-body {
  display: grid;
  grid-template-columns: minmax(15rem, 18rem) minmax(0, 1fr);
  gap: 28px;
  padding-top: 20px;
}

.mapper-fields {
  margin: 0;
  padding: 0;
  border: none;
  min-width: 0;
}

.mapper-fields legend {
  padding: 0;
  margin-bottom: 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--mist);
}

.field-note {
  margin-left: 8px;
  font-weight: 400;
  color: var(--slate);
}

.mapper-preview {
  min-width: 0;
}

.preview-caption {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--slate);
}

.preview-table {
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

.preview-table th,
.preview-table td {
  padding: 8px 16px 8px 12px;
  text-align: left;
  white-space: nowrap;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--slate);
}

.preview-table th {
  vertical-align: bottom;
  border-bottom: 1px solid var(--field-line);
  font-weight: 500;
}

.preview-table td {
  border-bottom: 1px solid var(--navy-line);
}

.preview-table .row-num {
  padding-left: 0;
  text-align: right;
}

/* The company's column, linked to an Atlas field: the field's name above it, a cyan line beside its cells. */
.preview-table .mapped {
  color: var(--mist);
  box-shadow: inset 2px 0 0 var(--cyan);
}

.col-tag {
  display: block;
  width: max-content;
  margin-bottom: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--cyan);
  color: var(--navy);
  font-size: 13px;
  font-weight: 600;
}

.col-tag.fresh {
  animation: tag-in 0.18s ease-out;
}

@keyframes tag-in {
  from { opacity: 0; transform: translateY(4px); }
}

@media (prefers-reduced-motion: reduce) {
  .col-tag.fresh { animation: none; }
}

.mapper-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 24px;
}

.mapper .status-msg {
  margin: 20px 0 0;
}

.export-history {
  margin-top: 14px;
}

.export-history > summary,
.skipped > summary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--mist);
}

.export-history > summary::-webkit-details-marker,
.skipped > summary::-webkit-details-marker {
  display: none;
}

/* The browser's own marker goes away with display:flex; this chevron says "opens", and turns when open. */
.export-history > summary::before,
.skipped > summary::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--slate);
  border-bottom: 2px solid var(--slate);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}

.export-history[open] > summary::before,
.skipped[open] > summary::before {
  transform: rotate(45deg);
}

@media (prefers-reduced-motion: reduce) {
  .export-history > summary::before,
  .skipped > summary::before {
    transition: none;
  }
}

.export-history[open] > summary {
  margin-bottom: 8px;
}

.cell-note {
  margin: 4px 0 0;
  max-width: 36ch;
  font-size: 14px;
  color: var(--slate);
}

.skipped > summary {
  justify-content: flex-end;
  min-width: 44px;
}

.skipped ul {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 14px;
  color: var(--slate);
}

@media (max-width: 860px) {
  .mapper-controls,
  .mapper-body {
    grid-template-columns: 1fr;
  }
  /* On a narrow screen the export comes first: see the columns, then choose them. */
  .mapper-preview {
    order: -1;
  }
}

@media (max-width: 860px) {
  .upload-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .site-header-inner {
    height: auto;
    min-height: 64px;
    padding: 8px 16px;
    flex-wrap: wrap;
  }
  .user-menu .user-name {
    display: none;
  }
  .admin-main {
    padding: 36px 16px 64px;
    gap: 48px;
  }
  .admin-upload {
    padding: 20px 16px;
  }
  .mapper {
    padding: 20px 16px;
  }
  .source-row {
    flex-direction: column;
  }
}

/* The tiers a company may use, as one control of three segments filled from the left: L1 always (not a control),
   L2 and L3 native checkboxes Lynks switches on once the company has paid and signed. L3 waits for L2. */
.tier-switch {
  margin: 24px 0 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.tier-switch legend {
  padding: 0;
  margin-bottom: 10px;
  font-size: 15px;
  font-weight: 500;
  color: var(--mist);
}

.tier-options {
  display: inline-flex;
  border: 1px solid var(--field-line);
  border-radius: 12px;
  background: var(--navy);
  overflow: hidden;
}

.tier-option {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-height: 52px;
  padding: 14px 20px;
  cursor: pointer;
  color: var(--slate);
}

.tier-option + .tier-option {
  border-left: 1px solid var(--field-line);
}

.tier-option input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.tier-option:hover {
  background: var(--navy-3);
  color: var(--mist);
}

.tier-option:has(input:checked) {
  background: var(--cyan);
  color: var(--navy);
}

/* Inside the segment: the control clips anything drawn outside it. */
.tier-option:has(input:focus-visible) {
  outline: 2px solid var(--cyan);
  outline-offset: -5px;
}

.tier-option:has(input:checked:focus-visible) {
  outline-color: var(--navy);
}

.tier-switch:disabled .tier-option {
  cursor: progress;
}

.tier-option.is-fixed {
  background: var(--cyan);
  color: var(--navy);
  cursor: default;
}

.tier-option:has(input:disabled) {
  color: var(--slate);
  opacity: 0.55;
  cursor: not-allowed;
}

.tier-option:has(input:disabled):hover {
  background: transparent;
  color: var(--slate);
}

.tier-option input:disabled {
  cursor: not-allowed;
}

.tier-code {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.tier-desc {
  font-size: 15px;
}

#tier-status {
  margin: 16px 0 0;
  max-width: 68ch;
}

@media (max-width: 640px) {
  .tier-options {
    display: flex;
    flex-direction: column;
  }
  .tier-option + .tier-option {
    border-left: 0;
    border-top: 1px solid var(--field-line);
  }
}

/* A source's editors: columns first, then (sales funnel) its stages and rules. */
.source-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.source-text .source-status + .source-status {
  margin-top: 4px;
}

.rules-body {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 32px;
}

.rules-body .field {
  margin: 0 0 14px;
}

@media (max-width: 860px) {
  .rules-body {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

@media (max-width: 640px) {
  .source-row {
    flex-direction: column;
  }
  .source-actions {
    justify-content: flex-start;
  }
}

/* ---------- Superadmin (Lynks only) ----------
   The same page language as the company admin's; the one difference is the cyan "Lynks" mark beside the brand, so
   whoever is logged in sees at a glance that this is the setup the client never sees. */

.lynks-tag {
  margin-left: 4px;
  padding: 2px 10px;
  border: 1px solid var(--cyan);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--cyan);
}

/* A department's address sits under its name, before its sources: every alarm of the department falls back to it. */
.address-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
  margin: 16px 0 4px;
}

.address-form .field {
  flex: 0 1 28rem;
  margin: 0;
}

.address-form .btn-solid {
  margin: 0;
}

.address-form .status-msg {
  flex-basis: 100%;
  margin: 0;
}

/* The alarm editor: one row per alarm kind, its switch beside its number. */
.alarm-row {
  display: grid;
  grid-template-columns: minmax(14rem, 18rem) minmax(0, 22rem);
  align-items: end;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--navy-line);
}

.alarm-row .field {
  margin: 0;
}

.alarm-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  font-size: 16px;
  font-weight: 500;
  color: var(--mist);
  cursor: pointer;
}

.alarm-toggle input {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--cyan);
  flex-shrink: 0;
}

.alarm-toggle input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

/* A kind with no number to set (prestar dokument): what it does, in place of the field. */
.alarm-note {
  align-self: center;
  margin: 0;
  max-width: 40ch;
  font-size: 14px;
  line-height: 1.5;
  color: var(--slate);
}

.field.off label,
.field.off .field-note {
  color: var(--slate);
}

.field.off input {
  border-style: dashed;
  color: var(--slate);
}

/* Responsible people: a name from the exports, the user it is linked to, and where its alarms go. */
.people {
  margin-top: 28px;
}

.people-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.people-list {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.person {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(12rem, 16rem);
  gap: 8px 24px;
  align-items: end;
  padding: 16px 0;
  border-top: 1px solid var(--navy-line);
}

.person .field {
  margin: 0;
}

.person > .source-status {
  grid-column: 1 / -1;
  margin: 0;
}

.person-name {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.person-offers {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--slate);
}

/* A user's e-mail, edited in its table row. */
#users-table td {
  vertical-align: middle;
}

#users-table td:first-child {
  white-space: nowrap;
}

.inline-form.field {
  display: flex;
  gap: 8px;
  margin: 0;
  min-width: 18rem;
}

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

@media (max-width: 640px) {
  .address-form .field {
    flex-basis: 100%;
  }
  .alarm-row,
  .person {
    grid-template-columns: 1fr;
  }
}

/* Evidencija upita: paging under the table. */
.query-log-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.query-log-pager .admin-hint {
  margin: 0;
}

/* Evidencija upita: the filters and the CSV download above the table (issue #51). */
.query-log-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  align-items: end;
  gap: 12px 16px;
  margin-bottom: 16px;
}

.query-log-filters .field {
  margin: 0;
}

.query-log-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  font-size: 14px;
  color: var(--mist);
  cursor: pointer;
}

.query-log-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--cyan);
}

.query-log-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.query-log-actions .btn-solid {
  text-decoration: none;
}

.query-log-actions .btn-solid[aria-disabled="true"] {
  background: var(--navy-3);
  color: var(--slate);
  pointer-events: none;
}

#query-log-filter-error {
  margin: 0 0 12px;
}

.query-log-csv-note {
  margin: 0 0 12px;
}
