:root {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f5f7fb;
    color: #1f2937;
}

.container {
    max-width: 1360px;
    padding: 12px;
}

.card {
    background: #fff;
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 2px 12px rgba(15, 23, 42, .08);
    margin-bottom: 12px;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.app-header .header-button {
    display: flex;
    gap: 4px;
}

.app-header .header-button button {
    padding: 6px 12px;
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
    cursor: pointer;
    border-radius: 4px;
}

h1 {
    margin: 0;
    font-size: 22px;
}

h3 {
    margin: 0 0 10px;
}

.row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.grid3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.field label {
    font-size: 12px;
    color: #6b7280;
}

input,
button,
select,
textarea {
    padding: 9px 10px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
}

textarea {
    min-height: 84px;
}

button {
    white-space: nowrap;
    padding: 6px 12px;
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

button.secondary {
    background: #fff;
    color: #2563eb;
}

button:disabled {
    opacity: .72;
    cursor: not-allowed;
}

.material-icons.spin {
    animation: icon-spin 1s linear infinite;
}

@keyframes icon-spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.status {
    font-size: 13px;
    color: #374151;
}

.table-wrap {
    overflow-x: auto;
    width: 100%;
}

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

th,
td {
    border-bottom: 1px solid #eef2f7;
    text-align: left;
    padding: 8px;
    vertical-align: top;
    white-space: nowrap;
}

th {
    background: #fafafa;
}

.tag {
    display: inline-block;
    font-size: 12px;
    white-space: nowrap;
    padding: 2px 8px;
    border-radius: 999px;
    background: #e5edff;
    color: #1d4ed8;
}

.danger {
    background: #ffe5e5;
    color: #b91c1c;
}

.wl-found {
    background: #dcfce7;
    color: #166534;
}

.wl-temp {
    background: #fef3c7;
    color: #92400e;
}

.wl-alarm {
    background: #ffe5e5;
    color: #b91c1c;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.warn {
    color: #b45309;
    font-size: 12px;
}

.app-tabs {
    position: sticky;
    top: 0;
    z-index: 50;
    background: #f5f7fb;
    padding: 8px 0;
    margin-bottom: 8px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
}

.app-tab {
    flex: 0 0 auto;
    background: #fff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    white-space: nowrap;
}

.app-tab.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.page-panel {
    display: none;
    opacity: 0;
    transform: translateY(8px);
}

.page-panel.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
    animation: panelIn .22s ease;
}

.tabs {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    margin-bottom: 12px;
}

.tabs-wrap {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.tabs button {
    width: -webkit-fill-available;
}

.tab {
    background: #fff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.tab.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-group input,
.input-group select {
    width: 100%;
}

.group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.group input,
.group select,
.group button {
    height: 36px;
}

.toast-wrap {
    position: fixed;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toast {
    white-space: nowrap;
    pointer-events: auto;
    background: #111827;
    color: #fff;
    border-radius: 100px;
    padding: 8px 14px;
    box-shadow: 0 6px 24px rgba(2, 6, 23, .28);
    border: 1px solid rgba(255, 255, 255, .08);
    opacity: 0;
    transform: translateY(-14px);
    animation: toastIn .22s ease forwards;
    font-size: 13px;
}

.toast.success {
    background: #252525;
}

.toast.error {
    background: #991b1b;
}

.toast.recognize {
    background: #1e3a8a;
}

.toast-title {
    font-weight: 700;
    margin-right: 6px;
}

.toast.hide {
    animation: toastOut .18s ease forwards;
}

.latest-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.latest-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.latest-grid {
    display: grid;
    grid-template-columns: 1.1fr 1.9fr;
    gap: 14px;
    align-items: stretch;
}

.latest-info {
    display: grid;
    gap: 8px;
}

.latest-line {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 8px;
    align-items: center;
    font-size: 13px;
}

.latest-label {
    color: #6b7280;
    font-size: 12px;
}

.latest-images {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 8px;
    align-items: stretch;
    position: relative;
}

.latest-image {
    position: relative;
    display: block;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    background: #f8fafc;
}

#latestThumbImg {
    position: absolute;
    bottom: 15px;
    right: 8px;
    width: auto;
    height: 60px;
    border-radius: 6px;
    border: 1px solid #4747478f;
}

.latest-image.big {
    min-height: 180px;
}

.latest-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.latest-image img[src=""] {
    display: none;
}

.latest-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.latest-actions button {
    flex: 1;
    min-width: 80px;
}

/* ---------- History collapsible cards ---------- */

.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 600px;
    overflow-y: auto;
}

.history-item {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    transition: box-shadow .15s;
}

.history-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.history-summary {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
}

.history-summary .material-icons.expand-icon {
    font-size: 18px;
    color: #9ca3af;
    transition: transform .2s;
}

.history-item.open .history-summary .expand-icon {
    transform: rotate(180deg);
}

.history-plate {
    font-weight: 700;
    font-size: 15px;
    min-width: 100px;
}

.history-time {
    font-size: 12px;
    color: #6b7280;
    margin-left: auto;
    white-space: nowrap;
}

.history-detail {
    display: none;
    padding: 0 14px 12px;
    animation: panelIn .15s ease;
}

.history-item.open .history-detail {
    display: block;
}

.history-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 6px 16px;
    font-size: 13px;
    margin-bottom: 8px;
}

.history-detail-grid .dl { display: flex; gap: 4px; }
.history-detail-grid .dl dt { color: #6b7280; white-space: nowrap; }
.history-detail-grid .dl dd { margin: 0; font-weight: 600; }

.history-thumb {
    width: 160px;
    max-height: 120px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    margin-top: 4px;
    cursor: pointer;
}

.card-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed #e5e7eb;
}

.card-actions button {
    font-size: 12px;
    padding: 4px 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.card-actions button .material-icons {
    font-size: 15px;
}

/* ---------- Detail modal nav ---------- */
.detail-nav {
    display: flex;
    gap: 6px;
}

.detail-nav button {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 4px;
}

.detail-nav button .material-icons {
    font-size: 18px;
}

.detail-actions {
    display: flex;
    gap: 6px;
}

.detail-actions button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    padding: 4px 12px;
    border-radius: 4px;
}

.detail-actions button .material-icons {
    font-size: 16px;
}

/* ---------- Whitelist card summary extras ---------- */
.wl-summary-field {
    font-size: 12px;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 4px;
}

.wl-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    flex-shrink: 0;
}

.wl-id {
    font-size: 11px;
    color: #9ca3af;
    font-family: 'Menlo', 'Consolas', monospace;
    min-width: 30px;
}

/* ---------- Device info panel ---------- */
.device-info-panel {
    margin-top: 8px;
    padding: 10px 14px;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    font-size: 13px;
}

.device-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 6px 20px;
}

.device-info-grid .dl {
    display: flex;
    gap: 6px;
    align-items: center;
}

.device-info-grid .dl dt {
    color: #6b7280;
    white-space: nowrap;
    font-size: 12px;
}

.device-info-grid .dl dd {
    margin: 0;
    font-weight: 600;
    font-size: 13px;
}

dialog.modal {
    border: none;
    background: transparent;
    padding: 0;
    max-width: none;
    max-height: none;
    width: fit-content;
    overflow: visible;
}

dialog.modal::backdrop {
    background: rgba(15, 23, 42, .55);
}

.modal-card {
    width: min(720px, 92vw);
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, .28);
    padding: 16px;
    animation: modalIn .2s ease;
}

.modal-card.modal-wide {
    width: min(960px, 96vw);
    max-height: 80vh;
}

.modal-card.modal-wide .modal-body {
    max-height: 60vh;
    overflow-y: auto;
}

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

.modal-body {
    padding-bottom: 8px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.icon-btn {
    border: none;
    background: transparent;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: #6b7280;
    padding: 4px 6px;
}

.icon-btn .material-icons {
    font-size: 22px;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-14px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

@keyframes panelIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 980px) {

    .grid2,
    .grid3 {
        grid-template-columns: 1fr;
    }

    .row>* {
        width: 100%;
    }

    .row>label {
        width: auto;
    }

    .row>button {
        width: 100%;
    }

    h1 {
        font-size: 20px;
    }

    .card {
        padding: 12px;
    }

    .latest-grid {
        grid-template-columns: 1fr;
    }

    .latest-images {
        grid-template-columns: 1fr;
    }

    table {
        min-width: 640px;
    }
}