:root {
    color-scheme: light;
    --page: #f5f7f6;
    --surface: #ffffff;
    --ink: #192923;
    --muted: #718078;
    --line: #e1e8e4;
    --accent: #147d66;
    --accent-hover: #0e6754;
    --accent-soft: #e5f3ef;
    --danger: #b13f39;
    --danger-soft: #fff0ee;
    --success: #236c4d;
    --success-soft: #e9f5ed;
    --radius: 8px;
    font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
    color: var(--ink);
    background: var(--page);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--page); }
button, input { font: inherit; }
a { color: inherit; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { background: #fff; border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; }
.brand { height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 8px; color: var(--ink); text-decoration: none; font-size: 15px; font-weight: 700; }
.brand-mark { width: 30px; height: 30px; display: grid; place-items: center; color: #fff; background: var(--accent); border-radius: 7px; font-size: 14px; }
.sidebar nav { display: grid; gap: 4px; margin-top: 32px; }
.nav-link { display: flex; gap: 11px; align-items: center; min-height: 40px; padding: 0 11px; border-radius: 6px; color: #58665f; text-decoration: none; font-size: 13px; }
.nav-link:hover { background: #f2f6f4; color: var(--ink); }
.nav-link[aria-current="page"] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.nav-icon { width: 17px; text-align: center; font-size: 15px; }
.sidebar-foot { margin-top: auto; padding: 14px 8px 4px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.state-mark { width: 7px; height: 7px; border-radius: 50%; background: #41a677; }
.main-area { min-width: 0; }
.topbar { height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 0 32px; border-bottom: 1px solid var(--line); background: var(--surface); color: #506058; font-size: 12px; }
.topbar-env { padding: 5px 9px; background: #f3f6f4; border-radius: 5px; color: #68766e; }
.page-content { max-width: 1180px; margin: 0 auto; padding: 28px 32px 56px; }
.page-content > h1 { margin: 0 0 23px; font-size: 22px; line-height: 1.3; font-weight: 650; }
.page-heading, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.page-heading { margin-bottom: 20px; }
.page-heading h2, .section-heading h2 { margin: 0; font-size: 15px; line-height: 1.45; font-weight: 650; }
.page-heading p, .section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.metrics-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 0 0 20px; }
.metric { min-height: 114px; padding: 18px 19px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.metric > span, .metric small { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin: 7px 0 2px; font-size: 28px; line-height: 1.1; font-weight: 650; font-variant-numeric: tabular-nums; }
.content-section { margin: 0 0 18px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.section-heading { margin-bottom: 16px; }
.button { min-height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 12px; border: 1px solid transparent; border-radius: 6px; text-decoration: none; cursor: pointer; font-size: 12px; font-weight: 600; white-space: nowrap; transition: background-color .15s, border-color .15s, transform .12s; }
.button:active { transform: translateY(1px); }
.button:focus-visible, .text-button:focus-visible, .text-link:focus-visible, input:focus-visible { outline: 3px solid #98d7c6; outline-offset: 2px; }
.button-primary { color: #fff; background: var(--accent); }
.button-primary:hover { background: var(--accent-hover); }
.button-secondary { color: #33463d; background: #fff; border-color: #ced9d3; }
.button-secondary:hover { background: #f5f8f6; border-color: #aebdb4; }
.link-row { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 10px 9px 14px; background: #f5f8f6; border: 1px solid #e8eeeb; border-radius: 6px; }
.link-row code { overflow-wrap: anywhere; font-size: 12px; color: #31453b; }
.text-link { color: var(--accent); font-size: 12px; font-weight: 600; text-decoration: none; }
.text-link:hover, .text-button:hover { text-decoration: underline; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 12px; }
th { padding: 10px 12px; border-bottom: 1px solid var(--line); color: #738078; font-weight: 600; white-space: nowrap; }
td { padding: 12px; border-bottom: 1px solid #edf1ef; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
.empty-state { min-height: 112px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--muted); text-align: center; }
.empty-state strong { color: #394a41; font-size: 13px; }
.empty-state span { font-size: 12px; }
.alert { margin: 0 0 16px; padding: 10px 12px; border-radius: 6px; font-size: 12px; line-height: 1.6; }
.alert-success { color: var(--success); background: var(--success-soft); }
.alert-error { color: var(--danger); background: var(--danger-soft); }
.count-label { color: var(--muted); font-size: 12px; white-space: nowrap; }
.agent-name { font-weight: 600; }
.subtle { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { display: inline-flex; align-items: center; min-height: 23px; padding: 0 8px; border-radius: 12px; font-size: 11px; white-space: nowrap; }
.status-on { color: #216a4c; background: #e8f4ec; }
.status-off { color: #6d7772; background: #eff2f0; }
.qr-thumb { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 5px; }
.qr-thumb img { width: 40px; height: 40px; object-fit: contain; image-rendering: pixelated; }
.row-actions { white-space: nowrap; }
.row-actions > * + * { margin-left: 12px; }
.inline-form { display: inline; }
.text-button { padding: 0; border: 0; color: var(--accent); background: none; cursor: pointer; font-size: 12px; }
.form-section { scroll-margin-top: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 18px; }
.form-grid label, .date-filter label { display: grid; gap: 7px; color: #46584e; font-size: 12px; font-weight: 600; }
.form-grid input:not([type="checkbox"]), .date-filter input { width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid #cfdad4; border-radius: 6px; background: #fff; color: var(--ink); font-size: 12px; }
.form-grid input[type="file"] { padding: 6px; }
.form-grid input::placeholder { color: #9ba7a0; }
.form-grid small { color: var(--muted); font-size: 11px; font-weight: 400; }
.field-wide { grid-column: 1 / -1; }
.check-field { display: flex !important; align-items: center; gap: 8px !important; min-height: 25px; }
.check-field input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-actions { display: flex; align-items: center; gap: 8px; padding-top: 3px; }
.code-panel { max-width: 790px; }
.date-filter { display: flex; align-items: end; gap: 12px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.date-filter label { min-width: 160px; }
.date-filter > span { padding-bottom: 10px; color: var(--muted); font-size: 12px; }
.stats-total { margin: 18px 0 10px; }
.share-cell { display: flex; align-items: center; gap: 12px; min-width: 150px; }
.share-cell > span:first-child { min-width: 44px; font-variant-numeric: tabular-nums; }
.share-track { width: 110px; height: 6px; overflow: hidden; border-radius: 4px; background: #e8eeeb; }
.share-track i { display: block; height: 100%; background: var(--accent); }

@media (max-width: 760px) {
    .app-shell { grid-template-columns: minmax(0, 1fr); }
    .sidebar { padding: 10px 12px 8px; border-right: 0; border-bottom: 1px solid var(--line); }
    .brand { height: 36px; }
    .sidebar nav { display: flex; gap: 3px; overflow-x: auto; margin-top: 10px; }
    .nav-link { min-width: max-content; min-height: 36px; padding: 0 9px; }
    .sidebar-foot { display: none; }
    .topbar { height: 46px; padding: 0 16px; }
    .page-content { padding: 21px 15px 40px; }
    .page-content > h1 { margin-bottom: 17px; font-size: 20px; }
    .metrics-grid { gap: 8px; }
    .metric { min-height: 100px; padding: 13px 12px; }
    .metric strong { font-size: 24px; }
    .metric small { font-size: 10px; }
    .content-section { padding: 15px; }
    .page-heading { align-items: flex-start; }
    .form-grid { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
}

@media (max-width: 480px) {
    .metrics-grid { grid-template-columns: 1fr; }
    .metric { min-height: 76px; display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 8px; }
    .metric strong { grid-column: 2; grid-row: 1 / span 2; }
    .metric small { grid-column: 1; }
    .page-heading { flex-direction: column; }
    .date-filter { align-items: stretch; flex-wrap: wrap; }
    .date-filter label { min-width: calc(50% - 12px); flex: 1; }
    .date-filter > span { display: none; }
}


.qr-upload-panel {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px dashed #b7cfc5;
    border-radius: 8px;
    background: #f7fbf9;
}
.qr-upload-heading {
    display: grid;
    gap: 4px;
}
.qr-upload-heading strong {
    font-size: 12px;
    color: #31453b;
}
.qr-upload-heading span,
.qr-file-meta small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
    line-height: 1.55;
}
.qr-upload-body {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 14px;
    align-items: center;
}
.qr-preview-box {
    width: 112px;
    height: 112px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}
.qr-preview-box img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.qr-preview-empty {
    padding: 8px;
    color: var(--muted);
    font-size: 11px;
    text-align: center;
    line-height: 1.4;
}
.qr-upload-controls {
    display: grid;
    gap: 8px;
}
.qr-file-label {
    position: relative;
    display: inline-flex !important;
    width: fit-content;
    gap: 0 !important;
    font-weight: 600;
}
.qr-file-label input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}
.qr-file-meta {
    display: grid;
    gap: 4px;
}
.qr-file-meta > span {
    color: #3d5248;
    font-size: 12px;
}
.qr-decode-status {
    min-height: 18px;
    font-size: 12px;
    line-height: 1.5;
}
.qr-decode-status[data-state="ok"] { color: var(--success); }
.qr-decode-status[data-state="warn"] { color: #9a6b12; }
.qr-decode-status[data-state="pending"] { color: var(--muted); }

@media (max-width: 760px) {
    .qr-upload-body { grid-template-columns: 1fr; }
    .qr-preview-box { width: 96px; height: 96px; }
}
