:root {
    --bg: #0d0d0d;
    --panel: #171717;
    --header: #202020;
    --line: #0d0d0d;
    --text: #f2f2f2;
    --muted: #7a7a7a;
    --cyan: #079cbd;
    --cyan-dark: #057d99;
    --danger: #d95e5e;
}

@font-face {
    font-family: 'W Tlesk';
    src: url('fonts/w-tlesk-regular.ttf') format('truetype');
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: 'W Tlesk';
    src: url('fonts/w-tlesk-thin.ttf') format('truetype');
    font-style: normal;
    font-weight: 300;
    font-display: swap;
}

@font-face {
    font-family: 'W Tlesk';
    src: url('fonts/w-tlesk-bold.ttf') format('truetype');
    font-style: normal;
    font-weight: 700;
    font-display: swap;
}

@font-face {
    font-family: 'W Tlesk';
    src: url('fonts/w-tlesk-black.ttf') format('truetype');
    font-style: normal;
    font-weight: 900;
    font-display: swap;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'W Tlesk', Tahoma, Arial, sans-serif;
    font-size: 16px;
}

button,
input,
select {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 3px;
}

.app-shell {
    min-height: 100vh;
    padding: 70px 4.4vw 36px;
}

.app-header {
    position: relative;
    min-height: 82px;
}

.top-nav {
    display: flex;
    justify-content: center;
    gap: clamp(34px, 5vw, 76px);
    direction: rtl;
    padding: 10px 0 35px;
}

.top-nav a {
    color: #292929;
    font-size: 24px;
    line-height: 1;
    transition: color 140ms ease;
}

.top-nav a:hover,
.top-nav a.active {
    color: var(--text);
}

.account-bar {
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
}

.account-bar form {
    margin: 0;
}

.add-book,
.logout-button {
    border: 1px solid var(--cyan-dark);
    border-radius: 4px;
    background: transparent;
    color: var(--cyan);
    cursor: pointer;
    padding: 7px 11px;
}

.add-book:hover,
.logout-button:hover {
    background: rgba(7, 156, 189, .12);
}

.flash-stack {
    position: fixed;
    z-index: 20;
    top: 18px;
    right: 18px;
    display: grid;
    gap: 8px;
    width: min(360px, calc(100vw - 36px));
}

.flash {
    border: 1px solid #3e3e3e;
    border-radius: 4px;
    background: #1d1d1d;
    padding: 12px 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
}

.flash-success {
    border-color: var(--cyan-dark);
}

.flash-error,
.form-error {
    border-color: #914545;
    color: #f1a1a1;
}

.table-stage {
    width: 100%;
    overflow-x: auto;
    scrollbar-color: #3b3b3b var(--bg);
}

.table-frame {
    width: max-content;
    min-width: 0;
    margin: 0 auto;
}

.table-header-frame,
.row-frame {
    display: grid;
    grid-template-columns: 42px max-content 42px;
    direction: ltr;
    align-items: stretch;
}

.table-header-frame {
    min-height: 58px;
    margin-bottom: 18px;
}

.table-header,
.data-row {
    display: grid;
    direction: rtl;
}

.catalog-grid {
    grid-template-columns: 180px 282px 110px 208px 108px 92px 96px 96px 122px 80px;
}

.status-grid {
    grid-template-columns: 180px 282px 110px 110px 110px 200px 160px;
}

.table-header {
    overflow: hidden;
    background: var(--header);
}

.cell {
    min-width: 0;
    border-left: 4px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 58px;
    padding: 12px 10px;
    text-align: center;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.header-cell {
    color: #f0f0f0;
    white-space: nowrap;
}

.row-frame {
    position: relative;
    min-height: 236px;
    margin-bottom: 14px;
}

.data-row {
    min-height: 236px;
    overflow: hidden;
    background: var(--panel);
}

.data-row .cell {
    min-height: 236px;
}

.cover-cell {
    padding: 14px 18px;
}

.cover-cell img {
    display: block;
    width: 140px;
    height: 209px;
    object-fit: cover;
}

.cover-placeholder {
    color: #555;
    font-size: 13px;
}

.title-cell {
    font-size: 17px;
}

.latin-cell {
    direction: ltr;
}

.status-cell {
    flex-direction: column;
    gap: 13px;
}

.row-edit,
.menu-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #f2f2f2;
}

.row-edit {
    font-size: 28px;
    opacity: .92;
}

.row-edit:hover {
    color: var(--cyan);
}

.row-frame.is-locked .data-row,
.row-frame.is-locked .row-edit,
.row-frame.is-locked .menu-cell {
    opacity: .42;
    filter: grayscale(1);
}

.row-frame.is-locked::after {
    position: absolute;
    top: 12px;
    right: 54px;
    content: 'در حال ویرایش';
    color: #bbb;
    font-size: 12px;
    pointer-events: none;
}

.menu-cell {
    position: relative;
}

.menu-button {
    display: grid;
    gap: 5px;
    width: 28px;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 6px 0;
}

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

.menu-button span {
    display: block;
    height: 2px;
    border-radius: 2px;
    background: var(--text);
}

.drag-handle {
    cursor: grab;
}

.drag-handle:active {
    cursor: grabbing;
}

.dragging {
    opacity: .45;
}

.drag-over .data-row {
    outline: 2px solid var(--cyan);
    outline-offset: -2px;
}

.action-spacer {
    display: block;
}

.empty-state {
    width: 100%;
    border: 1px solid #232323;
    background: var(--panel);
    color: var(--muted);
    padding: 42px;
    text-align: center;
}

.form-stage {
    width: min(920px, 100%);
    margin: 28px auto 0;
}

.form-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
}

.form-heading h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 400;
}

.back-link {
    color: var(--cyan);
}

.form-error {
    border: 1px solid;
    border-radius: 4px;
    background: rgba(145, 69, 69, .12);
    margin-bottom: 16px;
    padding: 12px 14px;
}

.book-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    border: 1px solid #242424;
    background: var(--panel);
    padding: 24px;
}

.field {
    display: grid;
    gap: 8px;
    color: #d4d4d4;
    font-size: 14px;
}

.field-wide {
    grid-column: 1 / -1;
}

.field input,
.field select,
.login-form input {
    width: 100%;
    border: 1px solid #3a3a3a;
    border-radius: 3px;
    background: #101010;
    color: var(--text);
    padding: 11px 12px;
}

.field input[type="file"] {
    padding: 8px;
}

.cover-sources {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.cover-source {
    display: grid;
    gap: 8px;
    color: #ccc;
}

.cover-library {
    min-width: 0;
    border: 1px solid #3a3a3a;
    padding: 12px;
}

.cover-library legend {
    color: #ccc;
    padding: 0 6px;
}

.cover-library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 10px;
}

.cover-library-option {
    position: relative;
    cursor: pointer;
}

.cover-library-option input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.cover-library-card {
    display: grid;
    gap: 6px;
    height: 170px;
    border: 1px solid #3a3a3a;
    padding: 6px;
    text-align: center;
}

.cover-library-card img {
    width: 100%;
    height: 130px;
    object-fit: cover;
}

.cover-library-card > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cover-library-option input:checked + .cover-library-card,
.cover-library-option:focus-within .cover-library-card {
    border-color: var(--cyan);
    box-shadow: 0 0 0 1px var(--cyan);
}

.cover-library-empty {
    margin: 0;
    color: var(--muted);
}

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

.field input:disabled,
.field select:disabled {
    opacity: .65;
    color: #aaa;
}

.lock-notice {
    border: 1px solid #6b5b35;
    background: rgba(107, 91, 53, .14);
    color: #e4c98e;
    margin-bottom: 16px;
    padding: 12px 14px;
}

.danger-button {
    border: 1px solid #914545;
    border-radius: 5px;
    background: transparent;
    color: #ec9b9b;
    cursor: pointer;
    padding: 10px 17px;
}

.danger-button:hover {
    background: rgba(145, 69, 69, .16);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 8px;
}

.primary-button,
.secondary-button,
.checklist-button,
.checklist-save {
    display: inline-block;
    border: 1px solid var(--cyan);
    border-radius: 5px;
    background: var(--cyan);
    color: #fff;
    cursor: pointer;
    padding: 10px 17px;
    text-align: center;
}

.primary-button:hover,
.checklist-button:hover,
.checklist-save:hover {
    background: var(--cyan-dark);
}

.secondary-button {
    border-color: #555;
    background: transparent;
    color: #ccc;
}

.secondary-button:hover {
    background: #292929;
}

.checklist-cell {
    padding: 12px 18px;
}

.checklist-button {
    white-space: nowrap;
}

.checklist-dialog {
    width: min(744px, calc(100vw - 32px));
    min-height: 750px;
    border: 4px solid var(--cyan);
    border-radius: 8px;
    background: #080808;
    color: var(--text);
    padding: 0;
}

.checklist-dialog::backdrop {
    background: rgba(0, 0, 0, .78);
}

.checklist-form {
    position: relative;
    min-height: 742px;
    padding: 100px 30px 28px;
}

.dialog-close {
    position: absolute;
    top: 14px;
    left: 18px;
    border: 0;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 28px;
    line-height: 1;
}

.checklist-form h2 {
    margin: 0 0 22px;
    font-size: 20px;
    font-weight: 400;
    text-align: right;
}

.dialog-book-title {
    margin: -10px 0 18px;
    color: var(--muted);
    text-align: right;
}

.check-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    margin: 12px 0;
    font-size: 17px;
}

.check-row input {
    width: 22px;
    height: 22px;
    accent-color: var(--cyan);
}

.check-row > span:not(.check-controls) {
    flex: 1;
}

.check-row .completed {
    color: var(--muted);
    text-decoration: line-through;
}

.check-drag-handle {
    display: grid;
    flex: 0 0 24px;
    gap: 4px;
    width: 24px;
    border: 0;
    background: transparent;
    cursor: grab;
    padding: 4px 0;
}

.check-drag-handle:active {
    cursor: grabbing;
}

.check-drag-handle span {
    display: block;
    height: 2px;
    border-radius: 2px;
    background: var(--text);
}

.check-controls {
    display: flex;
    gap: 4px;
}

.check-controls button {
    border: 1px solid #444;
    border-radius: 3px;
    background: transparent;
    color: #ccc;
    cursor: pointer;
    padding: 3px 7px;
}

.check-controls button:hover:not(:disabled) {
    border-color: var(--cyan);
    color: var(--cyan);
}

.checklist-add {
    display: flex;
    gap: 8px;
    margin-top: 22px;
}

.checklist-add input {
    min-width: 0;
    flex: 1;
    border: 1px solid #3a3a3a;
    border-radius: 3px;
    background: #101010;
    color: var(--text);
    padding: 10px 12px;
}

.checklist-add .checklist-save {
    width: auto;
    margin: 0;
}

.checklist-error {
    color: #f1a1a1;
}

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

.checklist-save {
    width: 100%;
    margin-top: 20px;
}

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

.login-card {
    width: min(420px, 100%);
    border: 1px solid #292929;
    background: var(--panel);
    padding: 34px;
}

.login-mark {
    margin-bottom: 24px;
    color: var(--cyan);
    font-size: 14px;
}

.login-card h1 {
    margin: 0 0 10px;
    font-size: 23px;
    font-weight: 400;
}

.login-card p {
    margin: 0 0 26px;
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 16px;
}

.login-form label {
    display: grid;
    gap: 8px;
    color: #d4d4d4;
    font-size: 14px;
}

.login-form .primary-button {
    margin-top: 6px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

@media (max-width: 760px) {
    .app-shell {
        padding: 30px 16px 24px;
    }

    .top-nav {
        gap: 22px;
        padding-top: 8px;
    }

    .top-nav a {
        font-size: 18px;
    }

    .account-bar {
        position: static;
        justify-content: center;
        margin-bottom: 18px;
    }

    .app-header {
        min-height: 118px;
    }

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

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

    .form-heading h1 {
        font-size: 20px;
    }
}
