/* Учёт оборудования — оформление. Светлая и тёмная темы, вёрстка под планшет. */

:root {
  color-scheme: light dark;

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #dbeafe;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --off: #475569;
  --off-soft: #e2e8f0;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-strong: 0 12px 40px rgba(15, 23, 42, 0.18);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --surface: #161b23;
    --surface-2: #1c222c;
    --border: #29313d;
    --border-strong: #3a4453;
    --text: #e8eef7;
    --muted: #9aa7b8;
    --primary: #5b8cff;
    --primary-strong: #7aa2ff;
    --primary-soft: #1e2a44;
    --danger: #f87171;
    --danger-soft: #3a1d1d;
    --ok: #4ade80;
    --ok-soft: #14301f;
    --warn: #fbbf24;
    --warn-soft: #33260f;
    --off: #c3cddb;
    --off-soft: #242b36;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-strong: 0 16px 48px rgba(0, 0, 0, 0.55);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
}

h1,
h2,
p {
  margin: 0;
}

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

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--surface);
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 100;
}

.skip-link:focus {
  left: 16px;
}

/* ------------------------------------------------------------------ шапка */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) 4px 16px;
  max-width: 1180px;
  margin: 0 auto;
}

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

.brand__mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  flex: none;
}

.brand__logo {
  box-sizing: content-box;
  height: 24px;
  width: auto;
  flex: none;
  padding: 4px 9px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 9px;
}

.brand__text h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand__text p {
  font-size: 0.86rem;
  color: var(--muted);
}

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

/* ---------------------------------------------------------------- кнопки */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 60ms ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-2);
}

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

.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

.btn--ghost {
  background: transparent;
}

.btn__plus {
  font-size: 1.15rem;
  line-height: 1;
  margin-top: -1px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 11px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.icon-button:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.icon-button--danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: transparent;
}

/* --------------------------------------------------------------- разметка */

.layout {
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* --------------------------------------------------------------- сводка */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(142px, 1fr));
  gap: 10px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: 12px;
}

.stat__value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  font-size: 0.82rem;
  color: var(--muted);
}

.stat--ok {
  border-left-color: var(--ok);
}
.stat--warn {
  border-left-color: var(--warn);
}
.stat--bad {
  border-left-color: var(--danger);
}
.stat--off {
  border-left-color: var(--off);
}
.stat--muted {
  border-left-color: var(--muted);
}

/* -------------------------------------------------------- поиск и фильтры */

.panel--filters {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

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

.field--search {
  grid-column: span 2;
}

.field__label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-size: 1rem;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.field textarea {
  min-height: 84px;
  resize: vertical;
  line-height: 1.4;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.menu {
  position: relative;
}

.menu > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu[open] > summary {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.menu__list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 250px;
  display: grid;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-strong);
}

.menu__list button {
  text-align: left;
  padding: 11px 12px;
  min-height: 44px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 0.95rem;
}

.menu__list button:hover {
  background: var(--surface-2);
}

/* ---------------------------------------------------------------- таблица */

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

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

.table th {
  text-align: left;
  padding: 11px 14px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}

.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: var(--surface-2);
}

.table__actions-head {
  text-align: right;
}

.table__actions {
  text-align: right;
  white-space: nowrap;
}

.table__actions .icon-button + .icon-button {
  margin-left: 4px;
}

.record-name {
  font-weight: 600;
}

.record-note {
  display: block;
  margin-top: 3px;
  font-size: 0.84rem;
  color: var(--muted);
  max-width: 46ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ----------------------------------------------------------------- бейджи */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge--ok {
  color: var(--ok);
  background: var(--ok-soft);
}
.badge--warn {
  color: var(--warn);
  background: var(--warn-soft);
}
.badge--bad {
  color: var(--danger);
  background: var(--danger-soft);
}
.badge--off {
  color: var(--off);
  background: var(--off-soft);
}
.badge--muted {
  color: var(--muted);
  background: var(--off-soft);
}

/* ------------------------------------------------------------ папки */

.panel--folders {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
}

.folders__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.folders__title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.folders__label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.folders__path {
  font-weight: 600;
  font-size: 0.95rem;
}

.folders__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.folders__actions .btn {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.88rem;
}

.panel--folders.is-collapsed .folders {
  display: none;
}

.panel--folders.is-collapsed {
  padding-bottom: 8px;
}

.folders__toggle {
  border-color: transparent;
  color: var(--muted);
}

.folders__toggle:hover {
  color: var(--text);
  background: var(--surface-2);
}

.folders {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
  max-height: 280px;
  overflow: auto;
}

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

.folder {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-size: 0.93rem;
  text-align: left;
  cursor: pointer;
}

.folder:hover {
  background: var(--surface-2);
}

.folder--active {
  background: var(--primary-soft);
  border-color: var(--primary);
  font-weight: 600;
}

.folder__count {
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.folder--active .folder__count {
  color: var(--primary);
}

.dialog--narrow {
  width: min(420px, calc(100vw - 32px));
}

/* ------------------------------------------------------------ фото */

.photo {
  display: grid;
  gap: 8px;
  padding-top: 4px;
}

.photo__preview {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}

.photo__preview img {
  width: 180px;
  height: 130px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.photo__actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  vertical-align: middle;
  margin-right: 8px;
}

.record-name {
  vertical-align: middle;
}

/* ------------------------------------------------------------ история */

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 55vh;
  overflow: auto;
}

.history__item {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.92rem;
}

.history__time {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.history__details {
  color: var(--muted);
}

.history__empty {
  padding: 24px 0;
  text-align: center;
  color: var(--muted);
}

/* ------------------------------------------------------------ карточки (iPad) */

.cards {
  display: none;
  list-style: none;
  margin: 0;
  padding: 12px;
  gap: 10px;
}

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

.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card__head .record-name {
  font-size: 1.02rem;
  line-height: 1.35;
}

.card__grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 0 0 10px;
  font-size: 0.9rem;
}

.card__grid dt {
  color: var(--muted);
}

.card__grid dd {
  margin: 0;
}

.card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.card__note {
  font-size: 0.86rem;
  color: var(--muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card__actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

/* ------------------------------------------------------------ пустое состояние */

.empty {
  padding: 48px 20px;
  text-align: center;
}

.empty__title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.empty__text {
  color: var(--muted);
  font-size: 0.92rem;
}

.result-count {
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------------ диалог */

.dialog {
  width: min(580px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-strong);
  overflow: hidden;
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.dialog__form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
}

.dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.dialog__head h2 {
  font-size: 1.12rem;
  font-weight: 700;
}

.dialog__body {
  display: grid;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.dialog__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.field--hint {
  align-self: end;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.35;
  margin: 0;
}

.required {
  color: var(--danger);
}

.form-error {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 500;
}

.dialog__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ------------------------------------------------------------------- тост */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #111827;
  color: #f8fafc;
  font-size: 0.92rem;
  box-shadow: var(--shadow-strong);
}

.toast__action {
  border: none;
  background: transparent;
  color: #93c5fd;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 4px;
  min-height: 32px;
}

.noscript {
  max-width: 640px;
  margin: 40px auto;
  padding: 16px;
  border-radius: 12px;
  background: var(--warn-soft);
  color: var(--warn);
}

/* -------------------------------------------------------------- адаптивность */

@media (max-width: 760px) {
  body {
    padding-left: 12px;
    padding-right: 12px;
  }

  .table-wrap {
    display: none;
  }

  .cards {
    display: grid;
  }

  .field--search {
    grid-column: 1 / -1;
  }

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

  .topbar__actions {
    width: 100%;
  }

  .topbar__actions .btn--primary {
    flex: 1;
  }

  .data-actions {
    justify-content: flex-start;
  }

  .menu__list {
    left: 0;
    right: auto;
  }
}

@media (max-width: 420px) {
  .brand__text h1 {
    font-size: 1.05rem;
  }

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

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* ------------------------------------------------- вход, роли, права */

[hidden] {
  display: none !important;
}

.userbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex-basis: 100%;
  padding-top: 4px;
}

.userbar__name {
  font-size: 0.9rem;
  font-weight: 600;
}

.userbar .btn {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.88rem;
}

.is-locked .topbar__actions {
  display: none;
}

.is-readonly .table__actions,
.is-readonly .table__actions-head,
.is-readonly .card__actions {
  display: none;
}

.login {
  display: grid;
  place-items: center;
  padding: 24px 16px 48px;
}

.login__card {
  display: grid;
  gap: 12px;
  width: min(380px, 100%);
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.login__logo {
  box-sizing: content-box;
  height: 40px;
  width: auto;
  margin: 0 auto;
  padding: 8px 14px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 14px;
}

.login h1 {
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
}

.login__hint {
  margin: -6px 0 6px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

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

@media (max-width: 420px) {
  .login__card {
    padding: 18px;
  }
}

