:root {
  --ink: #1c2430;
  --muted: #5d6b7a;
  --paper: #f3f0e8;
  --card: #fffdf8;
  --line: #e4dccb;
  --sidebar: #1a2330;
  --sidebar-text: #d5dbe3;
  --amber: #b86e00;
  --amber-deep: #8a4e00;
  --ok: #1f7a4d;
  --danger: #9b2c2c;
  --shadow: 0 10px 30px rgba(28, 36, 48, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Segoe UI", "Liberation Sans", "Noto Sans", sans-serif;
  font-size: 15px;
}

a { color: var(--amber-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex: none;
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 22px 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: white;
  margin-bottom: 28px;
}
.brand strong { display: block; font-size: 18px; letter-spacing: 0.04em; }
.brand small { color: #9eabba; }

.brand-mark {
  width: 36px;
  height: 36px;
  border: 2px solid #e0a100;
  border-radius: 50%;
  position: relative;
  flex: none;
}
.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  background: #e0a100;
}
.brand-mark::before { width: 2px; height: 100%; left: 50%; transform: translateX(-50%); }
.brand-mark::after { height: 2px; width: 100%; top: 50%; transform: translateY(-50%); }
.brand-mark.light { border-color: #f2c14e; }

.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar a {
  color: var(--sidebar-text);
  padding: 8px 10px;
  border-radius: 8px;
}
.sidebar a:hover { background: rgba(255, 255, 255, 0.05); text-decoration: none; }
.sidebar a.active { background: rgba(224, 161, 0, 0.18); color: #f6d48a; }
.nav-label {
  margin: 18px 10px 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #7f8b99;
}

.app-main { flex: 1; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  background: rgba(255, 253, 248, 0.9);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title { font-weight: 650; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); }
.topbar-user em { font-style: normal; color: var(--amber-deep); font-size: 12px; }
.btn-logout { color: var(--ink); padding: 0; text-decoration: none; }
.nav-burger { display: none; }

.content { padding: 28px; max-width: 1180px; }

h1 { font-size: 28px; margin: 0 0 8px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 0 0 12px; }
.lead, .muted, .note-text { color: var(--muted); }
.kicker { text-transform: uppercase; letter-spacing: 0.08em; font-size: 12px; color: var(--amber-deep); margin-bottom: 6px; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.note { border-left: 4px solid var(--amber); }

.stat-grid, .split { display: grid; gap: 12px; }
.stat-grid { grid-template-columns: repeat(3, 1fr); margin: 18px 0; }
.split { grid-template-columns: 1fr 1fr; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  color: inherit;
  box-shadow: var(--shadow);
}
.stat:hover { text-decoration: none; border-color: #d7b56a; }
.stat span, .stat small { display: block; color: var(--muted); }
.stat strong { display: block; font-size: 32px; line-height: 1.1; margin-top: 4px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters .form-control, .filters .form-select { max-width: 280px; }
.archive-filters .form-control, .archive-filters .form-select { max-width: 180px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); }

.btn-accent {
  background: var(--amber);
  border: 0;
  color: white;
  border-radius: 8px;
  padding: 8px 14px;
}
.btn-accent:hover { background: var(--amber-deep); color: white; }

.table-wrap { overflow-x: auto; }
.table-meta { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.sheet-wrap { overflow-x: auto; }
.sheet { width: 100%; border-collapse: collapse; background: var(--card); }
.sheet th, .sheet td { border-bottom: 1px solid var(--line); padding: 9px 10px; vertical-align: top; }
.sheet th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 650; }
.sheet tr:hover td { background: #fff8ea; }
.sheet a { text-decoration: underline; text-underline-offset: 2px; font-weight: 650; }
.line-input { width: 110px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; }
.deficit td { background: #fff1ec; }
.tag.warn { color: #8a4b08; border-color: #efd3a8; background: #fff6ea; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mono { font-family: "Liberation Mono", ui-monospace, monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }
.comment { max-width: 280px; color: var(--muted); }
.empty { color: var(--muted); padding: 18px 10px; }
.actions { display: flex; gap: 10px; align-items: center; }
.actions form { margin: 0; }

.tag {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  color: var(--muted);
}
.tag.ok { color: var(--ok); border-color: #b7dfc8; background: #f1faf4; }

.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; margin: 16px 0; }
.facts dt { color: var(--muted); font-size: 12px; }
.facts dd { margin: 0; }
.description { white-space: pre-wrap; }
.link-list { list-style: none; padding: 0; margin: 0; }
.link-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.subplan { color: var(--muted); font-size: 12px; margin-top: 2px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.plain { margin: 0; padding-left: 18px; }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
.json-view {
  max-height: 360px;
  overflow: auto;
  background: #1a2330;
  color: #f4efe4;
  padding: 12px;
  border-radius: 10px;
  font-size: 12px;
}
.form-card input[type="text"],
.form-card input[type="password"],
.form-card input[type="email"],
.form-card input[type="date"],
.form-card input[type="number"],
.form-card select {
  display: block;
  width: min(420px, 100%);
  margin-bottom: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}
.form-card input[type="checkbox"] { margin: 0 8px 12px 0; }
.token-once {
  background: #fff4d8;
  border: 1px dashed var(--amber);
  padding: 10px 12px;
  border-radius: 8px;
  word-break: break-all;
}
.change { display: inline-block; margin-right: 8px; }
.alert { border-radius: 10px; }

.login-body { background: var(--sidebar); }
.login-layout { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 0.9fr; }
.login-aside { color: white; padding: 64px; display: flex; flex-direction: column; justify-content: flex-end; gap: 12px; }
.login-aside h1 { font-size: 48px; }
.login-aside p { max-width: 420px; color: #c5d0dc; }
.login-card { background: var(--paper); margin: 24px; border-radius: 18px; padding: 36px; align-self: center; }
.login-card .form-control { margin-bottom: 12px; }
.login-card .btn { margin-top: 8px; }
.login-card form + form { margin-top: 18px; }
.login-hint, .login-links { margin-top: 14px; }
.print-select { max-width: 360px; display: inline-block; width: auto; }
.print-frame { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: 10px; background: white; margin-top: 12px; }
.print-chooser { align-items: end; }
.col-photo { width: 48px; }
.item-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; background: #efe8d8; display: block; }
.photo-main { max-width: min(480px, 100%); height: auto; border-radius: 12px; background: #efe8d8; }
.photo-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.photo-card { width: 140px; }
.photo-card img { width: 120px; height: 120px; object-fit: cover; border-radius: 8px; background: #efe8d8; }
.photo-card form { display: inline; }
.photo-upload { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.photo-upload input[type="file"] { max-width: 100%; }

.chat-launcher {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  background: var(--amber-deep);
  color: white;
  box-shadow: var(--shadow);
}
.chat-panel {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 40;
  width: min(420px, calc(100vw - 24px));
  height: calc(100vh - 24px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.chat-panel.is-open { display: flex; }
.chat-panel-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.chat-panel-bar a { margin-left: auto; }
.chat-app { display: grid; grid-template-columns: 220px 1fr; gap: 12px; min-height: 70vh; }
.chat-app-panel { grid-template-columns: 1fr; min-height: 0; height: 100%; }
.chat-app-panel .chat-dialogs { max-height: 120px; }
.chat-dialogs, .chat-main {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.chat-panel .chat-dialogs, .chat-panel .chat-main { border: 0; border-radius: 0; box-shadow: none; }
.chat-panel .chat-main { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.chat-dialogs-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.chat-dialogs ul { list-style: none; margin: 0; padding: 0; overflow: auto; max-height: 62vh; }
.chat-dialogs li button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
}
.chat-dialogs li.is-active button, .chat-dialogs li button:hover { background: #f6efe0; }
.chat-log { overflow: auto; min-height: 240px; max-height: 58vh; display: flex; flex-direction: column; gap: 10px; }
.chat-panel .chat-log { max-height: none; flex: 1; min-height: 0; }
.chat-msg { border-radius: 12px; padding: 10px 12px; background: #f7f3ea; }
.chat-msg-user { background: #fff7e4; margin-left: 18px; }
.chat-msg-assistant { margin-right: 18px; }
.chat-msg pre { white-space: pre-wrap; background: #1a2330; color: #f4efe4; padding: 8px; border-radius: 8px; }
.chat-msg code { font-family: ui-monospace, monospace; }
.chat-msg-files { color: var(--muted); font-size: 13px; }
.chat-wizard { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.chat-wizard h3 { font-size: 13px; margin: 0; }
.chat-wizard-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chat-wizard button[disabled], .chat-wizard.is-disabled button { opacity: .55; }
.chat-wizard-avito, .chat-wizard-missing, .chat-wizard-detail { font-size: 12px; }
.chat-wizard-missing, .chat-wizard-detail { color: var(--muted); }
.chat-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  margin: 8px 0;
}
.chat-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chat-actions label { margin: 0; cursor: pointer; }
.chat-previews { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-file {
  display: flex;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 6px;
  max-width: 100%;
}
.chat-file img { width: 42px; height: 42px; object-fit: cover; border-radius: 6px; }
.chat-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.chat-banner, .chat-typing { color: var(--amber-deep); margin: 0 0 8px; }
.chat-main.is-dropping { outline: 2px dashed var(--amber); }
.chat-hint { margin: 8px 0 0; font-size: 12px; }
.chat-empty { color: var(--muted); }

@media (max-width: 900px) {
  .chat-app { grid-template-columns: 1fr; min-height: 0; }
  .chat-dialogs ul { max-height: 160px; }
  .chat-log { max-height: 48vh; }
  .chat-panel { inset: 0; width: auto; height: auto; border-radius: 0; }
  .chat-launcher { right: 12px; bottom: 12px; }
}

@media (max-width: 900px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-105%); transition: transform 0.2s ease; }
  .nav-toggle:checked ~ .app-shell .sidebar { transform: none; }
  .nav-burger { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
  .content { padding: 16px; }
  .stat-grid, .split, .login-layout, .facts { grid-template-columns: 1fr; }
  .login-aside { padding: 28px; min-height: 180px; }
  .login-card { margin: 0 16px 16px; }
  .topbar-user span, .topbar-user em { display: none; }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.picker-page .app-shell { height: 100vh; overflow: hidden; }
.picker-page .app-main { display: flex; flex-direction: column; height: 100vh; min-height: 0; }
.picker-page .content-picker {
  max-width: none;
  padding: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.picker-page .chat-launcher { bottom: calc(var(--picker-dock, 280px) + 12px); }
.picker { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--paper); }
.picker-top { flex: 1; min-height: 0; overflow: auto; padding: 16px 22px 18px; }
.picker-tools { display: flex; gap: 10px; align-items: center; }
.picker-search { flex: 1; }
.picker-search input, .picker-fields input, .picker-fields select, .picker-line input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
}
.picker-tabs, .picker-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.picker-tabs button, .picker-filters button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px;
  color: var(--ink);
}
.picker-tabs button.is-active, .picker-filters button.is-active {
  background: #1a2330;
  color: #f6d48a;
  border-color: #1a2330;
}
.picker-note { min-height: 1.2em; margin: 8px 0; }
.picker-catalog { display: flex; flex-direction: column; gap: 16px; }
.pick-shelf h3, .picker-catalog h2 { margin: 0 0 8px; font-size: 16px; }
.pick-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.pick-card {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 8px;
  align-items: center;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  cursor: pointer;
  min-height: 104px;
}
.pick-card:hover, .pick-card.is-in { border-color: #d7b56a; background: #fff8ea; }
.pick-photo { width: 72px; height: 72px; border-radius: 8px; background: #efe8d8; overflow: hidden; }
.pick-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pick-card strong { display: block; font-size: 13px; line-height: 1.3; }
.pick-code, .pick-price, .pick-wait, .pick-in { display: block; color: var(--muted); font-size: 12px; }
.pick-price { color: var(--ink); font-variant-numeric: tabular-nums; }
.pick-badge { margin-top: 4px; }
.pick-badge-ok { color: var(--ok); border-color: #b7dfc8; background: #f1faf4; }
.pick-badge-wait { color: #8a4b08; border-color: #efd3a8; background: #fff6ea; }
.pick-plus {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--amber);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.picker-dock {
  flex: none;
  height: var(--picker-dock, 280px);
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: 0 -8px 24px rgba(28, 36, 48, 0.05);
}
.picker-dock.is-collapsed { height: 48px !important; }
.picker-dock.is-collapsed .picker-dock-body, .picker-dock.is-collapsed .picker-dock-handle { display: none; }
.picker-dock-handle { height: 8px; cursor: ns-resize; background: linear-gradient(#e4dccb, #e4dccb) center / 42px 3px no-repeat; }
.picker-dock-bar { display: flex; gap: 12px; align-items: center; padding: 0 16px 8px; }
.picker-dock-bar .btn { margin-left: auto; }
.picker-sum { font-variant-numeric: tabular-nums; font-weight: 650; }
.picker-dock-body { overflow: auto; padding: 0 16px 14px; }
.picker-dock-hint { margin-top: 0; }
.picker-line { display: grid; grid-template-columns: minmax(140px, 1.4fr) 90px 120px 110px auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.picker-line-name strong, .picker-line-name span { display: block; }
.picker-line-name span, .picker-line-sum { color: var(--muted); font-size: 12px; }
.picker-fields { display: grid; grid-template-columns: 1.2fr 0.8fr 1fr auto; gap: 8px; align-items: end; margin-top: 8px; }
.picker-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.picker-party-list { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; margin: 0; }
.picker-party-list button { text-align: left; border: 1px solid var(--line); background: white; border-radius: 8px; padding: 6px 8px; }
.picker-result { min-height: 1.2em; margin: 8px 0 0; }

@media (max-width: 900px) {
  .picker-page .content-picker { padding: 0; }
  .picker-top { padding: 12px; }
  .pick-row { grid-template-columns: 1fr; }
  .picker-line, .picker-fields { grid-template-columns: 1fr; }
  .picker-page .chat-launcher { display: none; }
}
