:root {
    color-scheme: dark;
    --bg: #0f141b;
    --card: #161d27;
    --text: #e7edf5;
    --muted: #9aa8b7;
    --line: #2b3645;
    --field: #101720;
    --brand: #14b8a6;
    --brand2: #0d9488;
    --danger: #f87171;
    --warn: #fbbf24;
    --ok: #34d399;
    --shadow: 0 12px 30px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "Microsoft YaHei", "Segoe UI", Arial, sans-serif; }
a { color: inherit; text-decoration: none; }
input, select, textarea, button { font: inherit; }

.topbar { position: sticky; top: 0; z-index: 10; min-height: 58px; display: flex; align-items: center; gap: 20px; padding: 0 20px; background: #121922; border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; color: var(--brand); font-size: 17px; }
.topbar nav { display: flex; gap: 6px; }
.topbar nav a { padding: 8px 10px; border-radius: 6px; color: var(--muted); white-space: nowrap; }
.topbar nav a:hover { background: #102923; color: var(--brand); }
.adminbar { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.container { width: min(1480px, calc(100% - 28px)); margin: 22px auto 60px; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.auth-card, .narrow { width: min(460px, 100%); }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
h1 { margin: 0; font-size: 28px; }
h2 { margin: 0 0 12px; font-size: 18px; }
.eyebrow { margin: 0 0 5px; color: var(--brand); font-weight: 800; font-size: 12px; text-transform: uppercase; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: #1b2532; color: var(--text); cursor: pointer; font-weight: 700; white-space: nowrap; }
.button:hover { background: #233044; }
.button.primary { background: var(--brand2); border-color: var(--brand); color: #f8fffd; }
.button.primary:hover { background: var(--brand); }
.button.danger { background: #321b22; border-color: #7f2d36; color: var(--danger); }
.button.ghost { background: transparent; }
.button.small { min-height: 30px; padding: 0 9px; font-size: 13px; }
.button:disabled, button:disabled { opacity: .45; cursor: not-allowed; }

input, select, textarea { width: 100%; min-height: 36px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); color: var(--text); }
input::placeholder, textarea::placeholder { color: #6f7e8f; }
textarea { min-height: 70px; resize: vertical; }
label { display: grid; gap: 5px; font-weight: 700; color: var(--muted); }
.date-label { color: #b7c4d3; }

.form-stack { display: grid; gap: 12px; }
.inline-form, .search-form, .mini-form, .bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input { max-width: 260px; }
.search-form input { width: 280px; }
.mini-form { margin: 10px 0; }
.mini-form input, .mini-form select { min-width: 0; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--line); background: #151d28; }
.alert.success { background: #11261f; border-color: #225c49; color: var(--ok); }
.alert.danger { background: #2b171b; border-color: #7f2d36; color: var(--danger); }
.toast-stack { position: fixed; top: 76px; right: 18px; z-index: 1000; display: grid; gap: 10px; width: min(360px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: #151d28; color: var(--text); box-shadow: var(--shadow); animation: toast-in .18s ease-out; }
.toast.success { background: #11261f; border-color: #225c49; color: var(--ok); }
.toast.danger { background: #2b171b; border-color: #7f2d36; color: var(--danger); }
.toast.is-hiding { opacity: 0; transform: translateY(-8px); transition: opacity .2s ease, transform .2s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

.grid-layout { display: grid; grid-template-columns: 310px minmax(0, 1fr); gap: 16px; }
.sidebar { position: sticky; top: 74px; align-self: start; max-height: calc(100vh - 96px); overflow: auto; }
.tree details { margin-left: 12px; }
.tree > details { margin-left: 0; }
.tree summary { margin: 3px 0; cursor: pointer; }
.tree summary::marker { color: var(--muted); }
.tree-leaf { margin: 3px 0 3px 12px; }
.tree > .tree-leaf { margin-left: 0; }
.tree a, .tree-label { display: flex; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 6px; color: var(--muted); }
.tree-label { cursor: pointer; }
.tree a.active, .tree a:hover, .tree-label.active, .tree-label:hover { background: #102923; color: var(--brand); font-weight: 700; }
.tree-view { margin: 2px 0 6px 18px; font-size: 12px; border: 1px solid var(--line); background: #101720; }
.tree small { color: var(--muted); }
.admin-tools { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.main-panel { min-width: 0; }
.section-summary { font-size: 17px; font-weight: 800; cursor: pointer; }

.customer-form { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 10px; }
.customer-form textarea { min-height: 38px; }
.customer-form .tag-list, .customer-form button, .customer-form .actions { grid-column: 1 / -1; }
.modal-form { min-width: min(900px, 90vw); }
dialog { color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 20px 70px rgba(0,0,0,.5); }
dialog::backdrop { background: rgba(0,0,0,.55); }

.tag-list { display: flex; gap: 8px; flex-wrap: wrap; }
.tag-choice { display: inline-flex; align-items: center; gap: 5px; font-weight: 400; }
.tag-choice input { width: auto; min-height: auto; }
.tag, .tag-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 8px; border-radius: 999px; background: #102923; color: var(--tag, #14b8a6); font-size: 12px; font-weight: 700; margin: 2px; }
.tag-filter { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.tag-pill small { margin-left: 4px; color: var(--muted); font-size: 11px; }
.tag-manage { display: inline-flex; align-items: center; gap: 4px; }
.tag-manage form { margin: 0; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.data-table { width: 100%; min-width: 1260px; border-collapse: collapse; background: #111821; }
.data-table th, .data-table td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.data-table th { position: sticky; top: 0; background: #111a24; color: var(--muted); font-size: 12px; z-index: 1; }
.data-table tr:hover td { background: #121b27; }
.data-table input[type=checkbox] { width: auto; min-height: auto; }
.data-table .action-col { position: sticky; right: 0; min-width: 118px; background: #111821; box-shadow: -10px 0 14px rgba(15, 20, 27, .72); z-index: 2; }
.data-table th.action-col { background: #111a24; z-index: 3; }
.data-table tr:hover .action-col { background: #121b27; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.clip { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip.long { max-width: 250px; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }

.status { display: inline-flex; margin-left: 4px; padding: 1px 6px; border-radius: 999px; font-size: 12px; }
.status.ok { color: var(--ok); background: #102923; }
.status.warn { color: var(--warn); background: #30280f; }
.status.danger { color: var(--danger); background: #321b22; }
.status.muted { color: var(--muted); background: #202a38; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; color: var(--muted); }
.pager select { width: auto; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
code { display: inline-block; background: #101720; padding: 4px 6px; border-radius: 4px; word-break: break-all; }

@media (max-width: 900px) {
    .topbar { height: auto; flex-wrap: wrap; padding: 12px; gap: 10px; }
    .toast-stack { top: 10px; left: 8px; right: 8px; width: auto; }
    .topbar nav { width: 100%; overflow-x: auto; padding-bottom: 2px; }
    .adminbar { width: 100%; margin-left: 0; justify-content: space-between; }
    .container { width: min(100% - 16px, 1480px); margin-top: 14px; }
    .grid-layout, .two-col { grid-template-columns: 1fr; }
    .sidebar { position: static; max-height: none; }
    .customer-form { grid-template-columns: 1fr; }
    .page-head { display: grid; }
    .search-form, .inline-form, .bulkbar { display: grid; grid-template-columns: 1fr; width: 100%; }
    .search-form input, .inline-form input { width: 100%; max-width: none; }
    .card { padding: 14px; }
    .data-table { min-width: 1080px; }
    .data-table .action-col { min-width: 96px; }
    .row-actions { gap: 6px; }
    .clip { max-width: 120px; }
    .clip.long { max-width: 180px; }
    .pager { justify-content: flex-start; flex-wrap: wrap; }
}
