/* ============================================================
   WISEWORDS Dashboard — Main Stylesheet
   ============================================================ */

:root {
    --bg: #0d1117;
    --bg2: #161b22;
    --bg3: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --primary: #7c5cfc;
    --primary-dim: #3d2f7a;
    --primary-glow: rgba(124, 92, 252, .25);
    --accent: #a78bfa;
    --success: #3fb950;
    --warning: #d29922;
    --danger: #f85149;
    --info: #388bfd;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, .5);
    --transition: .22s cubic-bezier(.4, 0, .2, 1);
}


/* Light mode */

@media (prefers-color-scheme: light) {
     :root {
        --bg: #f0f2f5;
        --bg2: #ffffff;
        --bg3: #e8eaf0;
        --border: #d0d7de;
        --text: #1f2328;
        --text-muted: #636e7b;
        --shadow: 0 4px 24px rgba(0, 0, 0, .12);
    }
}


/* Manual overrides via [data-theme] */

[data-theme="dark"] {
    --bg: #0d1117;
    --bg2: #161b22;
    --bg3: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --shadow: 0 4px 24px rgba(0, 0, 0, .5);
}

[data-theme="light"] {
    --bg: #f0f2f5;
    --bg2: #ffffff;
    --bg3: #e8eaf0;
    --border: #d0d7de;
    --text: #1f2328;
    --text-muted: #636e7b;
    --shadow: 0 4px 24px rgba(0, 0, 0, .12);
}


/* ── Reset ──────────────────────────────────────────────────── */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    display: block;
}

button {
    cursor: pointer;
    font-family: inherit;
}

input,
select,
textarea {
    font-family: inherit;
}


/* ── Layout ─────────────────────────────────────────────────── */

.app-wrapper {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
}


/* ── Topbar ──────────────────────────────────────────────────── */

.topbar {
    grid-column: 1 / -1;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

.topbar-brand .brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.topbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.theme-toggle {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: var(--transition);
}

.theme-toggle:hover {
    color: var(--text);
    border-color: var(--accent);
}


/* ── Sidebar ─────────────────────────────────────────────────── */

.sidebar {
    background: var(--bg2);
    border-right: 1px solid var(--border);
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-label {
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    padding: 10px 12px 4px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: .9rem;
    font-weight: 500;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: var(--transition);
}

.sidebar-item:hover {
    background: var(--bg3);
    color: var(--text);
}

.sidebar-item.active {
    background: var(--primary-dim);
    color: var(--accent);
}

.sidebar-item .icon {
    font-size: 18px;
    width: 22px;
    text-align: center;
}

.sidebar-legal {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.sidebar-item[href]:hover {
    text-decoration: none;
}


/* ── Main content ────────────────────────────────────────────── */

.main-content {
    padding: 28px 32px;
    overflow-y: auto;
}


/* ── Section panels ──────────────────────────────────────────── */

.panel {
    display: none;
}

.panel.active {
    display: block;
}


/* ── Page heading ────────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -.02em;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: .9rem;
    margin-top: 2px;
}


/* ── Buttons ─────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    border: none;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    box-shadow: 0 2px 12px var(--primary-glow);
}

.btn-primary:hover {
    opacity: .9;
    transform: translateY(-1px);
    box-shadow: 0 4px 18px var(--primary-glow);
}

.btn-secondary {
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-lg {
    padding: 12px 26px;
    font-size: 1rem;
}

.btn:disabled {
    opacity: .5;
    pointer-events: none;
}

.btn .spinner {
    width: 15px;
    height: 15px;
    border: 2px solid rgba(255, 255, 255, .4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    display: none;
}

.btn.loading .spinner {
    display: block;
}

.btn.loading .btn-label {
    opacity: .6;
}


/* ── Stats grid ──────────────────────────────────────────────── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-card .stat-icon {
    font-size: 26px;
    margin-bottom: 4px;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}

.stat-card .stat-label {
    font-size: .8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.stat-card.primary {
    border-color: var(--primary);
}

.stat-card.success {
    border-color: var(--success);
}

.stat-card.info {
    border-color: var(--info);
}

.stat-card.warning {
    border-color: var(--warning);
}


/* ── Generate hero card ──────────────────────────────────────── */

.generate-card {
    background: linear-gradient(135deg, var(--primary-dim) 0%, var(--bg2) 100%);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    margin-bottom: 28px;
}

.generate-card h2 {
    font-size: 1.4rem;
    margin-bottom: 6px;
}

.generate-card p {
    color: var(--text-muted);
    margin-bottom: 20px;
}

.preview-custom-inputs {
    display: grid;
    gap: 10px;
    max-width: 760px;
    margin: 0 auto 16px;
    text-align: left;
}

.preview-custom-inputs .form-control {
    background: rgba(0, 0, 0, 0.14);
}


/* ── Post preview card ───────────────────────────────────────── */

.preview-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 28px;
}

@media (max-width: 900px) {
    .preview-section {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: .9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 20px;
}

.post-image-preview {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--bg3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: .9rem;
}

.post-image-preview img {
    width: 100%;
    border-radius: var(--radius-sm);
}

.post-image-preview.empty {
    min-height: 200px;
}

.quote-block {
    background: var(--bg3);
    border-left: 3px solid var(--primary);
    padding: 16px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-style: italic;
    margin-bottom: 14px;
    line-height: 1.7;
}

.caption-text {
    font-size: .875rem;
    color: var(--text-muted);
    line-height: 1.7;
}

.hashtag-text {
    font-size: .8rem;
    color: var(--info);
    margin-top: 10px;
    line-height: 1.6;
}


/* ── History grid ────────────────────────────────────────────── */

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.history-item {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
    cursor: pointer;
}

.history-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.history-item .thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--bg3);
}

.history-item .thumb.no-image {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 2rem;
}

.history-item .item-meta {
    padding: 10px 12px;
}

.history-item .item-date {
    font-size: .75rem;
    color: var(--text-muted);
}

.history-item .item-quote {
    font-size: .8rem;
    margin-top: 4px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.history-item .item-badges {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.badge {
    font-size: .65rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.badge-success {
    background: rgba(63, 185, 80, .18);
    color: var(--success);
}

.badge-danger {
    background: rgba(248, 81, 73, .18);
    color: var(--danger);
}

.badge-info {
    background: rgba(56, 139, 253, .18);
    color: var(--info);
}

.badge-warning {
    background: rgba(210, 153, 34, .18);
    color: var(--warning);
}

.badge-muted {
    background: var(--bg3);
    color: var(--text-muted);
}


/* ── Settings form ───────────────────────────────────────────── */

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 800px) {
    .settings-grid {
        grid-template-columns: 1fr;
    }
}

.settings-section {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.settings-section .section-title {
    padding: 14px 20px;
    font-weight: 600;
    font-size: .9rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-section .section-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.form-control {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    width: 100%;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-control::placeholder {
    color: var(--text-muted);
    opacity: .6;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.toggle-label {
    font-size: .875rem;
}


/* Toggle switch */

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-track {
    position: absolute;
    inset: 0;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 999px;
    transition: var(--transition);
    cursor: pointer;
}

.toggle-track::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: var(--transition);
}

.toggle input:checked+.toggle-track {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle input:checked+.toggle-track::after {
    left: calc(100% - 21px);
    background: #fff;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .875rem;
    cursor: pointer;
}

.checkbox-item input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--primary);
    cursor: pointer;
}

.save-bar {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 8px;
}


/* ── Alert / toast ───────────────────────────────────────────── */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    font-size: .875rem;
    box-shadow: var(--shadow);
    pointer-events: all;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideUp .3s ease;
    max-width: 380px;
}

.toast.toast-success {
    border-color: var(--success);
}

.toast.toast-error {
    border-color: var(--danger);
}

.toast.toast-info {
    border-color: var(--info);
}


/* ── Modal ───────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .65);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: min(95vw, 700px);
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(.96);
    transition: var(--transition);
    box-shadow: var(--shadow);
}

.modal-overlay.open .modal {
    transform: scale(1);
}

.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 24px;
}


/* ── Setup wizard / notice ───────────────────────────────────── */

.setup-notice {
    background: linear-gradient(135deg, rgba(124, 92, 252, .1), rgba(124, 92, 252, .03));
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 24px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.setup-notice .notice-icon {
    font-size: 24px;
    flex-shrink: 0;
    margin-top: 2px;
}

.setup-notice h3 {
    font-size: .95rem;
    margin-bottom: 4px;
}

.setup-notice p {
    font-size: .85rem;
    color: var(--text-muted);
}


/* ── Platform status badges ──────────────────────────────────── */

.platform-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.platform-row:last-child {
    border-bottom: none;
}

.platform-icon {
    font-size: 20px;
    width: 28px;
    text-align: center;
}

.platform-name {
    flex: 1;
    font-weight: 500;
    font-size: .9rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.ok {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.status-dot.missing {
    background: var(--warning);
}

.status-dot.error {
    background: var(--danger);
}


/* ── Scroll / misc ───────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: .9rem;
}

.section-divider {
    height: 1px;
    background: var(--border);
    margin: 28px 0;
}

.mt-4 {
    margin-top: 16px;
}

.mb-4 {
    margin-bottom: 16px;
}

.text-muted {
    color: var(--text-muted);
}

.text-sm {
    font-size: .85rem;
}


/* ── Animations ──────────────────────────────────────────────── */

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes slideUp {
    from {
        transform: translateY(16px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: .5;
    }
}

.pulse {
    animation: pulse 1.8s ease-in-out infinite;
}


/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 700px) {
    .app-wrapper {
        grid-template-columns: 1fr;
    }
    .sidebar {
        display: none;
    }
    .main-content {
        padding: 16px;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}