/* Панель администратора «Прим Green». Все цвета и размеры – в :root (сняты с логотипа). */
:root {
  --c-bg: #f5efe4;
  --c-surface: #fffdf9;
  --c-surface-2: #faf6ef;
  --c-border: #e5dac8;
  --c-text: #2a1a10;
  --c-muted: #6b5a4b;
  --c-accent: #0f5a30;
  --c-accent-hover: #0b4625;
  --c-accent-soft: #e4efe5;
  --c-accent-text: #ffffff;
  --c-danger: #a8321f;
  --c-danger-soft: #fbebe7;
  --c-warn: #8a5a0a;
  --c-warn-soft: #faf0dc;
  --c-info: #24618f;
  --c-info-soft: #e6eff7;
  --c-neutral-soft: #efe7da;
  --c-sidebar: #2e1a0f;
  --c-sidebar-text: #efe3d2;
  --c-sidebar-muted: #c2ab90;
  --c-sidebar-active: #0f5a30;
  --c-overlay: rgba(42, 26, 16, 0.45);

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.2);
  --sidebar-w: 248px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs: 15px;
  --fs-sm: 13px;
  --tap: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: var(--fs);
  line-height: 1.45;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--c-accent); }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 18px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 16px; margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--c-muted); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.error-text { color: var(--c-danger); }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 8px 14px;
  font: inherit; font-weight: 500; line-height: 1.2;
  border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  background: var(--c-surface); color: var(--c-text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--c-surface-2); }
.btn:focus-visible, .input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--c-accent); outline-offset: 1px;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--c-accent); border-color: var(--c-accent); color: var(--c-accent-text); }
.btn-primary:hover { background: var(--c-accent-hover); }
.btn-danger { color: var(--c-danger); border-color: #e6b9b3; }
.btn-danger:hover { background: var(--c-danger-soft); }
.btn-sm { min-height: 34px; padding: 5px 10px; font-size: var(--fs-sm); }
.btn-link { border: 0; background: none; color: var(--c-accent); padding: 4px 0; min-height: 0; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-sm); color: var(--c-muted); }
label.field > span { font-weight: 500; }
label.field > span.hint { font-weight: 400; }
.input, select, textarea {
  font: inherit; font-size: var(--fs); color: var(--c-text);
  min-height: var(--tap); padding: 8px 10px; width: 100%;
  border: 1px solid var(--c-border); border-radius: var(--radius-sm); background: var(--c-surface);
}
textarea { resize: vertical; min-height: 72px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; min-height: var(--tap); }
.check input { width: 18px; height: 18px; accent-color: var(--c-accent); }
.radio-group { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-card {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: var(--tap);
  border: 1px solid var(--c-border); border-radius: var(--radius-sm); cursor: pointer; background: var(--c-surface);
}
.radio-card input { accent-color: var(--c-accent); width: 18px; height: 18px; }
.radio-card:has(input:checked) { border-color: var(--c-accent); background: var(--c-accent-soft); }

/* ---------- раскладка ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--c-sidebar); color: var(--c-sidebar-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { margin: 14px 14px 10px; padding: 10px 12px; border-radius: var(--radius); background: var(--c-surface); color: var(--c-text); font-weight: 600; font-size: 14px; }
.brand img { display: block; width: 150px; max-width: 100%; height: auto; }
.brand small { display: block; font-weight: 400; color: var(--c-muted); font-size: 12px; margin-top: 6px; }
.nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--c-sidebar-text); text-decoration: none; min-height: var(--tap);
}
.nav a:hover { background: rgba(255, 255, 255, 0.06); }
.nav a.active { background: var(--c-sidebar-active); color: #fff; }
.nav .count {
  min-width: 22px; padding: 1px 7px; border-radius: 11px; font-size: 12px; text-align: center;
  background: rgba(255, 255, 255, 0.15); color: #fff;
}
.sidebar-bottom { margin-top: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.saby-box {
  border: 1px solid rgba(255, 255, 255, 0.12); border-radius: var(--radius); padding: 12px;
  font-size: var(--fs-sm); display: flex; flex-direction: column; gap: 6px;
}
.saby-box .title { color: #fff; font-weight: 600; }
.saby-box .row { color: var(--c-sidebar-muted); }
.saby-box .row b { color: var(--c-sidebar-text); font-weight: 500; }
.saby-box .err { color: #ffb4a8; word-break: break-word; }
.saby-box .btn { width: 100%; background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.3); }
.saby-box .btn:hover { background: rgba(255, 255, 255, 0.08); }
.user-box { font-size: var(--fs-sm); color: var(--c-sidebar-muted); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.user-box b { color: var(--c-sidebar-text); font-weight: 500; display: block; }
.user-box .btn { background: transparent; color: var(--c-sidebar-text); border-color: rgba(255, 255, 255, 0.25); }

.topbar { display: none; }
.main { flex: 1; min-width: 0; padding: 24px 28px 40px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: 8px; text-decoration: none; font-size: var(--fs-sm); }

.card {
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card + .card { margin-top: 16px; }

.filters {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; align-items: end;
  margin-bottom: 14px;
}
.filters .btn { align-self: end; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button {
  font: inherit; font-size: var(--fs-sm); padding: 7px 12px; min-height: 36px;
  border: 1px solid var(--c-border); background: var(--c-surface); border-radius: 18px; cursor: pointer; color: var(--c-text);
}
.tabs button.active { background: var(--c-accent); border-color: var(--c-accent); color: #fff; }

/* ---------- таблицы ---------- */
.table-wrap { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--c-border); }
.table th { font-size: var(--fs-sm); font-weight: 600; color: var(--c-muted); background: var(--c-surface-2); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--c-surface-2); }
.table tr.unread td { background: #eef5ee; }
.table td.num, .table th.num { text-align: right; white-space: nowrap; }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions .btn + .btn { margin-left: 6px; }
@media (min-width: 761px) and (max-width: 1400px) {
  .table td.actions { white-space: normal; width: 1%; }
  .table td.actions .btn { display: flex; width: 100%; }
  .table td.actions .btn + .btn { margin-left: 0; margin-top: 6px; }
}
.table tr.is-hidden td { color: var(--c-muted); }
.empty { padding: 28px 16px; text-align: center; color: var(--c-muted); }

.thumb {
  width: 48px; height: 48px; border-radius: var(--radius-sm); object-fit: cover; background: var(--c-neutral-soft);
  display: block; border: 1px solid var(--c-border);
}
.thumb-empty { display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--c-muted); }

/* ---------- значки ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 11px; font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--c-neutral-soft); color: var(--c-text);
}
.badge.st-new { background: var(--c-info-soft); color: var(--c-info); }
.badge.st-accepted { background: var(--c-warn-soft); color: var(--c-warn); }
.badge.st-assembled { background: var(--c-accent-soft); color: var(--c-accent-hover); }
.badge.st-delivery { background: #e9e6f6; color: #574a9b; }
.badge.st-cancelled { background: var(--c-danger-soft); color: var(--c-danger); }
.badge.green { background: var(--c-accent-soft); color: var(--c-accent-hover); }
.badge.red { background: var(--c-danger-soft); color: var(--c-danger); }
.badge.blue { background: var(--c-info-soft); color: var(--c-info); }
.badge.gray { background: var(--c-neutral-soft); color: var(--c-muted); }
.unread-dot {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 11px;
  background: var(--c-accent); color: #fff; font-size: 12px; font-weight: 600; white-space: nowrap;
}

/* ---------- карточка заявки ---------- */
.order-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: var(--fs); }
.kv dt { color: var(--c-muted); }
.kv dd { margin: 0; word-break: break-word; }
.diff { color: var(--c-warn); font-weight: 600; }
.total-row { display: flex; justify-content: flex-end; gap: 12px; padding: 12px 4px 0; font-size: 16px; }
.total-row b { font-weight: 600; }

.chat { display: flex; flex-direction: column; height: 560px; max-height: 75vh; padding: 0; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--c-border); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--c-surface-2); }
.msg { max-width: 85%; padding: 8px 11px; border-radius: 10px; background: var(--c-surface); border: 1px solid var(--c-border); }
.msg.staff { align-self: flex-end; background: var(--c-accent-soft); border-color: #c5dcc9; }
.msg .meta { font-size: 12px; color: var(--c-muted); margin-bottom: 2px; }
.msg .text { white-space: pre-wrap; word-break: break-word; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--c-border); }
.chat-form textarea { min-height: var(--tap); height: 44px; flex: 1; }

/* ---------- баннеры ---------- */
.banner-list { display: flex; flex-direction: column; gap: 10px; }
.banner-item { display: grid; grid-template-columns: 160px minmax(0, 1fr) auto; gap: 14px; align-items: center; }
.banner-img { width: 160px; height: 80px; object-fit: cover; border-radius: var(--radius-sm); background: var(--c-neutral-soft); border: 1px solid var(--c-border); display: block; }
.banner-list .card + .card { margin-top: 0; }
.banner-img.thumb-empty { display: flex; }
.check input { flex: 0 0 auto; }
.banner-item .controls { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- окно ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: var(--c-overlay); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--c-surface); border-radius: 10px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column;
}
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--c-border); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal .close { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--c-muted); min-width: var(--tap); min-height: var(--tap); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.photo-edit { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.photo-edit img { width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--c-border); background: var(--c-neutral-soft); }
.shop-checks { max-height: 260px; overflow-y: auto; border: 1px solid var(--c-border); border-radius: var(--radius-sm); padding: 4px 10px; }
.shop-checks .check { display: flex; }
.hint { font-size: var(--fs-sm); color: var(--c-muted); }

/* ---------- уведомления ---------- */
#toast-root { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: var(--c-sidebar); color: #fff; padding: 11px 15px; border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: var(--fs-sm); max-width: 380px; }
.toast.error { background: var(--c-danger); }

/* ---------- вход ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 24px; }
.login-card h1 { font-size: 20px; }
.login-logo { width: 180px; height: auto; align-self: center; margin-bottom: 4px; }
body.login-page { background: #e9dfcd; }
.login-card .btn { width: 100%; }
.password-once { font: 600 20px/1.3 ui-monospace, Consolas, monospace; letter-spacing: 1px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--c-accent-soft); color: var(--c-text); user-select: all; }

.loading { padding: 32px; text-align: center; color: var(--c-muted); }

/* ---------- планшет ---------- */
@media (max-width: 1100px) {
  .order-grid { grid-template-columns: 1fr; }
  .chat { height: 480px; }
}

/* ---------- телефон ---------- */
@media (max-width: 760px) {
  :root { --fs: 15px; --tap: 44px; }
  .layout { display: block; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    position: sticky; top: 0; z-index: 30; padding: 8px 12px;
    background: var(--c-sidebar); color: #fff;
  }
  .topbar .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.3); min-height: 44px; min-width: 44px; }
  .sidebar .btn-sm { min-height: 44px; }
  .sidebar {
    position: fixed; z-index: 40; top: 0; left: 0; bottom: 0; height: auto;
    width: min(300px, 86vw); transform: translateX(-100%); transition: transform 0.2s ease;
  }
  .layout.menu-open .sidebar { transform: none; }
  .menu-backdrop { position: fixed; inset: 0; background: var(--c-overlay); z-index: 35; }
  .main { padding: 14px 12px 32px; }
  h1 { font-size: 19px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .wide { grid-column: 1 / -1; }

  /* таблицы превращаются в карточки */
  .table-wrap { background: none; border: 0; box-shadow: none; overflow: visible; }
  table.table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }
  .table tr {
    background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 10px; padding: 8px 12px;
  }
  .table td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--c-muted); font-size: var(--fs-sm); text-align: left; flex: 0 0 auto; max-width: 45%; }
  .table td[data-label=""]::before, .table td:not([data-label])::before { display: none; }
  .table td.primary { font-weight: 600; font-size: 16px; text-align: left; justify-content: flex-start; padding-top: 6px; }
  .table td.primary::before { display: none; }
  .table td.primary .small { font-weight: 400; font-size: var(--fs-sm); }
  .table td.num { text-align: right; }
  .table td.actions { justify-content: flex-start; flex-wrap: wrap; gap: 6px; padding-top: 8px; text-align: left; }
  .table td.actions::before { display: none; }
  .table td.actions .btn + .btn { margin-left: 0; }
  .table td.media { justify-content: flex-start; }
  .table td.media::before { display: none; }
  .table tr.unread { border-color: var(--c-accent); }
  .table tr.unread td { background: none; }
  .empty { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); }

  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dt { margin-top: 8px; font-size: var(--fs-sm); }
  .chat { height: 70vh; }
  .banner-item { grid-template-columns: 96px minmax(0, 1fr); }
  .banner-img { width: 96px; height: 60px; }
  .banner-item .controls { grid-column: 1 / -1; justify-content: flex-start; }

  .modal-backdrop { padding: 8px; align-items: flex-end; }
  .modal { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); }
  .form-row { grid-template-columns: 1fr; }
  .modal-foot .btn { flex: 1; }
  /* сверху, чтобы не закрывать кнопки окна внизу экрана */
  #toast-root { left: 12px; right: 12px; top: 12px; bottom: auto; }
}
