:root {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #172033;
    background: #eef2f7;
    line-height: 1.45;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem max(1rem, env(safe-area-inset-left));
    background: #0b5ed7;
    color: white;
}

.topbar h1 {
    margin: 0;
    font-size: clamp(1.3rem, 4vw, 2rem);
}

.topbar p {
    margin: .2rem 0 0;
    opacity: .82;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: .55rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.counter, .badge {
    white-space: nowrap;
    padding: .45rem .7rem;
    border-radius: 999px;
    background: rgba(255,255,255,.16);
    font-weight: 700;
}

.header-link {
    color: white;
    text-decoration: none;
    font-weight: 700;
    border: 1px solid rgba(255,255,255,.45);
    border-radius: 9px;
    padding: .45rem .7rem;
}

.layout, .settings-page {
    width: min(1180px, calc(100% - 2rem));
    margin: 1rem auto 3rem;
    display: grid;
    gap: 1rem;
}

.settings-page {
    max-width: 820px;
}

.card {
    background: white;
    border-radius: 14px;
    padding: 1rem;
    box-shadow: 0 5px 18px rgba(23, 32, 51, .08);
}

.card h2 { margin: 0 0 1rem; }

.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .85rem;
}

label {
    display: grid;
    gap: .35rem;
    font-size: .9rem;
    font-weight: 650;
}

input, select {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 9px;
    padding: .78rem;
    font: inherit;
    background: white;
}

input:focus, select:focus {
    outline: 3px solid rgba(11, 94, 215, .16);
    border-color: #0b5ed7;
}

.hint {
    margin: .8rem 0 0;
    color: #64748b;
    font-size: .88rem;
}

#reader {
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 12px;
}

.actions {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    margin-top: .9rem;
}

.actions.compact { margin: 0; }

button, .button {
    border: 0;
    border-radius: 9px;
    padding: .72rem 1rem;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}

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

.primary { background: #0b5ed7; color: white; }
.secondary { background: #e2e8f0; color: #172033; }
.success { background: #198754; color: white; }
.danger { background: #fff0f0; color: #b42318; }

.manual {
    margin-top: 1.2rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}

.manual-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .6rem;
    margin-top: .4rem;
}

.status {
    margin-top: 1rem;
    padding: .75rem;
    border-radius: 9px;
}

.status.neutral { background: #f1f5f9; }
.status.success { background: #e8f7ee; color: #146c43; }
.status.warning { background: #fff4d6; color: #8a5a00; }
.status.error { background: #fdecec; color: #b42318; }

.last-code {
    margin-top: 1rem;
    display: grid;
    gap: .2rem;
    text-align: center;
    padding: 1rem;
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
}

.last-code span { color: #64748b; }
.last-code strong {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: clamp(1.2rem, 5vw, 2rem);
    overflow-wrap: anywhere;
}

.list-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.list-heading h2 { margin: 0; }

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

table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    font-size: .82rem;
    color: #64748b;
    text-transform: uppercase;
}

.empty {
    text-align: center;
    color: #64748b;
    padding: 2rem;
}

.icon-button {
    padding: .35rem .6rem;
    background: #fff0f0;
    color: #b42318;
}

.storage-status {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .8rem;
}

.storage-status div {
    background: #f1f5f9;
    padding: 1rem;
    border-radius: 10px;
    display: grid;
    gap: .2rem;
}

.storage-status span {
    color: #64748b;
    font-size: .85rem;
}

.storage-status strong {
    font-size: 1.35rem;
}

.storage-option {
    grid-template-columns: auto 1fr;
    align-items: start;
    gap: .8rem;
    padding: 1rem;
    border: 1px solid #dbe3ee;
    border-radius: 12px;
    margin-bottom: .8rem;
}

.storage-option input {
    width: auto;
    margin-top: .25rem;
}

.storage-option span {
    display: grid;
    gap: .2rem;
}

.storage-option small {
    color: #64748b;
    font-weight: 400;
}

.migration-box {
    margin-top: 1rem;
    display: grid;
    gap: .8rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}

@media (min-width: 900px) {
    .layout {
        grid-template-columns: 1fr 1fr;
    }
    .settings, .list-card {
        grid-column: 1 / -1;
    }
}

@media (max-width: 720px) {
    .grid, .storage-status {
        grid-template-columns: 1fr;
    }
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }
    .header-actions {
        justify-content: flex-start;
    }
    .list-heading {
        align-items: stretch;
        flex-direction: column;
    }
    .actions.compact {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}
