:root {
    color-scheme: light;
    --ink: #172026;
    --muted: #68737d;
    --line: #d9dfe3;
    --surface: #ffffff;
    --canvas: #edf1f2;
    --primary: #087f5b;
    --primary-strong: #056247;
    --primary-soft: #e6f5ef;
    --danger: #bf3b35;
    --danger-soft: #fff0ef;
    --amber: #a45b08;
    --shadow: 0 10px 30px rgba(23, 32, 38, 0.08);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--canvas);
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100dvh;
    background: var(--canvas);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    letter-spacing: 0;
}

button,
input,
select,
textarea {
    font: inherit;
    letter-spacing: 0;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(8, 127, 91, 0.22);
    outline-offset: 2px;
}

#loginOverlay {
    padding: 20px;
    background: #20292e;
}

.tech-grid {
    display: none;
}

.login-box {
    width: min(100%, 380px);
    max-width: 100%;
    padding: 32px;
    border: 0;
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.26);
    backdrop-filter: none;
}

.login-mark {
    width: 52px;
    height: 52px;
    margin-bottom: 18px;
    border-radius: 8px;
    box-shadow: 0 5px 16px rgba(23, 32, 38, 0.14);
}

.login-box h1 {
    margin: 0;
    color: var(--ink);
    font-size: 24px;
    font-weight: 760;
    letter-spacing: 0;
}

.login-box h1 span {
    color: inherit;
}

.login-box p {
    margin: 7px 0 24px;
    color: var(--muted);
    font-size: 13px;
    letter-spacing: 0;
}

.tech-input {
    width: 100%;
    min-height: 50px;
    margin: 0 0 12px;
    padding: 0 14px;
    border: 1px solid #cbd3d7;
    border-radius: 7px;
    background: #fff;
    color: var(--ink);
    font-family: inherit;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 6px;
}

.tech-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8, 127, 91, 0.11);
    color: var(--ink);
}

.tech-input::placeholder {
    color: #929ba2;
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0;
}

#loginPin {
    border-width: 2px;
    border-color: #aeb8be;
    background: #ffffff;
    color: #101820;
    -webkit-text-fill-color: #101820;
    caret-color: var(--primary);
    opacity: 1;
}

#loginPin:focus {
    border-color: var(--primary);
    background: #ffffff;
    color: #101820;
    -webkit-text-fill-color: #101820;
    box-shadow: 0 0 0 3px rgba(8, 127, 91, 0.16);
}

#loginPin::placeholder {
    color: #68737d;
    -webkit-text-fill-color: #68737d;
    opacity: 1;
}

.tech-btn {
    min-height: 50px;
    border-radius: 7px;
    background: var(--primary);
    font-size: 15px;
    letter-spacing: 0;
}

.tech-btn:hover {
    box-shadow: none;
    filter: brightness(0.96);
    transform: none;
}

.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 68px;
    margin: 0;
    padding: 10px max(18px, calc((100vw - 1240px) / 2));
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: none;
    backdrop-filter: blur(12px);
}

.navbar-title-group,
.navbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.navbar h2 {
    color: var(--ink);
    font-size: 18px;
}

.refresh-control {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #f6f8f8 !important;
}

.switch {
    width: 40px;
    height: 22px;
}

.slider {
    border-radius: 22px;
}

.slider:before {
    width: 16px;
    height: 16px;
}

input:checked + .slider {
    background: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(18px);
}

#refreshStatusText {
    color: var(--muted) !important;
    font-size: 12px !important;
}

.container {
    width: min(100%, 1240px);
    max-width: 1240px;
    margin: 0 auto;
    padding: 18px;
}

.filter-card,
.table-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.filter-card {
    display: grid;
    grid-template-columns: 1.25fr 1fr 1fr auto;
    align-items: end;
    gap: 12px;
    padding: 16px;
}

.filter-group {
    min-width: 0;
}

.filter-group label {
    color: var(--muted) !important;
    font-size: 12px;
}

.quick-dates {
    min-height: 23px;
}

.date-link {
    color: var(--primary);
    font-size: 12px;
}

.date-range-wrapper {
    width: 100%;
}

.filter-input,
.page-select,
.page-btn {
    min-height: 42px;
    border: 1px solid #cdd4d8;
    border-radius: 7px;
    background: #fff;
    color: var(--ink);
}

.filter-input {
    width: 100%;
    padding: 0 11px;
}

.filter-input:focus {
    border-color: var(--primary);
}

.btn,
.back-btn,
.logout-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-height: 42px;
    margin: 0;
    padding: 0 13px;
    border: 1px solid transparent;
    border-radius: 7px;
    box-shadow: none;
    font-size: 13px;
    font-weight: 700;
}

.btn-primary,
.btn-success {
    background: var(--primary);
}

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

.btn-reset,
.back-btn {
    border-color: var(--line);
    background: #f5f7f7;
    color: #44505a;
}

.logout-btn {
    border-color: #e8c3c0;
    color: var(--danger);
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 42px;
    min-width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
}

.search-actions {
    min-width: 170px;
}

.table-header-tools {
    min-height: 60px;
    padding: 10px 14px;
    border-bottom-color: var(--line);
    background: #fff;
}

#dataStats {
    color: var(--primary) !important;
}

#trashTools {
    background: var(--danger-soft) !important;
}

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

table {
    min-width: 860px;
}

th,
td {
    padding: 12px;
    border-bottom-color: #e8ecee;
}

th {
    background: #f5f7f7;
    color: var(--muted);
}

td {
    color: #44505a;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.clickable-badge,
.copy-btn-mini {
    min-height: 34px;
    padding: 6px 9px;
    border-radius: 6px;
    background: var(--primary-soft);
    color: var(--primary-strong);
    border-color: #c7e2d7;
}

.pagination-container {
    min-height: 62px;
    border-top-color: var(--line);
    background: #fff;
}

.page-select {
    padding: 0 8px;
}

.page-btn {
    padding: 0 12px;
}

.modal-overlay {
    padding: 18px;
    background: rgba(12, 18, 21, 0.62);
    backdrop-filter: blur(3px);
}

.modal-box {
    width: min(100%, 480px);
    padding: 20px;
    border-radius: 8px;
}

.detail-textarea {
    min-height: 260px;
    padding: 12px;
    border-radius: 7px;
    line-height: 1.55;
}

.toast-msg {
    top: auto;
    bottom: calc(24px + var(--safe-bottom));
    width: max-content;
    max-width: calc(100vw - 32px);
    padding: 11px 18px;
    border-radius: 7px;
    background: rgba(23, 32, 38, 0.94);
    white-space: normal;
}

.toast-error {
    background: rgba(154, 42, 37, 0.96);
}

body[data-theme="dark"] {
    --ink: #eef2f3;
    --muted: #a5afb5;
    --line: #3b464c;
    --surface: #20292e;
    --canvas: #151b1f;
    --primary: #38bd8d;
    --primary-strong: #64d4ab;
    --primary-soft: #193c32;
    background: var(--canvas);
    color: var(--ink);
}

body[data-theme="dark"] .navbar,
body[data-theme="dark"] .filter-card,
body[data-theme="dark"] .table-card,
body[data-theme="dark"] .modal-box,
body[data-theme="dark"] .pagination-container,
body[data-theme="dark"] .table-header-tools,
body[data-theme="dark"] .icon-btn {
    border-color: var(--line);
    background: var(--surface);
    box-shadow: none;
}

body[data-theme="dark"] th {
    background: #182024;
    color: var(--muted);
}

body[data-theme="dark"] td {
    border-color: var(--line);
    color: var(--ink) !important;
}

body[data-theme="dark"] .filter-input,
body[data-theme="dark"] .page-select,
body[data-theme="dark"] .page-btn,
body[data-theme="dark"] .detail-textarea,
body[data-theme="dark"] .back-btn,
body[data-theme="dark"] .btn-reset {
    border-color: var(--line);
    background: #182024;
    color: var(--ink);
}

@media (max-width: 900px) {
    .filter-card {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 680px) {
    .navbar {
        position: static;
        gap: 9px;
        padding: 10px 12px;
    }

    .navbar-title-group,
    .navbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .navbar-actions {
        display: grid !important;
        grid-template-columns: 1fr 42px 1fr 1fr;
        overflow: visible !important;
    }

    .navbar-actions .btn,
    .navbar-actions .back-btn,
    .navbar-actions .logout-btn {
        width: 100% !important;
        min-width: 0;
        padding: 0 7px !important;
        overflow-wrap: anywhere;
        white-space: normal !important;
    }

    .container {
        padding: 12px;
    }

    .filter-card {
        grid-template-columns: 1fr;
        gap: 11px;
        padding: 14px;
    }

    .date-range-wrapper {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .search-actions {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        width: 100%;
        min-width: 0;
        margin: 0 !important;
    }

    .search-actions .btn {
        width: 100%;
    }

    .table-card {
        border: 0;
        background: transparent;
        box-shadow: none;
    }

    .table-header-tools {
        align-items: stretch;
        margin-bottom: 10px;
        border: 1px solid var(--line);
        border-radius: 8px;
    }

    .table-header-tools > div {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        width: 100%;
    }

    .table-header-tools .btn {
        width: 100%;
    }

    .table-responsive {
        overflow: visible;
    }

    table,
    tbody,
    tr,
    td {
        display: block;
        width: 100%;
        min-width: 0;
    }

    thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
    }

    tbody tr {
        position: relative;
        margin-bottom: 10px;
        padding: 12px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--surface);
        box-shadow: 0 6px 18px rgba(23, 32, 38, 0.06);
    }

    tbody td {
        display: grid;
        grid-template-columns: 88px minmax(0, 1fr);
        align-items: start;
        gap: 8px;
        min-height: 38px;
        padding: 8px 0;
        border-bottom: 1px solid #e8ecee;
        overflow-wrap: anywhere;
    }

    tbody td::before {
        color: var(--muted);
        font-size: 12px;
        font-weight: 700;
    }

    tbody td:nth-child(1)::before { content: "选择"; }
    tbody td:nth-child(2)::before { content: "记录"; }
    tbody td:nth-child(3)::before { content: "批次"; }
    tbody td:nth-child(4)::before { content: "时间"; }
    tbody td:nth-child(5)::before { content: "序列号"; }
    tbody td:nth-child(6)::before { content: "操作"; }

    tbody td:last-child {
        border-bottom: 0;
    }

    tbody td > div {
        flex-wrap: wrap;
    }

    tbody td .btn {
        min-height: 38px;
    }

    .pagination-container {
        justify-content: center;
        gap: 8px;
        margin-top: 2px;
        padding: 12px 6px calc(12px + var(--safe-bottom));
        border: 0;
        background: transparent;
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-box {
        width: 100%;
        max-width: none;
        max-height: 92dvh;
        padding: 18px 14px calc(16px + var(--safe-bottom));
        border-radius: 8px 8px 0 0;
    }

    .modal-actions .btn {
        flex: 1;
        width: auto;
    }
}

@media (max-width: 380px) {
    .navbar h2 {
        font-size: 15px;
    }

    .refresh-control {
        padding: 0 7px;
    }

    #refreshStatusText {
        display: none;
    }

    .navbar-actions {
        grid-template-columns: 1fr 42px 1fr;
    }

    .navbar-actions .logout-btn {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
