@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/Vazirmatn-Regular.woff2") format("woff2");
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/Vazirmatn-SemiBold.woff2") format("woff2");
    font-weight: 600;
    font-display: swap;
}

@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/Vazirmatn-Bold.woff2") format("woff2");
    font-weight: 700;
    font-display: swap;
}

:root {
    color-scheme: light;
    --page: #f4f4f0;
    --surface: #ffffff;
    --surface-subtle: #f8f8f5;
    --ink: #191a18;
    --muted: #6d716a;
    --line: #dcdfd8;
    --brand: #a84f2b;
    --brand-dark: #81371c;
    --brand-soft: #f6e8e1;
    --green: #2f6b50;
    --green-soft: #e6f1eb;
    --danger: #b53c38;
    --danger-soft: #f9e9e7;
    --focus: #176b87;
    --shadow: 0 18px 50px rgba(27, 30, 25, 0.09);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body,
button,
input,
select,
textarea {
    font-family: "Vazirmatn", Tahoma, sans-serif;
    letter-spacing: 0;
}

body {
    min-height: 100vh;
    background: var(--page);
    color: var(--ink);
    line-height: 1.6;
}

button,
input,
select,
textarea {
    font-size: 0.92rem;
}

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

button,
a {
    touch-action: manipulation;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(23, 107, 135, 0.22);
    outline-offset: 2px;
}

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

.eyebrow {
    color: var(--brand);
    font-size: 0.72rem;
    font-weight: 700;
}

.primary-button,
.secondary-button,
.danger-button,
.text-button,
.icon-button {
    border: 0;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease, transform 120ms ease;
}

.primary-button,
.secondary-button,
.danger-button {
    min-height: 42px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    font-weight: 700;
    white-space: nowrap;
}

.primary-button {
    background: var(--brand);
    color: #fff;
}

.primary-button:hover {
    background: var(--brand-dark);
}

.secondary-button {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
}

.secondary-button:hover {
    border-color: #b9bdb5;
    background: var(--surface-subtle);
}

.danger-button {
    background: var(--danger-soft);
    color: var(--danger);
}

.danger-button:hover {
    background: #f3d7d4;
}

.text-button {
    background: transparent;
    color: var(--muted);
    padding: 7px 2px;
}

.danger-text {
    color: var(--danger);
}

.icon-button {
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font-size: 1.1rem;
}

.icon-button:hover {
    background: var(--surface-subtle);
    border-color: #b9bdb5;
}

.primary-button:active,
.secondary-button:active,
.danger-button:active,
.icon-button:active {
    transform: translateY(1px);
}

.primary-button:disabled,
.secondary-button:disabled,
.danger-button:disabled,
.icon-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(120deg, rgba(168, 79, 43, 0.06), transparent 38%),
        linear-gradient(300deg, rgba(47, 107, 80, 0.06), transparent 42%),
        var(--page);
}

.auth-shell {
    width: min(100%, 460px);
}

.auth-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: clamp(24px, 6vw, 42px);
}

.auth-brand {
    display: inline-flex;
    align-items: center;
    gap: 13px;
    color: var(--ink);
    text-decoration: none;
}

.auth-brand img {
    width: 54px;
    height: 54px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid var(--line);
}

.auth-brand div {
    display: flex;
    flex-direction: column;
}

.auth-brand strong {
    font-size: 1.15rem;
}

.auth-brand span {
    color: var(--muted);
    font-size: 0.72rem;
    direction: ltr;
}

.auth-heading {
    margin: 38px 0 24px;
}

.auth-heading h1 {
    margin: 4px 0 8px;
    font-size: clamp(1.6rem, 5vw, 2.1rem);
}

.auth-heading > p:last-child {
    color: var(--muted);
    font-size: 0.88rem;
}

.form-alert {
    border-right: 3px solid var(--danger);
    background: var(--danger-soft);
    color: #7f2825;
    padding: 11px 13px;
    margin-bottom: 18px;
    font-size: 0.84rem;
}

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

.auth-submit {
    width: 100%;
    margin-top: 8px;
}

.back-link {
    display: block;
    color: var(--muted);
    text-align: center;
    text-decoration: none;
    margin-top: 20px;
    font-size: 0.82rem;
}

.field {
    display: grid;
    gap: 7px;
}

.field > span {
    color: #4d514b;
    font-size: 0.78rem;
    font-weight: 600;
}

.field > span small {
    margin-inline-start: 4px;
    color: var(--muted);
    font-size: 0.66rem;
    font-weight: 400;
}

.field input,
.field select,
.field textarea,
.search-field input,
.select-field select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    padding: 10px 12px;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input,
.field select,
.search-field input,
.select-field select {
    min-height: 44px;
}

.field textarea {
    resize: vertical;
    min-height: 92px;
}

.field input:hover,
.field select:hover,
.field textarea:hover,
.search-field input:hover,
.select-field select:hover {
    border-color: #b8bdb4;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.search-field input:focus,
.select-field select:focus {
    border-color: var(--focus);
    box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.1);
    outline: 0;
}

.field input:disabled {
    background: #eeeeea;
    color: var(--muted);
}

.admin-header {
    height: 68px;
    padding: 0 clamp(16px, 3vw, 42px);
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(18px);
}

.admin-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.admin-brand img {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: 1px solid var(--line);
    object-fit: cover;
}

.admin-brand div {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.admin-brand strong {
    font-size: 0.98rem;
}

.admin-brand span {
    color: var(--muted);
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logout-button {
    color: var(--danger);
}

.admin-main {
    min-height: calc(100vh - 68px);
}

.admin-toolbar {
    min-height: 74px;
    padding: 14px clamp(16px, 3vw, 42px);
    border-bottom: 1px solid var(--line);
    background: var(--surface-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.stats-line {
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--muted);
    font-size: 0.78rem;
    white-space: nowrap;
}

.stats-line strong {
    color: var(--ink);
    font-size: 0.9rem;
}

.stats-line span + span {
    border-right: 1px solid var(--line);
    padding-right: 14px;
}

.toolbar-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(100%, 650px);
}

#newItemButton {
    flex: 0 0 auto;
}

.search-field {
    flex: 1;
}

.compact-select {
    width: 180px;
}

.admin-workspace {
    min-height: calc(100vh - 143px);
    display: grid;
    grid-template-columns: minmax(320px, 38%) minmax(0, 1fr);
}

.item-browser {
    border-left: 1px solid var(--line);
    background: var(--surface);
    min-height: inherit;
    max-height: calc(100vh - 143px);
    overflow-y: auto;
}

.admin-item-list {
    padding-bottom: 24px;
}

.list-message {
    color: var(--muted);
    text-align: center;
    padding: 64px 20px;
    font-size: 0.86rem;
}

.list-category {
    padding: 15px 18px 7px;
    color: var(--muted);
    background: var(--surface-subtle);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    font-size: 0.72rem;
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 2;
}

.list-category:first-child {
    border-top: 0;
}

.admin-item-row {
    min-height: 76px;
    border-bottom: 1px solid #eceee9;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    transition: background-color 150ms ease;
}

.admin-item-row:hover,
.admin-item-row.selected {
    background: #faf4f0;
}

.admin-item-row.selected {
    box-shadow: inset -3px 0 0 var(--brand);
}

.admin-item-row.inactive {
    opacity: 0.62;
}

.item-row-main {
    min-width: 0;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: right;
    cursor: pointer;
    padding: 10px 16px 10px 8px;
    display: flex;
    align-items: center;
    gap: 11px;
}

.item-row-image {
    width: 52px;
    height: 52px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: #f0eee9;
    object-fit: cover;
    flex: 0 0 auto;
}

.item-row-placeholder {
    display: grid;
    place-items: center;
    font-size: 1.35rem;
}

.item-row-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.item-row-name {
    font-size: 0.86rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-row-meta {
    display: flex;
    gap: 7px;
    align-items: center;
    color: var(--muted);
    font-size: 0.69rem;
}

.item-row-meta .soon-label {
    color: var(--brand);
}

.item-row-actions {
    padding-left: 12px;
}

.mini-edit {
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
    width: 34px;
    height: 34px;
}

.item-editor {
    min-width: 0;
    background: var(--page);
    padding: clamp(22px, 4vw, 52px);
    overflow-y: auto;
    max-height: calc(100vh - 143px);
}

.editor-empty {
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.editor-empty img {
    width: min(360px, 72%);
    height: auto;
    opacity: 0.42;
}

.editor-empty h2 {
    font-size: 1.12rem;
    margin-top: 12px;
}

.editor-empty p {
    color: var(--muted);
    font-size: 0.8rem;
    margin-top: 5px;
}

.item-form {
    width: min(100%, 860px);
    margin: 0 auto;
}

.editor-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 22px;
}

.editor-heading h1 {
    font-size: clamp(1.35rem, 3vw, 1.85rem);
    line-height: 1.4;
}

.order-actions {
    display: flex;
    gap: 6px;
}

.form-section {
    padding: 24px 0;
    border-top: 1px solid var(--line);
}

.form-section h2 {
    font-size: 0.92rem;
    margin-bottom: 16px;
}

.section-note {
    color: var(--muted);
    font-size: 0.72rem;
    margin-top: -12px;
}

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

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

.image-section {
    display: grid;
    grid-template-columns: minmax(140px, 1fr) minmax(280px, 2fr);
    gap: 32px;
    align-items: center;
}

.image-control {
    display: flex;
    align-items: center;
    gap: 16px;
}

.image-preview {
    width: 132px;
    aspect-ratio: 1;
    border: 1px dashed #b8bdb4;
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 0.72rem;
    flex: 0 0 auto;
}

.image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-buttons {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.file-button input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 1px;
    height: 1px;
}

.toggle-list {
    display: grid;
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
}

.toggle-row {
    min-height: 68px;
    padding: 12px 14px;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    cursor: pointer;
}

.toggle-row > span:first-child {
    display: flex;
    flex-direction: column;
}

.toggle-row strong {
    font-size: 0.84rem;
}

.toggle-row small {
    color: var(--muted);
    font-size: 0.7rem;
}

.toggle-row input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch {
    width: 42px;
    height: 24px;
    border-radius: 14px;
    background: #c8ccc4;
    position: relative;
    flex: 0 0 auto;
    transition: background-color 160ms ease;
}

.switch::after {
    content: "";
    position: absolute;
    top: 3px;
    right: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    transition: transform 160ms ease;
}

.toggle-row input:checked + .switch {
    background: var(--green);
}

.toggle-row input:checked + .switch::after {
    transform: translateX(-18px);
}

.toggle-row input:focus-visible + .switch {
    outline: 3px solid rgba(23, 107, 135, 0.22);
    outline-offset: 2px;
}

.modifier-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.modifier-check {
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    cursor: pointer;
}

.modifier-check input {
    width: 18px;
    height: 18px;
    accent-color: var(--brand);
}

.modifier-check span {
    display: flex;
    flex-direction: column;
    font-size: 0.78rem;
}

.modifier-check small {
    color: var(--muted);
    font-size: 0.66rem;
}

.form-actions {
    padding: 22px 0 max(24px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: sticky;
    bottom: 0;
    z-index: 5;
    background: rgba(244, 244, 240, 0.96);
    backdrop-filter: blur(16px);
}

.form-actions-main {
    display: flex;
    gap: 8px;
}

.admin-toast {
    position: fixed;
    left: 24px;
    bottom: 24px;
    max-width: min(380px, calc(100vw - 32px));
    padding: 11px 16px;
    border-radius: 6px;
    background: #232622;
    color: #fff;
    box-shadow: var(--shadow);
    font-size: 0.82rem;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
    z-index: 50;
}

.admin-toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.admin-toast.error {
    background: var(--danger);
}

@media (max-width: 980px) {
    .admin-toolbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
    }

    .toolbar-controls {
        width: 100%;
    }

    .admin-workspace {
        min-height: calc(100vh - 205px);
        grid-template-columns: minmax(280px, 42%) minmax(0, 1fr);
    }

    .item-browser,
    .item-editor {
        max-height: calc(100vh - 205px);
    }

    .image-section {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

@media (max-width: 720px) {
    .admin-header {
        height: 62px;
        padding: 0 12px;
    }

    .admin-brand span {
        display: none;
    }

    .header-actions .secondary-button {
        min-height: 40px;
        padding-inline: 11px;
        font-size: 0.76rem;
    }

    .admin-toolbar {
        padding: 12px;
    }

    .stats-line {
        width: 100%;
        overflow-x: auto;
    }

    .toolbar-controls {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
    }

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

    .compact-select {
        width: auto;
    }

    .admin-workspace {
        display: block;
        min-height: 0;
    }

    .item-browser,
    .item-editor {
        max-height: none;
        min-height: 0;
        border-left: 0;
    }

    .item-editor {
        display: none;
        padding: 20px 14px;
    }

    body.editor-open .item-browser {
        display: none;
    }

    body.editor-open .item-editor {
        display: block;
    }

    .editor-empty {
        display: none;
    }

    .form-grid,
    .modifier-options {
        grid-template-columns: 1fr;
    }

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

    .image-control {
        align-items: flex-start;
    }

    .image-preview {
        width: 112px;
    }

    .form-actions {
        bottom: 0;
        padding-top: 14px;
    }

    .admin-toast {
        left: 16px;
        right: 16px;
        bottom: 16px;
        max-width: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
