:root {
  --blue: #189eff;
  --blue-dark: #0870ff;
  --blue-soft: #e7f4ff;
  --navy: #142132;
  --navy-2: #1d2e44;
  --text: #1f2532;
  --text-2: #52667a;
  --muted: #758ca3;
  --border: #d1d9e0;
  --border-soft: #e6ebf0;
  --bg: #f0f2f5;
  --card: #fff;
  --ok: #37d046;
  --ok-text: #1f8a2a;
  --ok-bg: #e7f9e9;
  --warn: #ffb75d;
  --warn-text: #a85f00;
  --warn-bg: #fff4e5;
  --error: #de294c;
  --error-bg: #fbe5ea;
  --info-text: #0870ff;
  --info-bg: #e7f4ff;
  --radius: 6px;
  --topbar: 52px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 600; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: #f3f5f7; border: 1px solid var(--border-soft); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
code.block { display: block; padding: 8px 10px; margin-top: 4px; font-weight: 400; }
code.copy { cursor: copy; }
code.copied { background: var(--ok-bg); border-color: var(--ok); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.text-error { color: var(--error); }
.mt { margin-top: 20px; }
[hidden] { display: none !important; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar); display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--navy); color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.2); }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 16px; width: 208px; letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.brand strong { color: var(--blue); font-weight: 700; }
.brand-dark { color: var(--text); font-size: 20px; width: auto; }
.shop-switch { display: flex; align-items: center; gap: 8px; }
.shop-switch label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #9fb1c4; }
.shop-switch select { background: var(--navy-2); color: #fff; border: 1px solid #34465d; min-width: 240px; height: 32px; }
.topbar .btn-ghost { color: #d5e0ea; border-color: #34465d; background: transparent; }
.topbar .btn-ghost:hover { background: var(--navy-2); color: #fff; }
.topbar-link { color: #9fb1c4; font-size: 13px; }
.spacer { flex: 1; }
.menu { position: relative; }
.menu summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius); }
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { background: var(--navy-2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--blue); display: grid; place-items: center; font-weight: 600; }
.menu-panel { position: absolute; right: 0; top: 44px; min-width: 220px; background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(20,33,50,.15); overflow: hidden; }
.menu-head { padding: 10px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border-soft); }
.menu-panel a, .menu-panel button { display: block; width: 100%; text-align: left; padding: 9px 14px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.menu-panel a:hover, .menu-panel button:hover { background: var(--blue-soft); text-decoration: none; }

/* Layout */
.layout { display: flex; min-height: calc(100vh - var(--topbar)); }
.sidebar { width: 224px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--border); padding: 12px 0; display: flex; flex-direction: column; position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); }
.sidebar > a { display: flex; align-items: center; gap: 12px; padding: 10px 20px; color: var(--text-2); font-weight: 500; border-left: 3px solid transparent; }
.sidebar > a:hover { background: #f6f8fa; text-decoration: none; color: var(--text); }
.sidebar > a.active { color: var(--blue-dark); background: var(--blue-soft); border-left-color: var(--blue); }
.sidebar-foot { margin-top: auto; padding: 16px 20px; border-top: 1px solid var(--border-soft); }
.sidebar-foot .label, .label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }
.shop-name { font-weight: 600; margin-top: 2px; }
.content { flex: 1; min-width: 0; padding: 24px 28px 48px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.back { font-size: 12px; color: var(--muted); display: inline-block; margin-bottom: 2px; }
.product-head { display: flex; align-items: center; gap: 16px; }
.product-head img { width: 64px; height: 64px; object-fit: contain; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }

/* Cards & grids */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card-flush { padding: 0; overflow: hidden; }
.card-title { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; font-weight: 600; border-bottom: 1px solid var(--border); background: #fafbfc; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 20px; border-top: 1px solid var(--border); background: #fafbfc; }
.grid { display: grid; gap: 20px; align-items: start; }
.grid > .card, .grid > div > .card:last-child { margin-bottom: 0; }
.grid > div > .card { margin-bottom: 20px; }
.grid { margin-bottom: 20px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-main-side { grid-template-columns: minmax(0, 1fr) 340px; }
.grid-side-main { grid-template-columns: 300px minmax(0, 1fr); }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.danger-zone { border-color: #f3c2cc; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpis-6 { grid-template-columns: repeat(6, 1fr); }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.kpi-accent { border-top: 3px solid var(--blue); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi-value { font-size: 24px; font-weight: 600; margin-top: 4px; letter-spacing: -.3px; }
.kpi-value-sm { font-size: 18px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chart-box { height: 280px; position: relative; }
.mini-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; text-align: center; }
.mini-kpis div { background: #f6f8fa; border-radius: var(--radius); padding: 8px 4px; }
.mini-kpis strong { display: block; font-size: 16px; }
.mini-kpis span { font-size: 11px; color: var(--muted); }
.meter { height: 8px; background: var(--border-soft); border-radius: 4px; overflow: hidden; }
.meter div { height: 100%; background: linear-gradient(90deg, var(--blue), var(--blue-dark)); }
.meter-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); margin-top: 6px; }

/* Lists */
.list { list-style: none; margin: 0 0 12px; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); }
.list li:last-child { border-bottom: 0; }
.status-list li span:first-child { display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot-warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.rank { margin: 0; padding-left: 20px; }
.rank li { padding: 5px 0; }
.rank li span { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.rank li strong { float: right; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: auto 1fr; gap: 0 8px; padding: 7px 0; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.feed li:last-child { border-bottom: 0; }
.feed li .muted { grid-column: 2; }
.dir { font: 600 10px/1 ui-monospace, Menlo, monospace; padding: 4px 6px; border-radius: 4px; white-space: nowrap; align-self: start; }
.dir-in { background: #e9e3ff; color: #5b3fd6; }
.dir-out { background: var(--blue-soft); color: var(--blue-dark); }
.dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 0; }
.dl dt { color: var(--muted); font-size: 12px; padding-top: 2px; }
.dl dd { margin: 0; }
pre.code { background: var(--navy); color: #d5e0ea; padding: 16px; border-radius: var(--radius); overflow: auto; max-height: 600px; font: 12px/1.5 ui-monospace, Menlo, monospace; margin: 0; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); background: #fafbfc; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table tbody tr:nth-child(even) { background: #fbfcfd; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-click tbody tr { cursor: pointer; }
.table-click tbody tr:hover { background: var(--blue-soft); }
.table .num { text-align: right; white-space: nowrap; }
.table tfoot td { border-top: 1px solid var(--border); border-bottom: 0; background: #fafbfc; }
.table tfoot .total td { font-weight: 600; font-size: 15px; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.table .thumb { width: 52px; padding-right: 0; }
.thumb img { width: 40px; height: 40px; object-fit: contain; border-radius: 4px; border: 1px solid var(--border-soft); background: #fff; display: block; }
.price-table td { padding: 6px 10px; }
.price-table input, .price-table select { height: 32px; }
.price-table input[type=number] { width: 110px; text-align: right; }
.price-table select { min-width: 220px; }

/* Badges */
.badge { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok-text); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-info { background: var(--info-bg); color: var(--info-text); }
.badge-muted { background: #eef1f4; color: var(--text-2); }

/* Status panels on order detail */
.status-panels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.status-panel { margin: 0; }
.status-current { margin: 8px 0 14px; }
.status-current .badge { font-size: 14px; padding: 4px 12px; }
.transitions { display: flex; flex-wrap: wrap; gap: 6px; }

/* Forms */
label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 14px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; height: 36px; padding: 0 10px; font: inherit; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 4px; }
input:focus, select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(24,158,255,.15); }
input:disabled, fieldset:disabled input { background: #f6f8fa; color: var(--text-2); }
fieldset { border: 0; padding: 0; margin: 0; }
.hint { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; height: auto; margin: 0; }
.segmented { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.segmented label { display: flex; gap: 8px; align-items: center; margin: 0; padding: 8px 12px; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }
.segmented input { width: auto; height: auto; margin: 0; }
.segmented label:has(input:checked) { border-color: var(--blue); background: var(--blue-soft); color: var(--text); }
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; }
.toolbar input[type=search] { max-width: 420px; margin: 0; }
.toolbar select { width: auto; margin: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { margin: 0; }
.inline-form { position: relative; }
.inline-form summary { list-style: none; }
.inline-form summary::-webkit-details-marker { display: none; }
.inline-form form { position: absolute; right: 0; top: 34px; z-index: 5; display: flex; gap: 6px; background: #fff; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(20,33,50,.12); width: 280px; }
.inline-form input { margin: 0; height: 30px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 16px; font: 500 14px Inter, system-ui, sans-serif; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f6f8fa; text-decoration: none; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn-danger:hover { background: #c01e3e; }
.btn-danger-ghost { color: var(--error); background: transparent; border-color: transparent; }
.btn-danger-ghost:hover { background: var(--error-bg); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: progress; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }
.alert-success { background: var(--ok-bg); border-color: #b5ecbb; color: var(--ok-text); }
.alert-error { background: var(--error-bg); border-color: #f3c2cc; color: #a3112e; }
.alert-info { background: var(--info-bg); border-color: #b8dfff; color: #0a4fa8; }

.pager { display: flex; justify-content: center; align-items: center; gap: 16px; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(135deg, var(--navy) 0%, #1c3a5e 100%); padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 10px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card .muted { margin: 4px 0 24px; }

@media (max-width: 1200px) {
  .kpis-6 { grid-template-columns: repeat(3, 1fr); }
  .grid-main-side, .grid-side-main { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { padding: 16px; }
  .kpis, .status-panels, .grid-2 { grid-template-columns: 1fr 1fr; }
  .brand { width: auto; }
  .brand span, .topbar-link, .shop-switch label { display: none; }
  .shop-switch select { min-width: 0; width: 140px; }
  .card-flush { overflow-x: auto; }
}

/* Language switch */
.lang-menu summary { gap: 6px; padding: 6px 8px; color: #d5e0ea; font-size: 12px; font-weight: 600; }
.lang-menu .caret { opacity: .7; }
.flag { width: 20px; height: 14px; border-radius: 2px; object-fit: cover; box-shadow: 0 0 0 1px rgba(0,0,0,.15); display: inline-block; vertical-align: middle; }
.lang-menu .menu-panel { min-width: 170px; }
.lang-menu .menu-panel button { display: flex; align-items: center; gap: 10px; }
.lang-menu .menu-panel button.current { font-weight: 600; }
.lang-menu .check-mark { margin-left: auto; color: var(--blue); }
.login-lang { position: fixed; top: 16px; right: 16px; }
.login-lang .lang-menu summary:hover { background: rgba(255,255,255,.1); }
@media (max-width: 860px) { .user-name, .lang-code { display: none; } }

/* Active shop box opens the endpoint dialog */
button.sidebar-foot { display: block; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--border-soft); font: inherit; color: inherit; cursor: pointer; }
button.sidebar-foot:hover { background: #f6f8fa; }
.sidebar-foot-link { margin-top: 6px; font-size: 12px; font-weight: 500; color: var(--blue-dark); }

/* Modal */
.modal { width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 64px); padding: 0; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 24px 64px rgba(20,33,50,.3); color: var(--text); }
.modal::backdrop { background: rgba(20,33,50,.45); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--border); background: #fafbfc; position: sticky; top: 0; }
.modal-head h2 { margin: 0 0 2px; }
.modal-body { padding: 16px 20px 20px; }
.modal-body > p { margin-top: 0; }
.endpoint { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.endpoint + .endpoint { margin-top: 16px; }
.endpoint-head { display: flex; align-items: center; gap: 10px; }
.method { font: 700 11px/1 ui-monospace, Menlo, monospace; background: var(--ok-bg); color: var(--ok-text); padding: 4px 7px; border-radius: 4px; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row code.block { flex: 1; margin: 0; }
.endpoint-meta { margin: 14px 0; grid-template-columns: 100px 1fr; font-size: 13px; }
.payload-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.btn-copied { background: var(--ok-bg) !important; border-color: var(--ok) !important; color: var(--ok-text) !important; }
