:root {
    color: #202124;
    background: #f5f6f8;
    font-family: Arial, "Microsoft JhengHei", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
}

main {
    min-height: 100vh;
}

h1,
h2 {
    margin-top: 0;
}

button,
input {
    font: inherit;
}

button {
    min-height: 38px;
    padding: 7px 18px;
    border: 1px solid #175cd3;
    border-radius: 4px;
    color: #ffffff;
    background: #175cd3;
    cursor: pointer;
    white-space: nowrap;
}

button:not(:disabled):hover {
    background: #144eaf;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

button.secondary {
    border-color: #68707d;
    color: #343a40;
    background: #ffffff;
}

button.secondary:not(:disabled):hover {
    background: #eceff3;
}

button.success {
    border-color: #198754;
    background: #198754;
}

button.success:not(:disabled):hover {
    background: #146c43;
}

button.danger {
    border-color: #c92a2a;
    background: #c92a2a;
}

button.danger:not(:disabled):hover {
    background: #a61e1e;
}

button.small {
    min-height: 28px;
    padding: 2px 10px;
    font-size: 13px;
}

input {
    min-height: 38px;
    padding: 7px 10px;
    border: 1px solid #aeb4bd;
    border-radius: 4px;
    background: #ffffff;
}

input:focus {
    border-color: #175cd3;
    outline: 2px solid #d7e5ff;
}

.login-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
}

.login-card {
    display: grid;
    width: min(100%, 360px);
    gap: 10px;
    padding: 28px;
    border: 1px solid #d8dce2;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.login-card h1 {
    margin-bottom: 14px;
    text-align: center;
}

.login-card button {
    margin-top: 14px;
}

.page-shell {
    width: min(1100px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0;
}

.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.title-row h1 {
    margin-bottom: 0;
}

.page-shell > hr {
    margin: 0 0 28px;
    border: 0;
    border-top: 1px solid #d8dce2;
}

.filter-row,
.dialog-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toolbar {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.loading-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#queryButton,
#createButton {
    width: 76px;
}

.loading-button.loading {
    cursor: wait;
}

.loading-spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.loading-button.loading .button-text {
    display: none;
}

.loading-button.loading .loading-spinner {
    display: block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.filter-row {
    margin-bottom: 14px;
}

.filter-row input {
    width: min(100%, 320px);
    min-width: 0;
}

#clearFilterButton {
    flex: none;
}

#clearFilterButton:disabled {
    border-color: #c8cdd4;
    color: #9298a1;
    background: #e3e6ea;
    opacity: 1;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid #d8dce2;
    border-radius: 6px;
    background: #ffffff;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th,
td {
    padding: 7px 10px;
    border-bottom: 1px solid #e3e6ea;
    text-align: left;
    white-space: nowrap;
}

th {
    background: #eef2f7;
}

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

.empty-row {
    padding: 30px;
    color: #68707d;
    text-align: center;
}

dialog {
    width: min(420px, calc(100% - 32px));
    padding: 24px;
    border: 0;
    border-radius: 8px;
    box-shadow: 0 12px 38px rgba(0, 0, 0, 0.28);
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.45);
}

#createDialog {
    width: min(460px, calc(100% - 32px));
}

dialog label,
dialog input {
    display: block;
    width: 100%;
}

dialog label {
    margin-bottom: 6px;
}

.create-account-warning {
    margin: 0 0 16px;
    color: #c92a2a;
    font-size: 14px;
    line-height: 1.5;
}

.dialog-actions {
    justify-content: flex-end;
    margin-top: 20px;
}

.qr-panel {
    text-align: center;
}

.qr-panel img {
    display: block;
    margin: 18px auto;
    border: 1px solid #d8dce2;
}

.app-download-dialog {
    width: min(650px, calc(100% - 32px));
}

.app-download-dialog .dialog-actions {
    justify-content: center;
}

.app-download-section + .app-download-section {
    margin-top: 24px;
}

.app-download-section h3 {
    margin: 0 0 12px;
}

.download-qr-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, 190px);
    justify-content: center;
    gap: 16px;
}

.download-qr-card {
    text-align: center;
}

.download-qr-card p {
    margin: 0 0 8px;
}

.download-qr-card img {
    display: block;
    margin: 0 auto;
    border: 1px solid #d8dce2;
}

.download-empty {
    grid-column: 1 / -1;
    margin: 0;
    padding: 20px;
    color: #68707d;
    text-align: center;
}

@media (max-width: 640px) {
    #queryButton {
        grid-row: 1;
        grid-column: 1;
        justify-self: start;
    }

    #addButton {
        grid-row: 1;
        grid-column: 3;
    }

    #appDownloadButton {
        grid-row: 1;
        grid-column: 4;
        justify-self: end;
    }

    .last-query-time {
        grid-row: 2;
        grid-column: 1 / -1;
    }
}

@media (max-width: 400px) {
    .toolbar {
        grid-template-columns: repeat(3, 1fr);
    }

    #queryButton {
        width: 100%;
        grid-column: 1;
    }

    #addButton {
        width: 100%;
        grid-column: 2;
    }

    #appDownloadButton {
        width: 100%;
        grid-column: 3;
    }

    .filter-row {
        flex-wrap: wrap;
    }

    .filter-row input,
    #clearFilterButton {
        width: 100%;
        flex: none;
    }
}
