:root {
    --bg: #f5f7fb;
    --panel: rgba(255, 255, 255, 0.88);
    --panel-strong: #ffffff;
    --text: #162033;
    --muted: #6d7890;
    --soft: rgba(58, 87, 136, 0.08);
    --soft-strong: rgba(58, 87, 136, 0.14);
    --shadow: 0 24px 70px rgba(31, 45, 80, 0.10);
    --shadow-card: 0 14px 36px rgba(31, 45, 80, 0.12);
    --radius-xl: 28px;
    --radius-lg: 22px;
    --radius-md: 16px;
    --accent: #365a9e;
    --danger: #b83d4b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(80, 118, 190, 0.14), transparent 32rem),
        linear-gradient(135deg, #f8fafc 0%, #eef3fb 100%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
    border: 0;
    border-radius: 999px;
    padding: 0.85rem 1.2rem;
    background: linear-gradient(135deg, #203a74, #4b72c0);
    color: #fff;
    box-shadow: 0 14px 26px rgba(52, 83, 150, 0.22);
    transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 18px 34px rgba(52, 83, 150, 0.28);
}

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

button.secondary {
    background: rgba(255, 255, 255, 0.78);
    color: var(--text);
    box-shadow: none;
}

input,
select,
textarea {
    width: 100%;
    border: 0;
    border-radius: 16px;
    padding: 0.9rem 1rem;
    background: rgba(41, 71, 122, 0.08);
    color: var(--text);
    outline: none;
    box-shadow: inset 0 0 0 1px transparent;
    transition: background 180ms ease, box-shadow 180ms ease;
}

textarea {
    min-height: 76px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    background: #fff;
    box-shadow: inset 0 0 0 2px rgba(54, 90, 158, 0.22), 0 8px 24px rgba(31, 45, 80, 0.08);
}

label {
    display: grid;
    gap: 0.45rem;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 650;
}

.app-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 2rem;
    padding: 2.4rem clamp(1rem, 4vw, 3rem) 1rem;
}

.app-header h1,
.login-card h1 {
    margin: 0;
    letter-spacing: -0.04em;
    font-size: clamp(2.2rem, 5vw, 4rem);
    line-height: 0.95;
}

.eyebrow {
    margin: 0 0 0.55rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.72rem;
    font-weight: 800;
}

.muted {
    color: var(--muted);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.pill,
.ghost-link {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    padding: 0.7rem 1rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--muted);
    text-decoration: none;
    box-shadow: 0 12px 30px rgba(31, 45, 80, 0.08);
}

.app-shell {
    display: grid;
    gap: 1.2rem;
    padding: 1rem clamp(1rem, 4vw, 3rem) 3rem;
}

.panel {
    background: var(--panel);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
    padding: clamp(1rem, 2.5vw, 1.6rem);
}

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

.panel-heading h2 {
    margin: 0 0 0.25rem;
    letter-spacing: -0.03em;
}

.panel-heading p {
    margin: 0;
}

.search-form {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) 180px 140px auto;
    gap: 0.8rem;
    align-items: end;
}

.toolbar,
.filters {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    flex-wrap: wrap;
}

.toolbar {
    margin-top: 1rem;
}

.status-line {
    min-height: 1.4rem;
    margin: 1rem 0 0.5rem;
    color: var(--muted);
    font-size: 0.92rem;
}

.status-line.error,
.notice.error {
    color: var(--danger);
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
    gap: 1rem;
}

.photo-card {
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--panel-strong);
    box-shadow: var(--shadow-card);
}

.photo-preview-button {
    position: relative;
    display: block;
    width: 100%;
    border: 0;
    border-radius: 0;
    padding: 0;
    background: var(--soft);
    color: inherit;
    cursor: zoom-in;
    box-shadow: none;
}

.photo-preview-button:disabled {
    cursor: default;
}

.photo-preview-button img,
.photo-card > img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    background: var(--soft);
}

.photo-preview-button span {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 0.4rem 0.65rem;
    border-radius: 999px;
    background: rgba(22, 32, 51, 0.82);
    color: #fff;
    font-size: 0.74rem;
    font-weight: 850;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.16s ease, transform 0.16s ease;
    backdrop-filter: blur(12px);
}

.photo-preview-button:hover span,
.photo-preview-button:focus-visible span {
    opacity: 1;
    transform: translateY(0);
}

.photo-body {
    display: grid;
    gap: 0.75rem;
    padding: 1rem;
}

.credit,
.meta-row {
    margin: 0;
    font-size: 0.83rem;
    color: var(--muted);
    line-height: 1.45;
}

.credit a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
}

.meta-row {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.meta-chip {
    display: inline-flex;
    padding: 0.35rem 0.55rem;
    border-radius: 999px;
    background: var(--soft);
}

.compact-form {
    display: grid;
    gap: 0.55rem;
}

.compact-form button {
    width: 100%;
}

.url-panel {
    display: grid;
    gap: 0.6rem;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    background: rgba(41, 71, 122, 0.06);
}

.url-panel[hidden] {
    display: none;
}

.url-panel textarea {
    min-height: 96px;
    font-size: 0.8rem;
    line-height: 1.45;
    word-break: break-all;
}

.url-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.url-actions button {
    width: auto;
    min-height: 40px;
    padding: 0.65rem 0.9rem;
}

.open-url-link {
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 800;
    text-decoration: none;
}

body.photo-preview-open {
    overflow: hidden;
}

.photo-preview-modal[hidden] {
    display: none;
}

.photo-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: clamp(0.75rem, 2vw, 1.5rem);
}

.photo-preview-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    border: 0;
    border-radius: 0;
    background: rgba(10, 14, 24, 0.78);
    cursor: zoom-out;
    backdrop-filter: blur(12px);
}

.photo-preview-dialog {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 0.85rem;
    width: min(100%, 1180px);
    max-height: calc(100vh - 2rem);
    padding: clamp(0.85rem, 2vw, 1.25rem);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 28px 90px rgba(5, 10, 20, 0.36);
}

.photo-preview-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.photo-preview-header h2 {
    margin: 0.15rem 0 0;
    font-size: clamp(1.2rem, 2vw, 1.7rem);
}

.photo-preview-close {
    width: 42px;
    min-height: 42px;
    border-radius: 999px;
    padding: 0;
    font-size: 1.25rem;
    line-height: 1;
}

.photo-preview-figure {
    display: grid;
    gap: 0.7rem;
    margin: 0;
}

.photo-preview-figure img {
    display: block;
    width: 100%;
    max-height: min(72vh, 760px);
    object-fit: contain;
    border-radius: 18px;
    background: #101827;
}

.photo-preview-actions {
    display: flex;
    justify-content: flex-end;
}
.url-status {
    min-height: 1.2rem;
    margin: 0;
    font-size: 0.82rem;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 1rem;
}

.login-shell {
    width: min(100%, 440px);
}

.login-card {
    padding: clamp(1.4rem, 5vw, 2.2rem);
    background: var(--panel);
    border-radius: 32px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.login-card h1 {
    font-size: clamp(2.5rem, 10vw, 4.6rem);
}

.login-form {
    display: grid;
    gap: 1rem;
    margin-top: 1.6rem;
}

.notice {
    margin-top: 1rem;
    padding: 0.9rem 1rem;
    border-radius: var(--radius-md);
    background: rgba(184, 61, 75, 0.08);
}

@media (max-width: 860px) {
    .app-header,
    .panel-heading,
    .library-heading {
        display: grid;
    }

    .search-form {
        grid-template-columns: 1fr;
    }
}

.manual-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 0.85rem;
    align-items: end;
}

.manual-form .wide-field {
    grid-column: span 2;
}

.manual-form button {
    align-self: end;
}

@media (max-width: 1100px) {
    .manual-form {
        grid-template-columns: repeat(2, minmax(180px, 1fr));
    }
}

@media (max-width: 640px) {
    .manual-form {
        grid-template-columns: 1fr;
    }

    .manual-form .wide-field {
        grid-column: auto;
    }
}

.photo-card.is-in-library {
    position: relative;
}

.photo-card.is-in-library::before {
    content: "In library";
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 0.42rem 0.7rem;
    border-radius: 999px;
    background: rgba(22, 32, 51, 0.86);
    color: #fff;
    font-size: 0.74rem;
    font-weight: 850;
    letter-spacing: 0.02em;
    box-shadow: 0 14px 34px rgba(22, 32, 51, 0.22);
    backdrop-filter: blur(12px);
}

button.already-saved {
    background: rgba(22, 32, 51, 0.12);
    color: rgba(22, 32, 51, 0.72);
    box-shadow: none;
}


.library-toolbar {
    justify-content: flex-start;
    margin: 0.65rem 0 1rem;
}

.library-search-input {
    min-width: min(280px, 100%);
    width: 280px;
}

.library-toolbar-bottom {
    margin-top: 1.2rem;
}

.library-page-jump-label {
    width: auto;
    min-width: 145px;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
}

.library-page-jump-label input {
    width: 82px;
    padding: 0.72rem 0.9rem;
}


.selection-toolbar {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    flex-wrap: wrap;
    margin: 1rem 0;
    padding: 0.8rem;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.62);
}

.selection-toolbar strong {
    min-width: 92px;
}

.library-card {
    position: relative;
}

.library-card.is-selected {
    box-shadow: 0 0 0 3px rgba(54, 90, 158, 0.24), var(--shadow-card);
}

.select-photo {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 4;
    display: inline-flex;
    grid-template-columns: none;
    align-items: center;
    gap: 0.45rem;
    width: auto;
    min-height: 34px;
    padding: 0.42rem 0.65rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--text);
    box-shadow: 0 12px 26px rgba(22, 32, 51, 0.16);
    backdrop-filter: blur(10px);
}

.select-photo input {
    width: 18px;
    height: 18px;
    padding: 0;
    accent-color: var(--accent);
}

.select-photo span {
    font-size: 0.74rem;
    font-weight: 800;
}

.library-limit-label {
    width: auto;
    min-width: 150px;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
}

.library-limit-label select {
    width: 88px;
    padding: 0.72rem 0.9rem;
}

@media (max-width: 640px) {
    .library-toolbar {
        align-items: stretch;
    }

    .library-toolbar button,
    .library-limit-label,
    .library-page-jump-label,
    .library-search-input {
        width: 100%;
    }

    .library-limit-label,
    .library-page-jump-label {
        justify-content: space-between;
    }
}

.batch-panel {
    display: grid;
    gap: 1rem;
    margin-top: 1rem;
    padding: 1rem;
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.58);
    box-shadow: 0 12px 34px rgba(31, 45, 80, 0.07);
}

.batch-panel[hidden] {
    display: none;
}

.batch-copy {
    display: grid;
    gap: 0.3rem;
}

.batch-copy strong {
    color: var(--text);
    font-size: 1rem;
}

.batch-copy span {
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.45;
}

.batch-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 0.75rem;
    align-items: end;
}

.batch-controls button {
    min-height: 48px;
    white-space: nowrap;
    width: 100%;
}

.universal-fallback-actions {
    display: grid;
    grid-column: span 2;
    gap: 0.45rem;
    padding: 0.8rem;
    border-radius: var(--radius-md);
    background: rgba(54, 90, 158, 0.08);
}

.universal-fallback-actions strong {
    color: var(--text);
    font-size: 0.9rem;
}

.universal-fallback-actions span {
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.35;
}

.universal-fallback-actions div {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.universal-fallback-actions button {
    padding-inline: 0.75rem;
}

.batch-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 48px;
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius-sm);
    background: rgba(41, 71, 122, 0.08);
}

.batch-checkbox-label input {
    width: 18px;
    height: 18px;
    padding: 0;
    accent-color: var(--accent);
}

@media (max-width: 640px) {
    .batch-controls {
        grid-template-columns: 1fr;
    }

    .universal-fallback-actions {
        grid-column: auto;
    }
}
