:root {
    --bg: #0b1220;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: rgba(255, 255, 255, .10);
    --shadow: 0 18px 60px rgba(0, 0, 0, .40);
    --radius: 14px;
    --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    /* key: prevent right-drift */
}

body {
    margin: 0;
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(1200px 500px at 10% 0%, rgba(96, 165, 250, .22), transparent 60%),
        radial-gradient(900px 420px at 90% 10%, rgba(52, 211, 153, .14), transparent 60%),
        var(--bg);
    -webkit-text-size-adjust: 100%;
}

/* Media elements can cause overflow */
img,
svg,
video,
canvas {
    max-width: 100%;
    height: auto;
}

/* Common layout */
.wrap {
    max-width: 1200px;
    margin: 28px auto;
    padding: 0 16px;
}

.panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    background: linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, .03));
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(96, 165, 250, .95), rgba(52, 211, 153, .85));
    box-shadow: var(--shadow);
}

.title h1 {
    font-size: 18px;
    margin: 0;
}

.title p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.hint {
    color: var(--muted);
    font-size: 12px;
}

/* Toolbar + controls */
.toolbar {
    padding: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, .08);
}

.input,
select {
    background: rgba(40, 40, 40, .80);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 12px;
    padding: 10px 12px;
    outline: none;
    min-height: 40px;
    max-width: 100%;
}

/* iOS: prevent zoom-on-focus by keeping inputs >= 16px */
input,
select,
textarea {
    font-size: 16px;
}

.input {
    flex: 1;
    min-width: 220px;
}

select {
    min-width: 160px;
}

.input:focus,
select:focus {
    border-color: rgba(96, 165, 250, .55);
}

select option {
    background-color: #1f2937;
    color: #e5e7eb;
}

select option:disabled {
    color: #9ca3af;
}

/* Buttons */
.btn {
    border: 1px solid var(--border);
    background: rgba(96, 165, 250, .18);
    color: var(--text);
    padding: 10px 12px;
    border-radius: 12px;
    cursor: pointer;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    white-space: nowrap;
}

.btn.secondary {
    background: rgba(255, 255, 255, .06);
}

.btn.danger {
    background: rgba(251, 113, 133, .16);
}

.actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
}

.actions .btn {
    padding: 8px 10px;
    border-radius: 10px;
    min-height: 34px;
}

.iconbtn {
    width: 40px;
    justify-content: center;
    padding: 8px 0;
    font-size: 16px;
}

.linkbtn[aria-disabled="true"] {
    opacity: .45;
    pointer-events: none;
    filter: grayscale(1);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    max-width: 100%;
}

th,
td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 14px;
    vertical-align: middle;
}

th {
    color: #cbd5e1;
    font-weight: 600;
    user-select: none;
    background: rgba(255, 255, 255, .03);
    position: sticky;
    top: 0;
}

.toast {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, .75);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    display: none;
    font-size: 13px;
    max-width: min(520px, calc(100% - 24px));
}

/* Books mobile cards (you already use these) */
.cards {
    display: none;
    padding: 12px;
}

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(0, 0, 0, .15);
    padding: 14px;
    margin-bottom: 12px;
}

.card h3 {
    margin: 0 0 6px;
    font-size: 16px;
}

.meta {
    color: var(--muted);
    font-size: 13px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.card .actions.one-row {
    justify-content: space-between;
    gap: 8px;
    flex-wrap: nowrap;
}

.card .actions.one-row .left,
.card .actions.one-row .right {
    display: flex;
    gap: 8px;
    align-items: center;
}

@media (max-width:900px) {
    table {
        display: none;
    }

    .cards {
        display: block;
    }

    .input {
        min-width: 100%;
    }

    .toolbar {
        align-items: stretch;
    }

    .toolbar .btn {
        justify-content: center;
    }

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

    .card h3 {
        font-size: 18px;
    }

    .linkbtn[aria-disabled="true"] {
        opacity: .18;
        filter: grayscale(1) blur(.2px);
    }

    .logout-text {
        display: none;
    }

    .logout-icon {
        display: inline;
    }

    .logout {
        padding: 9px 10px;
        border-radius: 12px;
    }
}

/* Login page helpers */
.page-login {
    background: #ffffff;
    color: #111827;
}

.login-wrap {
    max-width: 420px;
    margin: 40px auto;
    padding: 0 16px;
}

.login-card {
    padding: 24px;
    border: 1px solid #ddd;
    border-radius: 12px;
    background: #fff;
}

.login-card label {
    display: block;
    margin-top: 12px;
    font-weight: 600;
}

.login-card input {
    width: 100%;
    padding: 10px;
    margin-top: 6px;
    border: 1px solid #ccc;
    border-radius: 8px;
    color: #111827;
    background: #fff;
}

.login-card button {
    margin-top: 16px;
    width: 100%;
    padding: 10px;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.msg {
    margin-top: 12px;
    color: #b00020;
}

.modal-card {
    background: #0b1220 !important;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* Ensure long links in enrichment confirmation wrap on mobile/desktop */
#confirmText a {
    word-break: break-all;
}