/* Веб-версия Inventory — оформление. Светлая и тёмная темы по настройке системы. */

:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --pane: #ffffff;
  --pane-2: #f9fafb;
  --line: #e3e5e8;
  --text: #1c1e21;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101214;
    --pane: #1a1d21;
    --pane-2: #202428;
    --line: #2c3137;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --accent: #60a5fa;
    --accent-soft: #1e3a5f;
    --danger: #f87171;
    --ok: #4ade80;
    --warn: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
[hidden] { display: none !important; }

/* ---------- Раскладка: три колонки ---------- */
.app {
  display: grid;
  grid-template-columns: 300px minmax(280px, 420px) minmax(0, 1fr);
  height: 100dvh;
  gap: 1px;
  background: var(--line);
}
.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--pane);
}
.pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  min-height: 52px;
  flex: none;
}

/* ---------- Кнопки ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--pane-2);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  line-height: 1.2;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-small { padding: 3px 9px; font-size: 13px; }
.btn-icon {
  width: 34px; height: 34px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px;
}
/* Кнопки «назад» — только на узком экране (правило после .btn-icon, чтобы победить его display) */
.btn.only-narrow { display: none; }

/* ---------- Левая колонка ---------- */
.brand { display: flex; align-items: center; gap: 8px; flex: 1; font-weight: 600; font-size: 17px; }
.brand-icon {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  display: inline-block;
}
.storages { flex: none; max-height: 40%; overflow: auto; border-bottom: 1px solid var(--line); }
.storage {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; cursor: pointer;
  border-left: 3px solid transparent;
}
.storage:hover { background: var(--pane-2); }
.storage.active { background: var(--accent-soft); border-left-color: var(--accent); }
.storage-icon { font-size: 18px; width: 22px; text-align: center; flex: none; }
.storage-main { flex: 1; min-width: 0; }
.storage-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.storage-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.storage-sub.err { color: var(--danger); }
.storage-actions { display: flex; gap: 4px; flex: none; }
.storage-actions .btn-icon { width: 28px; height: 28px; font-size: 15px; }
.storage-actions .btn-icon.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.storages-empty { padding: 20px 14px; color: var(--muted); font-size: 14px; }
.storages-empty .btn { margin-top: 10px; }

.tags-block { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tags-head { display: flex; align-items: center; padding: 8px 12px 4px; }
.tags-title { flex: 1; font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tags-tree { flex: 1; overflow: auto; padding: 0 6px 12px; }
.tag-row {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 4px; border-radius: 6px; cursor: pointer;
  user-select: none; -webkit-user-select: none;
}
.tag-row:hover { background: var(--pane-2); }
.tag-row.selected { background: var(--accent-soft); }
.tag-toggle {
  width: 20px; height: 20px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 11px; border: 0; background: none; padding: 0; cursor: pointer;
}
.tag-toggle.leaf { visibility: hidden; }
.tag-toggle.open { transform: rotate(90deg); }
.tag-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,.15); }
.tag-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag-check { flex: none; width: 18px; height: 18px; accent-color: var(--accent); margin: 0; cursor: pointer; }
.tag-children { margin-left: 18px; }
.tag-children[hidden] { display: none; }

.pane-foot { flex: none; padding: 6px 12px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); }

/* ---------- Средняя колонка ---------- */
.search-box { flex: 1; min-width: 0; }
.search-box input {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--pane-2);
}
.sort-box select {
  padding: 6px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--pane-2);
}
.items-summary { padding: 6px 12px 0; font-size: 12px; color: var(--muted); }
.selected-tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 12px; }
.selected-tags:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px 2px 6px; border-radius: 999px;
  font-size: 12px; background: var(--pane-2); border: 1px solid var(--line);
  cursor: pointer;
}
.chip .tag-dot { width: 10px; height: 10px; }
.items-list { flex: 1; overflow: auto; }
.item-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.item-row:hover { background: var(--pane-2); }
.item-row.active { background: var(--accent-soft); }
.item-mark { width: 18px; flex: none; text-align: center; font-size: 15px; }
.mark-1 { color: var(--danger); }
.mark-2 { color: var(--warn); }
.mark-3 { color: var(--ok); }
.item-photo {
  width: 48px; height: 48px; flex: none; border-radius: 8px;
  background: var(--pane-2); border: 1px solid var(--line);
  object-fit: cover; display: block;
}
.item-photo.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 18px; }
.item-main { flex: 1; min-width: 0; }
.item-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-id { font-size: 11px; color: var(--muted); }
.items-empty { padding: 30px 16px; color: var(--muted); text-align: center; }
.items-sentinel { height: 1px; }

/* ---------- Карточка ---------- */
.card-head-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-actions { display: flex; gap: 6px; }
.card { flex: 1; overflow: auto; padding: 16px 20px 40px; }
.card-empty { color: var(--muted); text-align: center; padding: 60px 0; }
.card-title { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 4px; font-size: 22px; font-weight: 600; line-height: 1.25; }
.card-title .item-mark { font-size: 20px; margin-top: 3px; }
.card-id { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.card-tags .chip { cursor: default; }
.field {
  display: grid; grid-template-columns: minmax(120px, 30%) 1fr; gap: 6px 14px;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.field-name { color: var(--muted); font-size: 13px; padding-top: 2px; }
.field-value { white-space: pre-wrap; word-break: break-word; }
.field-value.num { font-variant-numeric: tabular-nums; }
.field-photos { grid-column: 1 / -1; }
.photos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.photos-grid img, .photos-grid .photo-placeholder {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px;
  background: var(--pane-2); border: 1px solid var(--line); cursor: zoom-in; display: block;
}
.photo-placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; cursor: default; }

/* ---------- Диалоги ---------- */
.dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px;
  background: var(--pane); color: var(--text); width: min(520px, 92vw);
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog h2 { margin: 0 0 8px; font-size: 18px; }
.dialog .hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.dialog textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--pane-2); resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px;
}
.dialog-error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

/* ---------- Фото на весь экран ---------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.lightbox img { max-width: 96vw; max-height: 92vh; object-fit: contain; }
.lightbox-close, .lightbox-nav {
  position: absolute; background: rgba(255,255,255,.12); color: #fff; border: 0;
  border-radius: 50%; width: 44px; height: 44px; font-size: 26px; cursor: pointer;
}
.lightbox-close { top: 12px; right: 12px; }
.lightbox-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 12px; top: 50%; transform: translateY(-50%); }
.lightbox-caption { position: absolute; bottom: 12px; left: 0; right: 0; text-align: center; color: #ddd; font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #111; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; z-index: 60; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.3);
}

/* ---------- Узкий экран: одна колонка ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .app .pane { display: none; }
  .app[data-pane="tags"] .pane-tags { display: flex; }
  .app[data-pane="items"] .pane-items { display: flex; }
  .app[data-pane="card"] .pane-card { display: flex; }
  .btn.only-narrow { display: inline-flex; }
  .storages { max-height: 45%; }
  .card { padding: 14px 14px 40px; }
  .field { grid-template-columns: 1fr; gap: 2px; }
}
