:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #f8f8f6;
  --hover: rgba(0, 0, 0, .04);
  --border: rgba(0, 0, 0, .09);
  --border-strong: rgba(0, 0, 0, .16);
  --text: #1f1f1d;
  --text-2: #5f5e5a;
  --text-3: #8a8984;
  --accent: #185fa5;
  --accent-bg: #e6f1fb;
  --accent-text: #0c447c;
  --success: #3b6d11;
  --success-bg: #eaf3de;
  --warning: #854f0b;
  --warning-bg: #faeeda;
  --danger: #a32d2d;
  --danger-bg: #fcebeb;
  --danger-fill: #d43c3b;
  --radius: 8px;
  --sidebar: 232px;
  --chip-blue: #e6f1fb; --chip-blue-t: #0c447c;
  --chip-violet: #eeedfe; --chip-violet-t: #3c3489;
  --chip-green: #eaf3de; --chip-green-t: #27500a;
  --chip-orange: #faece7; --chip-orange-t: #712b13;
  --chip-magenta: #fbeaf0; --chip-magenta-t: #72243e;
  --chip-aqua: #e1f5ee; --chip-aqua-t: #085041;
  --chip-yellow: #faeeda; --chip-yellow-t: #633806;
  --chip-red: #fcebeb; --chip-red-t: #791f1f;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #161615;
  --surface: #1f1f1d;
  --surface-2: #262624;
  --hover: rgba(255, 255, 255, .05);
  --border: rgba(255, 255, 255, .09);
  --border-strong: rgba(255, 255, 255, .18);
  --text: #ecebe6;
  --text-2: #b4b2a9;
  --text-3: #888780;
  --accent: #85b7eb;
  --accent-bg: #0c447c;
  --accent-text: #e6f1fb;
  --success: #97c459;
  --success-bg: #27500a;
  --warning: #ef9f27;
  --warning-bg: #633806;
  --danger: #f09595;
  --danger-bg: #791f1f;
  --danger-fill: #e24b4a;
  --chip-blue: #0c447c; --chip-blue-t: #e6f1fb;
  --chip-violet: #3c3489; --chip-violet-t: #eeedfe;
  --chip-green: #27500a; --chip-green-t: #eaf3de;
  --chip-orange: #712b13; --chip-orange-t: #faece7;
  --chip-magenta: #72243e; --chip-magenta-t: #fbeaf0;
  --chip-aqua: #085041; --chip-aqua-t: #e1f5ee;
  --chip-yellow: #633806; --chip-yellow-t: #faeeda;
  --chip-red: #791f1f; --chip-red-t: #fcebeb;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #161615; --surface: #1f1f1d; --surface-2: #262624; --hover: rgba(255, 255, 255, .05);
    --border: rgba(255, 255, 255, .09); --border-strong: rgba(255, 255, 255, .18);
    --text: #ecebe6; --text-2: #b4b2a9; --text-3: #888780;
    --accent: #85b7eb; --accent-bg: #0c447c; --accent-text: #e6f1fb;
    --success: #97c459; --success-bg: #27500a; --warning: #ef9f27; --warning-bg: #633806;
    --danger: #f09595; --danger-bg: #791f1f; --danger-fill: #e24b4a;
    --chip-blue: #0c447c; --chip-blue-t: #e6f1fb; --chip-violet: #3c3489; --chip-violet-t: #eeedfe;
    --chip-green: #27500a; --chip-green-t: #eaf3de; --chip-orange: #712b13; --chip-orange-t: #faece7;
    --chip-magenta: #72243e; --chip-magenta-t: #fbeaf0; --chip-aqua: #085041; --chip-aqua-t: #e1f5ee;
    --chip-yellow: #633806; --chip-yellow-t: #faeeda; --chip-red: #791f1f; --chip-red-t: #fcebeb;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 600; margin: 0; }
h2 { font-size: 16px; }
h3 { font-size: 14px; margin: 16px 0 4px; }
p { margin: 0 0 8px; }
small { font-size: 12px; }
.muted { color: var(--text-2); }
.block { display: block; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.strong { font-weight: 600; }
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.grow { flex: 1; min-width: 0; }
.pad { padding: 12px 16px; }
[hidden] { display: none !important; }

/* Form controls */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  height: 36px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); width: 100%; min-width: 0;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input:disabled { background: var(--surface-2); color: var(--text-2); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; white-space: nowrap; color: var(--text); }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #0b0b0b; }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] .btn-primary { color: #0b0b0b; } }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--danger-fill); border-color: var(--danger-fill); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: var(--radius);
  border: 0; background: transparent; cursor: pointer; color: var(--text-2); font-size: 18px; flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.form label small { font-weight: 400; color: var(--text-2); }
.form label.check, label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
label.check.small { font-size: 13px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.inline-form { display: inline; margin: 0; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); flex: none; background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 600; color: var(--text); }
.brand img, .auth-brand img { border-radius: 8px; object-fit: cover; }
.brand-preview { border-radius: 14px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); }
.brand:hover { text-decoration: none; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius); color: var(--text-2); margin-bottom: 2px; }
.nav-item i { font-size: 19px; }
.nav-item:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-bg); color: var(--accent-text); font-weight: 500; }
.nav-badge { margin-left: auto; background: var(--danger-fill); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 7px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 20px;
  background: var(--bg); border-bottom: 1px solid var(--border); }
.page-title { font-size: 17px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.content { padding: 20px; width: 100%; }
.sidebar-backdrop { display: none; }
.only-mobile { display: none !important; }

/* Profile dropdown */
.dropdown { position: relative; }
.profile-btn { display: flex; align-items: center; gap: 8px; border: 0; background: transparent; cursor: pointer; padding: 4px 6px; border-radius: var(--radius); }
.profile-btn:hover { background: var(--hover); }
.dropdown-menu { display: none; position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12); padding: 6px; z-index: 30; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-head { display: flex; gap: 10px; align-items: center; padding: 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown-head small { display: block; color: var(--text-2); }
.dropdown-menu a, .dropdown-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 0; background: none;
  border-radius: 6px; color: var(--text); cursor: pointer; text-align: left; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--hover); text-decoration: none; }
.dropdown-menu i { font-size: 18px; color: var(--text-2); }

/* Avatar */
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent-bg); color: var(--accent-text);
  font-weight: 600; object-fit: cover; flex: none; }
.avatar-sm { width: 30px; height: 30px; font-size: 12px; }
.avatar-md { width: 40px; height: 40px; font-size: 14px; }
.avatar-xl { width: 84px; height: 84px; font-size: 28px; }
.avatar-edit { display: flex; align-items: center; gap: 16px; }
.avatar-edit > div { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell small { display: block; }

/* Cards, tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 520px; }
.card-sub { background: transparent; border-style: dashed; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack > .card { margin-bottom: 0; }
.table-wrap { overflow-x: auto; margin: 0 -18px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; color: var(--text-3); font-size: 12px; padding: 8px 18px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.table td.wrap { white-space: normal; max-width: 360px; }
.row-muted td { opacity: .55; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: 6px 0; display: flex; align-items: center; gap: 8px; }
.empty { text-align: center; padding: 48px 16px; color: var(--text-2); }
.empty > i { font-size: 40px; color: var(--text-3); }
.empty h2 { margin: 8px 0 4px; color: var(--text); }

.badge { display: inline-block; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.badge-muted { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge-accent { background: var(--accent-bg); color: var(--accent-text); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.chip { display: inline-block; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.chip-shop { background: color-mix(in srgb, var(--c) 20%, transparent); color: color-mix(in srgb, var(--c) 70%, var(--text)); }
.color-input { width: 40px; height: 28px; padding: 0; border: 1px solid var(--border-strong); border-radius: 6px; background: none; cursor: pointer; }
.chip-blue { background: var(--chip-blue); color: var(--chip-blue-t); }
.chip-violet { background: var(--chip-violet); color: var(--chip-violet-t); }
.chip-green { background: var(--chip-green); color: var(--chip-green-t); }
.chip-orange { background: var(--chip-orange); color: var(--chip-orange-t); }
.chip-magenta { background: var(--chip-magenta); color: var(--chip-magenta-t); }
.chip-aqua { background: var(--chip-aqua); color: var(--chip-aqua-t); }
.chip-yellow { background: var(--chip-yellow); color: var(--chip-yellow-t); }
.chip-red { background: var(--chip-red); color: var(--chip-red-t); }

.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-info { background: var(--accent-bg); color: var(--accent-text); }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tabs.scroll { overflow-x: auto; scrollbar-width: none; }
.tab { padding: 9px 12px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
.tab .count { background: var(--danger-fill); color: #fff; font-size: 11px; border-radius: 10px; padding: 0 6px; margin-left: 2px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; color: var(--text); display: flex; flex-direction: column; }
.stat:hover { text-decoration: none; border-color: var(--border-strong); }
.stat span { color: var(--text-2); font-size: 13px; }
.stat strong { font-size: 26px; font-weight: 600; }
.log-list { list-style: none; margin: 0; padding: 0; }
.log-list li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); align-items: baseline; }
.log-list li:last-child { border-bottom: 0; }
.log-time { color: var(--text-3); font-size: 12px; white-space: nowrap; min-width: 90px; }
.log-error span:last-child { color: var(--danger); }
.log-warning span:last-child { color: var(--warning); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters > input, .filters > select { width: auto; flex: 0 1 170px; }
.filters > .grow, .filters > input[name=q] { flex: 1 1 220px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px; color: var(--text-2); }
.pager a, .pager span.disabled { display: inline-flex; width: 32px; height: 32px; align-items: center; justify-content: center; border-radius: var(--radius); border: 1px solid var(--border); }
.pager span.disabled { opacity: .4; }

/* Switch + segmented */
.switch-row { display: flex; align-items: center; gap: 16px; justify-content: space-between; }
.switch-row h2 { margin-bottom: 4px; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 26px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }
.carrier-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 10px; }
.carrier-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.carrier-row:last-child { border-bottom: 0; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; flex: none; }
.seg label { display: block !important; cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; padding: 5px 12px; font-size: 13px; font-weight: 400; }
.seg input:checked + span { background: var(--accent-bg); color: var(--accent-text); font-weight: 500; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.perm-grid fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; margin: 0; }
.perm-grid legend { font-weight: 600; padding: 0 4px; }

/* Orders */
.bulk-bar { position: sticky; top: 56px; z-index: 10; display: flex; gap: 8px; align-items: center; padding: 8px 12px; margin-bottom: 10px;
  background: var(--accent-bg); color: var(--accent-text); border-radius: 10px; }
.bulk-bar span { margin-right: auto; }
.orders-head { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.order-row { display: grid; grid-template-columns: 20px minmax(0, 1fr) 190px 130px 120px; gap: 14px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.order-row:hover { background: var(--hover); }
.order-row.needs-attention { background: var(--warning-bg); }
.order-main { color: var(--text); min-width: 0; }
.order-main:hover { text-decoration: none; }
.order-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.order-items { color: var(--text-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0; }
.order-meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--text-3); }
.order-meta i { margin-right: 3px; }
.order-ship { display: flex; flex-direction: column; font-size: 13px; min-width: 0; }
.order-ship small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-total { text-align: right; font-weight: 500; }
.order-actions { text-align: right; }
.back-link { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 10px; color: var(--text-2); }
.order-detail-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.order-detail-head h2 { font-size: 18px; display: flex; align-items: center; gap: 4px; }
.item-list { list-style: none; margin: 0; padding: 0; }
.item-list li { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.item-list img, .img-ph { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--text-3); }
.item-list .num { text-align: right; }
.total-row { display: flex; justify-content: space-between; padding-top: 12px; font-size: 15px; }
.note { margin-top: 12px; padding: 10px; background: var(--warning-bg); color: var(--warning); border-radius: var(--radius); }
.dl { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 8px 12px; margin: 0; }
.dl dt { color: var(--text-2); }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.money-dl dd { text-align: right; }

.dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 24px)); background: var(--surface); color: var(--text); box-shadow: 0 16px 48px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.option-list { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; }
.option-list label { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.option-list label:has(input:checked) { border-color: var(--accent); background: var(--accent-bg); color: var(--accent-text); }

.toast-wrap { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger-fill); color: #fff; }

/* Auth pages */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px 24px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 18px; text-align: center; }
.auth-brand h1 { font-size: 19px; }

/* Chat */
.page-chat .content { max-width: none; padding: 0; flex: 1; display: flex; }
.chat { flex: 1; display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; height: calc(100vh - 56px); background: var(--surface); position: relative; }
.chat-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.chat-list-head { display: flex; gap: 8px; align-items: center; padding: 10px 12px; }
.chat-list-head select { flex: 1; }
.chat-search { margin: 0 12px 8px; width: calc(100% - 24px) !important; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.conv:hover { background: var(--hover); }
.conv.active { background: var(--accent-bg); }
.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; gap: 6px; align-items: baseline; }
.conv-top strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.conv.unread .conv-top strong { font-weight: 700; }
.conv-time { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.conv-preview { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-unread { align-self: center; background: var(--danger-fill); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 7px; }
.chat-thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.thread-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; background: var(--surface-2); }
.msg { max-width: 75%; padding: 7px 11px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--accent-bg); color: var(--accent-text); border-color: transparent; }
.msg img { max-width: 220px; max-height: 260px; border-radius: 8px; display: block; }
.msg-time { display: block; font-size: 10px; color: var(--text-3); margin-top: 2px; text-align: right; }
.msg.me .msg-time { color: inherit; opacity: .7; }
.msg-day { align-self: center; font-size: 11px; color: var(--text-3); margin: 6px 0; }
.quick-replies { display: flex; gap: 6px; padding: 8px 12px 0; overflow-x: auto; scrollbar-width: none; }
.chip-btn { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 14px; padding: 3px 10px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.chip-btn:hover { background: var(--hover); }
.chip-btn.ghost { border-style: dashed; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; }
.composer textarea { flex: 1; max-height: 120px; resize: none; }
.chat-orders { border-left: 1px solid var(--border); overflow-y: auto; min-height: 0; }
.buyer-order { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 8px; font-size: 13px; }
.buyer-order .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.buyer-order .items { color: var(--text-2); font-size: 12px; margin: 4px 0; }
.chat-empty { position: absolute; left: 320px; right: 0; top: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-3); pointer-events: none; }
.chat-empty i { font-size: 42px; }
.chat.has-thread .chat-empty { display: none; }
.chat:not(.show-orders) { grid-template-columns: 320px minmax(0, 1fr); }

.context-item { display: flex; flex-direction: column; gap: 4px; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.item-card { display: flex; gap: 10px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); max-width: 340px; white-space: normal; }
.item-card:hover { text-decoration: none; border-color: var(--border-strong); }
.item-card img, .item-card .img-ph { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--text-3); }
.item-card.compact img, .item-card.compact .img-ph { width: 40px; height: 40px; }
.item-card-body { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.item-card-name { font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-card-meta { font-size: 12px; display: flex; gap: 8px; }
.msg.msg-card { padding: 4px; background: transparent; border: 0; }
.order-card { max-width: 380px; }
.order-card .item-card-meta { flex-wrap: wrap; align-items: center; }
.ai-tag { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; }
.ai-log td { vertical-align: top; }
.plain-fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.plain-fieldset legend { font-weight: 500; padding: 0; margin-bottom: 4px; }
.steps { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* Orders list, Shopee style */
.ocard-cols, .ocard-body { display: grid; grid-template-columns: minmax(0, 2.4fr) minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 1.1fr) 170px; gap: 16px; }
.ocard-cols { padding: 10px 28px; font-size: 12px; color: var(--text-3); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.osection { padding: 14px 16px 2px; }
.osection h3 { margin: 0; font-size: 13px; }
.ocard.order-row { display: block; padding: 0; margin: 10px 12px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.ocard.order-row:hover { background: var(--surface); border-color: var(--border-strong); }
.ocard.needs-attention { background: var(--surface); border-color: var(--warning); }
.ocard.needs-attention .ocard-head { background: var(--warning-bg); }
.ocard-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.ocard-buyer { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; }
.ocard-buyer i { font-size: 20px; color: var(--text-3); }
.chat-open { color: #ee4d2d; width: 28px; height: 28px; }
.chat-open:hover { color: #ee4d2d; }
.ocard-sn { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-2); }
.ocard-sn .icon-btn { width: 26px; height: 26px; font-size: 15px; }
.ocard-code { margin-left: auto; font-weight: 700; font-size: 14px; letter-spacing: .02em; }
.ocard-sn.after-code { margin-left: 0; padding-left: 8px; border-left: 1px solid var(--border-strong); }
.carrier-instant { align-self: flex-start; display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: 6px; background: rgba(55, 138, 221, .16); color: var(--accent); }
.link-btn.link-small { font-size: 12px; padding: 0; }
.badge-late { align-self: flex-start; }
.fin-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.fin-head select { width: auto; min-width: 200px; }
.fin-filters { margin-bottom: 10px; }
.fin-pager { margin: 10px 0; }
.seg-link { display: block; padding: 5px 12px; font-size: 13px; color: var(--text-2); }
.seg-link + .seg-link { border-left: 1px solid var(--border); }
.seg-link:hover { text-decoration: none; background: var(--hover); }
.seg-link.active { background: var(--accent-bg); color: var(--accent-text); font-weight: 500; }
.ocard-note { padding: 8px 16px; border-top: 1px dashed var(--border); font-size: 13px; color: var(--text-2); background: var(--warning-bg); }
.ocard-body { padding: 12px 16px; align-items: start; }
.ocol-items { display: flex; flex-direction: column; gap: 8px; color: var(--text); min-width: 0; }
.ocol-items:hover { text-decoration: none; }
.oitem { display: flex; gap: 10px; align-items: flex-start; }
.oitem img, .oitem .img-ph { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; flex: none; border: 1px solid var(--border); background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--text-3); }
.oitem-text { display: flex; flex-direction: column; min-width: 0; }
.oitem-name { font-size: 13px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ocol-pay, .ocol-status, .ocol-ship, .ocol-actions { display: flex; flex-direction: column; gap: 2px; font-size: 13px; min-width: 0; }
.ocol-ship small { overflow-wrap: anywhere; }
.link-btn { background: none; border: 0; padding: 2px 0; color: var(--accent); cursor: pointer; text-align: left; font: inherit; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }
.link-btn.muted { color: var(--text-2); }
.print-group { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
/* Dashboard ads chart */
.ads-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.ads-controls select { width: auto; min-width: 160px; }
.reply-item { border-top: 1px solid var(--border); padding: 14px 0; }
.reply-item:first-of-type { border-top: 0; }
.reply-actions { display: flex; align-items: center; gap: 4px; }
.reply-actions .icon-btn:disabled { opacity: .35; cursor: default; }
.dash-split { margin-bottom: 16px; }
@media (min-width: 861px) { .dash-split { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); } }
.ads-custom { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: -4px 0 12px; }
/* Date range picker (ads card) */
.drp { position: relative; }
.drp-btn { gap: 8px; font-weight: 400; }
.drp-btn .ti-chevron-down { color: var(--text-3); }
.drp-pop { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; display: flex; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .15); }
.drp-pop[hidden] { display: none; }
.drp-presets { list-style: none; margin: 0; padding: 8px 0; border-right: 1px solid var(--border); min-width: 150px; }
.drp-presets button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 16px; font: inherit; color: var(--text); cursor: pointer; }
.drp-presets button:hover { background: var(--hover); }
.drp-presets button.active { color: var(--accent); font-weight: 500; }
.drp-cal { padding: 8px 12px 10px; }
.drp-months { display: flex; gap: 20px; }
.drp-month { width: 252px; }
.drp-head { display: grid; grid-template-columns: 30px 30px 1fr 30px 30px; align-items: center; text-align: center; margin-bottom: 4px; }
.drp-head .icon-btn { width: 30px; height: 30px; }
.drp-head .icon-btn:disabled { opacity: .3; cursor: default; }
.drp-grid { display: grid; grid-template-columns: repeat(7, 36px); row-gap: 2px; }
.drp-wd { text-align: center; font-size: 12px; color: var(--text-3); padding: 6px 0; }
.drp-day { height: 32px; border: 0; background: none; font: inherit; font-size: 13px; color: var(--text); cursor: pointer; }
.drp-day:hover:not(:disabled) { background: var(--hover); border-radius: 6px; }
.drp-day:disabled { color: var(--text-3); opacity: .45; cursor: default; }
.drp-day.is-today { color: var(--danger-fill); font-weight: 600; }
.drp-day.in-range { background: var(--accent-bg); color: var(--accent-text); border-radius: 0; }
.drp-day.is-start, .drp-day.is-end { background: var(--accent); color: var(--surface); border-radius: 6px; font-weight: 600; }
.drp-hint { margin: 8px 0 0; font-size: 12px; }
@media (max-width: 860px) {
  .drp-pop { flex-direction: column; left: 0; right: auto; width: min(320px, calc(100vw - 40px)); }
  .drp-presets { display: flex; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border); padding: 6px; }
  .drp-presets button { padding: 6px 10px; }
  .drp-month { width: auto; }
  .drp-grid { grid-template-columns: repeat(7, 1fr); }
}
.seg label + label span { border-left: 1px solid var(--border); }
.ads-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 6px; }
.ads-tile { font: inherit; text-align: left; cursor: pointer; border-top: 3px solid transparent; }
.ads-tile.active { border-top-color: var(--c); box-shadow: 0 2px 8px rgba(0, 0, 0, .08); }
.ads-hint { display: block; margin-bottom: 4px; }
.ads-legend { justify-content: flex-end; }
.ads-cross { stroke: var(--border-strong); stroke-dasharray: 3 3; }
.ads-tiles .stat strong { font-size: 20px; }
@media (max-width: 640px) {
  .ads-tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
  .ads-tiles .stat { padding: 10px 12px; }
  .ads-tiles .stat strong { font-size: 16px; }
}
.ads-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); min-height: 4px; margin-bottom: 4px; }
.ads-legend i, .ads-tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.ads-chart { position: relative; width: 100%; }
.ads-chart svg { display: block; overflow: visible; }
.ads-grid { stroke: var(--border); }
.ads-axis { stroke: var(--border-strong); }
.ads-tick { fill: var(--text-3); font-size: 11px; }
.ads-hl { fill: var(--hover, rgba(0, 0, 0, .04)); }
.ads-today { opacity: .55; }
.ads-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ads-dot { stroke: var(--surface); stroke-width: 2; }
.ads-tip { position: absolute; top: 0; z-index: 5; pointer-events: none; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 170px; box-shadow: 0 4px 14px rgba(0, 0, 0, .12); }
.ads-tip div { display: flex; align-items: center; gap: 4px; color: var(--text-2); }
.ads-tip div span { margin-left: auto; padding-left: 12px; color: var(--text); font-variant-numeric: tabular-nums; }
.ads-tip-total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; font-weight: 500; }
.ads-table { margin-top: 10px; }
.ads-table summary { cursor: pointer; color: var(--text-2); font-size: 13px; }
.sound-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sound-row > span { min-width: 110px; font-weight: 500; }
.print-group-head { display: flex; justify-content: space-between; margin-bottom: 8px; }

/* Floating chat widget */
.cw { position: fixed; right: 20px; bottom: 0; width: 360px; height: 480px; max-height: calc(100vh - 80px); background: var(--surface); border: 1px solid var(--border-strong); border-bottom: 0; border-radius: 12px 12px 0 0; box-shadow: 0 8px 32px rgba(0, 0, 0, .25); display: flex; flex-direction: column; z-index: 60; }
.cw.cw-collapsed { height: auto; }
.cw.cw-collapsed .cw-body, .cw.cw-collapsed .cw-composer { display: none; }
.cw-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #ee4d2d; color: #fff; border-radius: 12px 12px 0 0; }
.cw-head .icon-btn, .cw-head .muted { color: #fff; }
.cw-head .icon-btn { width: 28px; height: 28px; }
.cw-head .icon-btn:hover { background: rgba(255, 255, 255, .15); }
.cw-body { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; background: var(--surface-2); }
.cw-body .msg { max-width: 85%; font-size: 13px; }
.cw-body .msg img { max-width: 180px; border-radius: 6px; display: block; }
.cw-card { display: flex; gap: 8px; align-items: center; color: inherit; }
.cw-card img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.cw-card span { display: flex; flex-direction: column; font-size: 12px; }
.cw-composer { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); align-items: flex-end; }
.cw-composer textarea { flex: 1; resize: none; height: 36px; }

@media (max-width: 1100px) {
  .order-row { grid-template-columns: 20px minmax(0, 1fr) 150px 110px; }
  .order-row .order-actions { grid-column: 2 / -1; text-align: left; }
  .chat.show-orders { grid-template-columns: 280px minmax(0, 1fr) 280px; }
}
@media (max-width: 860px) {
  .only-mobile { display: inline-flex !important; }
  .only-desktop { display: none !important; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0, 0, 0, .2); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 40; }
  .topbar { padding: 0 8px 0 4px; }
  .content { padding: 12px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .table-wrap { margin: 0 -18px; }
  .filters > input, .filters > select { flex: 1 1 140px; }
  .order-row { grid-template-columns: 20px minmax(0, 1fr) auto; gap: 8px 10px; align-items: start; }
  .order-row .order-ship { grid-column: 2; }
  .order-row .order-total { grid-column: 3; grid-row: 1; }
  .order-row .order-actions { grid-column: 2 / -1; text-align: left; }
  .order-items { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .dl { grid-template-columns: 110px minmax(0, 1fr); }
  .bulk-bar { top: 56px; }
  .chat, .chat:not(.show-orders), .chat.show-orders { grid-template-columns: minmax(0, 1fr); height: calc(100dvh - 56px); }
  .chat.has-thread .chat-list { display: none; }
  .chat:not(.has-thread) .chat-thread { display: none !important; }
  .chat.show-orders .chat-orders { position: absolute; inset: 0; background: var(--surface); z-index: 5; border: 0; }
  .chat-empty { display: none; }
  .msg { max-width: 85%; }
  .only-desktop-grid { display: none !important; }
  .ocard-body { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .ocol-items, .ocol-actions { grid-column: 1 / -1; }
  .ocol-actions { flex-direction: row; gap: 18px; }
  .ocard.order-row { margin: 8px; }
  .ocard-sn { margin-left: 0; width: 100%; }
  .cw { right: 0; left: 0; width: auto; height: 75vh; }
}
.fin-dl { grid-template-columns: minmax(0, 1fr) auto; }
.fin-dl .sub { color: var(--text-2); font-size: 12px; padding-left: 12px; }
.fin-dl .total { border-top: 1px solid var(--border); padding-top: 8px; font-size: 16px; }
.page-frame .content { max-width: none; padding: 0; flex: 1; display: flex; flex-direction: column; }
.asw-bar { display: flex; gap: 12px; align-items: center; padding: 6px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.asw-frame { border: 0; width: 100%; flex: 1; min-height: calc(100vh - 100px); background: #fff; }
.scan-input { font-size: 22px; padding: 12px; font-family: var(--mono, monospace); }
.scan-err { font-size: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
