:root {
  color-scheme: dark;
  --bg: #07080e;
  --surface: #0f1120;
  --surface-2: #151834;
  --text: #ededf4;
  --muted: #9a9ec0;
  --border: #23274a;
  --primary: #6870c0;
  --primary-dark: #5a62b4;
  --primary-soft: rgba(104, 112, 192, .18);
  --brand: #a2a6d1;
  --secondary: #31366b;
  --accent: #a2a6d1;
  --danger: #f28b8b;
  --danger-soft: rgba(242, 139, 139, .14);
  --blue: #9fb4ff;
  --blue-soft: rgba(104, 112, 192, .22);
  --orange: #f3b562;
  --orange-soft: rgba(243, 181, 98, .14);
  --green: #7fd6a2;
  --green-soft: rgba(127, 214, 162, .14);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  --sidebar: 236px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0 0 4px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; font-weight: 700; }
h3 { font-size: .95rem; margin: 12px 0 6px; }
p { margin: 0 0 10px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .9em; word-break: break-all; }
pre { white-space: pre-wrap; word-break: break-word; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.num { text-align: right; }

/* layout */
.layout { min-height: 100vh; }
.topbar { display: none; }
.sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar); background: #0a0c17; color: #c9cce6; border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 14px; z-index: 30; }
.brand { font-weight: 800; color: inherit; display: inline-flex; align-items: center; gap: 8px; font-size: 1.05rem; letter-spacing: .01em; }
.brand:hover { text-decoration: none; }
.brand-badge { background: var(--primary); color: #fff; border-radius: 7px; padding: 2px 7px; font-size: .8rem; letter-spacing: .04em; }
.brand-side { color: #fff; padding: 4px 8px 18px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: #b4b8d8; padding: 9px 10px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: rgba(162,166,209,.1); text-decoration: none; color: #fff; }
.nav a.active { background: var(--secondary); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.nav-section { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: #6f74a0; padding: 16px 10px 6px; }
.sidebar-user { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.sidebar-user-name { font-weight: 600; color: #fff; }
.sidebar-user .muted { color: #8085ad; }
.sidebar-user-actions { display: flex; gap: 14px; margin-top: 8px; font-size: .9rem; }
.sidebar-user-actions a, .sidebar-user-actions .linklike { color: #b4b8d8; }
.content { margin-left: var(--sidebar); padding: 28px 32px 60px; max-width: 1400px; }
.content-anon { margin: 0; padding: 40px 16px; display: flex; justify-content: center; align-items: flex-start; min-height: 100vh; flex-direction: column; align-items: center; }
.backdrop { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions, .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

/* cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.grid-detail { grid-template-columns: 1.15fr 1fr; }
.grid-tags { grid-template-columns: 1.4fr 1fr; }
.grid-constructor { grid-template-columns: 1fr 1fr; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* machine cards */
.machine-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.machine-photo { display: block; position: relative; aspect-ratio: 4 / 3; background: #0a0c17; }
.machine-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.no-photo { display: flex; align-items: center; justify-content: center; color: var(--muted); height: 100%; min-height: 120px; font-size: .9rem; background: repeating-linear-gradient(45deg, #11142a 0 10px, #0d1022 10px 20px); border-radius: 8px; }
.no-photo-lg { min-height: 240px; }
.machine-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.machine-body h3 { margin: 0; font-size: 1.05rem; }
.machine-body h3 a { color: var(--text); }
.price-row { display: flex; align-items: baseline; gap: 10px; }
.price { font-weight: 800; font-size: 1.15rem; color: #fff; }
.price-old { color: var(--muted); }
.machine-meta { margin-top: auto; }
.machine-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.status { position: absolute; left: 10px; top: 10px; font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: rgba(7,8,14,.82); color: var(--text); backdrop-filter: blur(4px); text-transform: uppercase; letter-spacing: .04em; }
h1 .status { position: static; font-size: .7rem; vertical-align: middle; border: 1px solid var(--border); }
.status-available { color: var(--green); }
.status-reserved { color: var(--orange); }
.status-sold { color: var(--danger); }
.status-archived { color: var(--muted); }

.gallery-main img { width: 100%; max-height: 460px; object-fit: contain; background: #0a0c17; border-radius: 10px; display: block; }
.gallery-thumbs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.gallery-thumbs img { width: 84px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.prose { white-space: pre-wrap; }
.machine-summary { display: flex; gap: 18px; align-items: flex-start; }
.machine-summary img, .machine-summary .no-photo { width: 180px; height: 135px; object-fit: cover; border-radius: 10px; flex: none; }
.machine-summary h2 { margin-bottom: 2px; font-size: 1.2rem; }
.mini-photo { width: 56px; height: 42px; object-fit: cover; border-radius: 6px; margin-right: 10px; flex: none; }
.cell-machine { display: flex; align-items: center; }

/* photo grid */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-bottom: 12px; }
.photo-item { border: 2px solid transparent; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.photo-item img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.photo-item.is-title { border-color: var(--brand); }
.photo-tools { display: flex; justify-content: space-between; gap: 6px; padding: 6px 8px; font-size: .78rem; flex-wrap: wrap; }

/* badges & chips */
.badge { display: inline-block; font-size: .74rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text); white-space: nowrap; vertical-align: middle; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-orange { background: var(--orange-soft); color: var(--orange); }
.badge-light { background: var(--surface-2); color: var(--muted); }
.badge-dealer { background: var(--blue-soft); color: var(--blue); }
.badge-farmer { background: var(--green-soft); color: var(--green); }
.badge-other { background: var(--surface-2); color: var(--muted); }
.badge-role-superadmin { background: var(--brand); color: #07080e; }
.badge-role-admin { background: var(--blue-soft); color: var(--blue); }
.badge-role-seller { background: var(--green-soft); color: var(--green); }
.badge-role-buyer { background: var(--orange-soft); color: var(--orange); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--secondary); color: #e4e6f7; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid transparent; }
.chip-sm { padding: 1px 8px; font-size: .74rem; }
a.chip:hover { text-decoration: none; background: #3d437f; }
.chip-btn { cursor: pointer; background: transparent; border-color: var(--border); color: var(--muted); font-family: inherit; }
.chip-btn:hover, .chip-btn.on { background: var(--secondary); color: #e4e6f7; border-color: var(--primary); }
.chip-check { cursor: pointer; background: transparent; border-color: var(--border); color: var(--muted); padding: 2px 10px 2px 6px; }
.chip-check input { width: 14px; height: 14px; }
.chip-check:has(input:checked) { background: var(--secondary); color: #e4e6f7; border-color: var(--primary); }
.chip-check input { margin: 0; }
.count-badge { display: inline-block; background: var(--primary); color: #fff; border-radius: 999px; padding: 1px 10px; font-size: .85rem; margin-left: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #3a3f6e; margin-right: 6px; }
.dot-sent, .dot-handed_over { background: var(--green); }
.dot-failed { background: var(--danger); }
.dot-partial, .dot-manual { background: var(--orange); }
.dot-pending { background: var(--blue); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-weight: 600; font-size: .92rem; cursor: pointer; font-family: inherit; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: #1b1f40; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(242,139,139,.4); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 11px; font-size: .82rem; }
.btn-lg { padding: 13px 22px; font-size: 1.02rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 16px; }
.linklike { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font: inherit; font-size: .9em; }
.linklike:hover { text-decoration: underline; }
.linklike.danger { color: var(--danger); }
.icon-btn { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: inherit; padding: 4px 8px; }

/* forms */
.form label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-size: .88rem; font-weight: 600; color: #c9cce6; }
.form label .muted { font-weight: 400; }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea, .filters input, .filters select, .input-sm {
  font: inherit; font-size: .95rem; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: #0a0c17; color: var(--text); width: 100%; }
.form textarea { resize: vertical; min-height: 60px; font-family: inherit; }
.form input:focus, .form select:focus, .form textarea:focus, .filters input:focus, .filters select:focus { outline: 2px solid rgba(104,112,192,.35); border-color: var(--primary); }
.form input[type=file] { padding: 7px; }
.form input:disabled { background: var(--surface); color: var(--muted); }
.input-sm { padding: 5px 8px; font-size: .85rem; width: auto; }
.checkline, .check, .radio { display: inline-flex !important; flex-direction: row !important; align-items: center; gap: 7px; font-weight: 500 !important; cursor: pointer; }
.checkline input, .check input, .radio input { width: auto !important; margin: 0; accent-color: var(--primary); }
.check-row { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 4px 0; }
.radio-group { border: 0; padding: 0; margin: 0 0 12px; }
.radio-group legend { font-size: .88rem; font-weight: 600; color: #c9cce6; margin-bottom: 6px; padding: 0; }
.radio-group .radio { margin-right: 14px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.sticky-actions { position: sticky; bottom: 12px; background: var(--surface); border: 1px solid var(--border); padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--shadow); }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.inline-form label.inline { display: inline-flex; flex-direction: row; align-items: center; gap: 8px; }
.inline-form select, .inline-form input { width: auto; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.filters input[type=search] { flex: 1 1 240px; }
.filters select { width: auto; max-width: 220px; }
.counter { display: block; text-align: right; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; width: 100%; max-width: 400px; box-shadow: var(--shadow); margin-top: 8vh; }
.brand-login { margin-bottom: 18px; }
.login-box h1 { margin-bottom: 16px; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table-scroll { max-height: 420px; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: #0b0d1b; position: sticky; top: 0; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #13162c; }
.table-compact th, .table-compact td { padding: 7px 10px; }
.card .table { margin: -4px 0; }
.row-inactive td { opacity: .55; }
.actions-cell { white-space: nowrap; }
.actions-cell form { display: inline; }
.actions-cell .btn { margin-left: 4px; }
.kv { width: 100%; border-collapse: collapse; }
.kv th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 12px 6px 0; width: 42%; vertical-align: top; font-size: .9rem; }
.kv td { padding: 6px 0; }
.bulk-bar { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; font-size: .9rem; }
.bulk-bar select { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: #0a0c17; color: var(--text); font: inherit; }

/* messengers */
.messengers { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.msg { display: inline-flex; align-items: center; gap: 4px; font-size: .74rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; color: #fff; }
.msg:hover { text-decoration: none; filter: brightness(.92); }
.msg-wa { background: #25d366; }
.msg-vb { background: #7360f2; }
.msg-tg { background: #2aabee; }
.msg-tg.msg-auto { box-shadow: 0 0 0 2px rgba(42,171,238,.45); }
.msg-mail { background: #4b5085; }

/* channel options */
.channel-group { margin-bottom: 12px; }
.channel-group-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.channel-option { display: flex; gap: 10px; align-items: flex-start; padding: 9px 10px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 6px; cursor: pointer; }
.channel-option:hover { background: var(--surface-2); }
.channel-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.channel-option input { margin-top: 4px; accent-color: var(--primary); }
.channel-info { display: flex; flex-direction: column; gap: 3px; }
.channel-name { font-weight: 600; }
.channel-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .8rem; }
.filter-block { margin-bottom: 14px; }
.filter-title { font-weight: 600; font-size: .88rem; margin-bottom: 4px; color: #c9cce6; }
.step { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: #fff; align-items: center; justify-content: center; font-size: .8rem; margin-right: 6px; }
.counts { margin-bottom: 8px; }
.text-block { margin-bottom: 14px; }
.text-block-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-weight: 600; font-size: .88rem; }
.text-block-head span { margin-right: auto; }
.message { background: #0a0c17; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 0; font-family: inherit; font-size: .95rem; }

/* flash */
.flash { padding: 11px 42px 11px 14px; border-radius: 10px; margin-bottom: 16px; position: relative; font-size: .93rem; border: 1px solid transparent; }
.flash-success { background: var(--green-soft); color: var(--green); border-color: rgba(127,214,162,.35); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: rgba(242,139,139,.35); }
.flash-warning { background: var(--orange-soft); color: var(--orange); border-color: rgba(243,181,98,.35); }
.flash-info { background: var(--blue-soft); color: var(--blue); border-color: rgba(104,112,192,.45); }
.flash a { color: inherit; text-decoration: underline; }
.flash-close { position: absolute; right: 8px; top: 6px; background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: inherit; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty-code { font-size: 3rem; font-weight: 800; color: var(--secondary); }
.danger-zone { margin-top: 8px; display: flex; justify-content: flex-end; }
.tag-edit input { width: 170px; }
.role-help div { margin-bottom: 3px; }
.topbar-user { margin-left: auto; font-size: .9rem; }

/* responsive */
@media (max-width: 1100px) {
  .grid-2, .grid-detail, .grid-tags, .grid-constructor { grid-template-columns: 1fr; }
  .row-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .topbar { display: flex; align-items: center; gap: 10px; background: #0a0c17; color: #fff; border-bottom: 1px solid var(--border); padding: 10px 12px; position: sticky; top: 0; z-index: 25; }
  .topbar .brand { color: #fff; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 29; }
  .content { margin-left: 0; padding: 16px 14px 60px; }
  .row-2, .row-3 { grid-template-columns: 1fr; }
  .machine-summary { flex-direction: column; }
  .machine-summary img { width: 100%; height: auto; max-height: 240px; }
  .page-head { flex-direction: column; }
  :root { font-size: 15px; }
  .filters select { max-width: 100%; }
}
