:root {
    --bg: #eef2f3;
    --surface: #ffffff;
    --surface-soft: #f7f9fa;
    --text: #182026;
    --muted: #6b7780;
    --line: #d8dee3;
    --primary: #087f8c;
    --primary-dark: #05606b;
    --accent: #315efb;
    --danger: #c24135;
    --success: #197b45;
    --shadow: 0 18px 50px rgba(24, 32, 38, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Arial, "Microsoft YaHei", "PingFang SC", sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea {
    font: inherit;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: #fff;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input {
    height: 42px;
    padding: 0 12px;
}

textarea {
    min-height: 250px;
    resize: vertical;
    padding: 12px;
    line-height: 1.6;
}

input:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8, 127, 140, 0.14);
}

label > span {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 13px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    color: #fff;
    background: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    color: var(--text);
    border-color: var(--line);
    background: #fff;
}

.btn-danger {
    color: #fff;
    background: var(--danger);
}

.btn-small {
    min-height: 34px;
    padding: 0 12px;
    font-size: 13px;
}

.alert {
    border-radius: 8px;
    padding: 12px 14px;
    line-height: 1.5;
}

.alert-success {
    color: var(--success);
    background: #e9f6ef;
    border: 1px solid #b8e0c9;
}

.alert-error {
    color: var(--danger);
    background: #fff0ee;
    border: 1px solid #fac8c2;
}

.brand-row,
.front-logo,
.admin-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark,
.front-logo img,
.admin-logo img {
    display: block;
    flex: 0 0 40px;
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    border-radius: 8px;
    background: #fff;
    object-fit: contain;
    overflow: hidden;
}

.brand-row h1,
.panel-heading h1,
.admin-topbar h1 {
    margin: 0;
}

.brand-row p,
.panel-heading span,
.admin-topbar span,
.hint {
    margin: 4px 0 0;
    color: var(--muted);
}

.hint:empty {
    display: none;
}

.front-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 72px;
    padding: 0 28px;
    background: rgba(255, 255, 255, 0.88);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.front-header nav {
    display: flex;
    gap: 18px;
    color: var(--muted);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(280px, 350px) minmax(0, 1fr);
    gap: 16px;
    padding: 16px;
    min-height: calc(100vh - 72px);
}

.control-panel,
.preview-panel,
.install-panel,
.login-card,
.content-section,
.admin-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.control-panel {
    padding: 16px;
    align-self: start;
    position: sticky;
    top: 88px;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.panel-heading h1 {
    font-size: 22px;
}

.count-pill {
    min-width: 68px;
    padding: 7px 10px;
    border-radius: 8px;
    text-align: center;
    background: #eef8f9;
    color: var(--primary-dark);
}

.control-panel textarea {
    min-height: 220px;
}

.control-panel .btn {
    min-height: 38px;
    padding: 0 12px;
}

.input-block {
    display: block;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.divider {
    height: 1px;
    background: var(--line);
    margin: 18px 0;
}

.playback-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: end;
    gap: 12px;
}

.speed-value {
    min-width: 86px;
    height: 42px;
    border-radius: 8px;
    border: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
}

input[type="range"] {
    padding: 0;
    accent-color: var(--primary);
}

.hint[data-type="success"] {
    color: var(--success);
}

.hint[data-type="error"] {
    color: var(--danger);
}

.preview-panel {
    display: grid;
    grid-template-rows: minmax(280px, 36vh) 1fr;
    overflow: hidden;
}

.stage {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: linear-gradient(135deg, #ffffff 0%, #edf7f7 100%);
    border-bottom: 1px solid var(--line);
}

.empty-state,
.stage-barcode {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
}

.empty-state strong {
    font-size: 24px;
}

.empty-state span {
    color: var(--muted);
}

.stage-svg {
    width: min(760px, 100%);
    max-width: 100%;
    height: auto;
    max-height: 210px;
    shape-rendering: crispEdges;
}

.stage-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--muted);
}

.stage-meta strong {
    color: var(--text);
    word-break: break-all;
}

.barcode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
    padding: 18px;
    overflow: auto;
}

.barcode-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #fff;
    cursor: pointer;
    min-height: 178px;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.barcode-card.is-selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8, 127, 140, 0.12);
}

.barcode-card.is-current {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 13px;
}

.card-head input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.card-svg {
    width: 100%;
    max-width: 100%;
    height: auto;
    shape-rendering: crispEdges;
}

.barcode-error {
    width: 100%;
    min-height: 110px;
    padding: 14px;
    border: 1px dashed #f0a7a0;
    border-radius: 8px;
    color: var(--danger);
    background: #fff7f6;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
}

.barcode-error span {
    color: #7f3a33;
    font-size: 12px;
    line-height: 1.5;
    word-break: break-all;
}

.stage-svg *,
.card-svg *,
.print-svg * {
    shape-rendering: crispEdges;
}

.print-area {
    display: none;
}

.install-page,
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(circle at top left, #dff3f1 0, transparent 34%), var(--bg);
}

.install-shell,
.login-shell {
    width: min(960px, 100%);
}

.install-panel,
.login-card {
    padding: 28px;
}

.login-card {
    width: min(420px, 100%);
    margin: 0 auto;
    display: grid;
    gap: 16px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-top: 22px;
}

.field-wide {
    grid-column: 1 / -1;
}

.install-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 20px;
}

.status-grid,
.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-top: 20px;
}

.status-grid div,
.metric-card {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.status-grid span,
.metric-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 8px;
}

.status-grid strong,
.metric-card strong {
    font-size: 24px;
}

.admin-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px 1fr;
}

.admin-sidebar {
    min-height: 100vh;
    padding: 22px;
    color: #fff;
    background: #101820;
    position: sticky;
    top: 0;
}

.admin-logo {
    margin-bottom: 28px;
}

.admin-logo img {
    background: #087f8c;
}

.admin-sidebar nav {
    display: grid;
    gap: 8px;
}

.admin-sidebar nav a,
.logout-link {
    display: block;
    padding: 11px 12px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.82);
}

.admin-sidebar nav a:hover,
.logout-link:hover {
    background: rgba(255, 255, 255, 0.10);
    color: #fff;
}

.logout-link {
    margin-top: 28px;
}

.admin-main {
    padding: 24px;
}

.admin-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
}

.admin-topbar h1 {
    font-size: 26px;
}

.admin-user {
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.content-section {
    padding: 20px;
    margin-bottom: 18px;
}

.two-column {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
}

.admin-card {
    padding: 20px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.section-head h2 {
    margin: 0;
    font-size: 18px;
}

.detail-list {
    display: grid;
    grid-template-columns: 96px 1fr;
    gap: 10px 14px;
    margin: 0;
}

.detail-list dt {
    color: var(--muted);
}

.detail-list dd {
    margin: 0;
    word-break: break-all;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    padding: 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-weight: 600;
    background: var(--surface-soft);
}

td pre {
    max-width: 420px;
    max-height: 220px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
    padding: 10px;
    border-radius: 8px;
    background: #f3f5f6;
}

.empty-cell,
.empty-text {
    color: var(--muted);
    text-align: center;
}

.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.filter-bar input {
    max-width: 420px;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.pagination a {
    min-width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.pagination a.active {
    color: #fff;
    border-color: var(--primary);
    background: var(--primary);
}

.settings-section {
    max-width: 860px;
}

.settings-form {
    display: grid;
    gap: 16px;
}

.settings-group {
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.settings-group h2 {
    margin: 0;
    font-size: 17px;
}

.compact-textarea {
    min-height: 96px;
}

.switch-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.switch-row input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.switch-row span {
    margin: 0;
    color: var(--text);
}

.form-split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

@media (max-width: 1100px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .control-panel {
        position: static;
    }

    .status-grid,
    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 780px) {
    .front-header {
        height: auto;
        align-items: flex-start;
        gap: 12px;
        padding: 14px;
        flex-direction: column;
    }

    .workspace {
        padding: 12px;
        min-height: auto;
    }

    .toolbar,
    .filter-bar,
    .install-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .preview-panel {
        grid-template-rows: minmax(240px, auto) 1fr;
    }

    .form-grid,
    .form-split,
    .two-column,
    .status-grid,
    .metric-grid {
        grid-template-columns: 1fr;
    }

    .admin-page {
        display: block;
    }

    .admin-sidebar {
        min-height: auto;
        position: static;
    }

    .admin-main {
        padding: 14px;
    }

    .admin-topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .detail-list {
        grid-template-columns: 1fr;
    }
}

@media print {
    @page {
        size: A4;
        margin: 8mm;
    }

    body.front-page.is-printing {
        background: #fff;
    }

    body.front-page.is-printing .front-header,
    body.front-page.is-printing .workspace {
        display: none !important;
    }

    body.front-page.is-printing .print-area {
        display: block !important;
    }

    body.front-page.is-printing .print-page {
        min-height: 281mm;
        display: flex;
        flex-direction: column;
        break-after: page;
        page-break-after: always;
    }

    body.front-page.is-printing .print-page:last-child {
        break-after: auto;
        page-break-after: auto;
    }

    body.front-page.is-printing .print-grid {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 3.2mm 3.5mm;
        align-content: start;
    }

    body.front-page.is-printing .print-item {
        min-height: 29mm;
        padding: 1.6mm;
        border: 1px solid #cfd4dc;
        break-inside: avoid;
        page-break-inside: avoid;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 1mm;
    }

    body.front-page.is-printing .print-order {
        align-self: flex-start;
        color: #4b5563;
        font-size: 8pt;
        line-height: 1;
    }

    body.front-page.is-printing .print-svg {
        width: 100%;
        max-height: 24mm;
        height: auto;
    }

    body.front-page.is-printing .print-footer {
        margin-top: auto;
        padding-top: 2mm;
        border-top: 1px solid #d1d5db;
        color: #4b5563;
        display: flex;
        justify-content: space-between;
        font-size: 8pt;
        line-height: 1.2;
    }

    body.front-page.is-printing .barcode-error {
        min-height: 22mm;
        padding: 1mm;
        border: 1px dashed #999;
        border-radius: 0;
        background: #fff;
        color: #111;
        font-size: 8pt;
    }

    body.front-page.is-printing .barcode-error span {
        color: #333;
        font-size: 7pt;
    }
}
