/* ==========================================================================
   کیو‌آر ساز — استایل اصلی
   معماری: متغیرهای CSS برای تم روشن/تاریک + چیدمان دو ستونه ریسپانسیو
   ========================================================================== */

/* ----- فونت محلی (آفلاین) ----- */
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn-Variable.woff2') format('woff2-variations');
    font-weight: 100 900;
    font-display: swap;
}

/* ----- متغیرهای تم ----- */
:root {
    --bg: #f1f3f9;
    --surface: #ffffff;
    --surface-2: #f7f8fc;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --accent: #e94560;
    --border: #e5e7eb;
    --shadow: 0 4px 24px rgba(30, 41, 99, .08);
    --radius: 16px;
    --radius-sm: 10px;
}

[data-theme="dark"] {
    --bg: #0f1120;
    --surface: #1a1d33;
    --surface-2: #22263f;
    --text: #eef0ff;
    --text-muted: #9aa0b8;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --border: #2e3352;
    --shadow: 0 4px 24px rgba(0, 0, 0, .35);
}

/* ----- پایه ----- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: 'Vazirmatn', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    transition: background .3s, color .3s;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: min(1200px, 100% - 2rem);
    margin-inline: auto;
}

.hidden { display: none !important; }

/* ----- هدر ----- */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: .9rem 0;
    position: sticky;
    top: 0;
    z-index: 20;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: .8rem; }

.brand-logo {
    font-size: 2rem;
    color: var(--primary);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-text h1 { font-size: 1.25rem; font-weight: 800; }
.brand-text p { font-size: .78rem; color: var(--text-muted); }

.icon-btn {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 42px; height: 42px;
    font-size: 1.15rem;
    cursor: pointer;
    transition: transform .2s;
}
.icon-btn:hover { transform: scale(1.1) rotate(15deg); }

.header-actions { display: flex; align-items: center; gap: .7rem; }

/* تب‌های حالت برنامه (ساخت/اسکن/دسته‌ای) */
.mode-tabs {
    display: flex;
    gap: .25rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .25rem;
}

.mode-tab {
    font-family: inherit;
    font-size: .82rem;
    font-weight: 600;
    padding: .4rem .8rem;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}

.mode-tab:hover { color: var(--text); }
.mode-tab.active { background: var(--primary); color: #fff; }

/* آیکن تم: پیش‌فرض (روشن) ماه را نشان بده */
.theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: inline; }

/* ----- چیدمان اصلی ----- */
.app-main {
    display: grid;
    grid-template-columns: 1.15fr .85fr;
    gap: 1.5rem;
    padding: 1.5rem 0 3rem;
    flex: 1;
    align-items: start;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.4rem;
}

/* ----- تب‌های نوع محتوا ----- */
.type-tabs {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: .5rem;
    margin-bottom: 1.2rem;
}

.type-tab {
    font-family: inherit;
    font-size: .85rem;
    padding: .55rem .3rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}

.type-tab:hover { border-color: var(--primary); }

.type-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 700;
}

/* ----- فرم‌ها ----- */
.type-form { display: none; }
.type-form.active { display: block; animation: fadeIn .25s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.field { display: block; margin-bottom: .9rem; flex: 1; }

.field > span {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    margin-bottom: .35rem;
    color: var(--text-muted);
}

.field input[type="text"],
.field input[type="url"],
.field input[type="tel"],
.field input[type="email"],
.field textarea,
.field select {
    width: 100%;
    font-family: inherit;
    font-size: .92rem;
    padding: .65rem .8rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    transition: border-color .2s, box-shadow .2s;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

.field textarea { resize: vertical; }

.field-row { display: flex; gap: .8rem; flex-wrap: wrap; align-items: flex-end; }

.checkbox-field {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .88rem;
    cursor: pointer;
    margin-bottom: .9rem;
    user-select: none;
}
.checkbox-field input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }

/* رنگ ----- */
.color-field input[type="color"] {
    width: 100%;
    height: 42px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    cursor: pointer;
    padding: 4px;
}

/* اسلایدر ----- */
.field input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
    cursor: pointer;
}

.field input[type="file"] {
    width: 100%;
    font-family: inherit;
    font-size: .85rem;
    padding: .5rem;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-muted);
    cursor: pointer;
}

output { color: var(--primary); font-weight: 700; }

/* ----- آکاردئون ----- */
.accordion {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 1rem;
    background: var(--surface-2);
    overflow: hidden;
}

.accordion summary {
    padding: .8rem 1rem;
    font-weight: 700;
    font-size: .95rem;
    cursor: pointer;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.accordion summary::-webkit-details-marker { display: none; }
.accordion summary::after { content: '▾'; transition: transform .2s; color: var(--text-muted); }
.accordion[open] summary::after { transform: rotate(180deg); }

.accordion-body { padding: .4rem 1rem 1rem; }

/* ----- پیش‌نمایش ----- */
.preview-sticky { position: sticky; top: 90px; }

.qr-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    background:
        repeating-conic-gradient(var(--surface-2) 0% 25%, transparent 0% 50%)
        50% / 24px 24px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    overflow: hidden;
}

.qr-preview canvas, .qr-preview svg {
    max-width: 100%;
    height: auto !important;
    border-radius: 8px;
}

.preview-placeholder {
    text-align: center;
    color: var(--text-muted);
    font-size: .95rem;
}

/* ----- دکمه‌ها ----- */
.download-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .5rem;
    margin-top: 1rem;
}

.btn {
    font-family: inherit;
    font-size: .88rem;
    font-weight: 700;
    padding: .65rem .5rem;
    border-radius: var(--radius-sm);
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}

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

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--primary-hover); transform: translateY(-2px); }

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:not(:disabled):hover { border-color: var(--primary); color: var(--primary); }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:not(:disabled):hover { color: var(--accent); border-color: var(--accent); }

.btn-sm { font-size: .78rem; padding: .35rem .7rem; }

/* ----- قالب‌های آماده ----- */
.section-title { font-size: .95rem; font-weight: 800; margin-bottom: .6rem; }

.presets { margin-top: 1.4rem; }

.preset-list { display: flex; gap: .5rem; flex-wrap: wrap; }

.preset-chip {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-family: inherit;
    font-size: .8rem;
    font-weight: 600;
    padding: .4rem .75rem;
    border-radius: 999px;
    border: 1.5px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: all .2s;
}
.preset-chip:hover { border-color: var(--primary); transform: translateY(-2px); }

.preset-swatch {
    width: 14px; height: 14px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,.15);
}

/* ----- تاریخچه ----- */
.history { margin-top: 1.4rem; }

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .4rem;
}

.history-list { list-style: none; max-height: 220px; overflow-y: auto; }

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .6rem;
    padding: .5rem .6rem;
    border-radius: var(--radius-sm);
    font-size: .82rem;
    cursor: pointer;
    transition: background .15s;
}
.history-item:hover { background: var(--surface-2); }

.history-item .h-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    direction: ltr;
    text-align: right;
}

.history-item .h-type { color: var(--text-muted); font-size: .75rem; flex-shrink: 0; }

.history-empty { color: var(--text-muted); font-size: .82rem; padding: .4rem .2rem; }

/* ----- حالت‌های اسکن و دسته‌ای ----- */
.app-single {
    padding: 1.5rem 0 3rem;
    flex: 1;
    max-width: 720px;
}

.panel-title { font-size: 1.15rem; font-weight: 800; margin-bottom: .3rem; }
.panel-desc { font-size: .86rem; color: var(--text-muted); margin-bottom: 1.1rem; }
.panel-desc code {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .05rem .4rem;
    font-size: .8rem;
}

.scan-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }

.file-btn { display: inline-flex; align-items: center; justify-content: center; }

.scan-video-wrap {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1.5px solid var(--border);
    margin-bottom: 1rem;
    background: #000;
}

.scan-video-wrap video { width: 100%; display: block; max-height: 420px; object-fit: cover; }

/* قاب راهنمای اسکن وسط تصویر */
.scan-frame {
    position: absolute;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: min(60%, 260px);
    aspect-ratio: 1;
    border: 3px solid var(--primary);
    border-radius: 18px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35);
    animation: pulse 1.6s ease-in-out infinite;
    pointer-events: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .55; }
}

.scan-result {
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    animation: fadeIn .25s ease;
}

.scan-result output {
    display: block;
    font-size: .88rem;
    word-break: break-all;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .6rem .8rem;
    margin-bottom: .7rem;
    color: var(--text);
    font-weight: 500;
    max-height: 160px;
    overflow-y: auto;
}

.scan-result-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.scan-result-actions .btn { text-decoration: none; }

.batch-progress {
    display: flex;
    align-items: center;
    gap: .8rem;
    margin-top: 1rem;
    font-size: .85rem;
    color: var(--text-muted);
}

.batch-progress progress {
    flex: 1;
    height: 10px;
    accent-color: var(--primary);
}

#batch-input { font-size: .85rem; }

/* ----- فوتر ----- */
.app-footer {
    border-top: 1px solid var(--border);
    padding: 1rem 0;
    text-align: center;
    font-size: .8rem;
    color: var(--text-muted);
    background: var(--surface);
}

/* ----- توست ----- */
.toast {
    position: fixed;
    bottom: 1.4rem;
    right: 50%;
    transform: translateX(50%) translateY(120%);
    background: var(--text);
    color: var(--bg);
    padding: .7rem 1.4rem;
    border-radius: 999px;
    font-size: .88rem;
    font-weight: 600;
    box-shadow: var(--shadow);
    transition: transform .3s ease;
    z-index: 50;
    pointer-events: none;
}
.toast.show { transform: translateX(50%) translateY(0); }

/* ----- ریسپانسیو ----- */
@media (max-width: 900px) {
    .app-main { grid-template-columns: 1fr; }
    .preview-sticky { position: static; }
    .type-tabs { grid-template-columns: repeat(4, 1fr); }
    .download-actions { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 640px) {
    .header-inner { flex-wrap: wrap; gap: .6rem; }
    .mode-tabs { order: 3; width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
    .type-tabs { grid-template-columns: repeat(2, 1fr); }
    .download-actions { grid-template-columns: repeat(2, 1fr); }
    .panel { padding: 1rem; }
    .field-row { flex-direction: column; align-items: stretch; }
}
