:root {
    --bg: #f5f4f1;
    --surface: #ffffff;
    --header: #18181b;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --facebook: #1877f2;
    --facebook-dark: #1565d8;
    --text: #111827;
    --text-muted: #6b7280;
    --text-faint: #9ca3af;
    --border: #e5e7eb;
    --border-focus: #4f46e5;
    --error: #dc2626;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
}

.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────────────────────────────── */

#login-view {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--header);
}

.login-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 48px 40px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.login-brand {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 4px;
    color: var(--text);
}

.login-sub {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 32px;
}

#login-form { display: flex; flex-direction: column; gap: 10px; }

.error { color: var(--error); font-size: 0.875rem; margin-top: 8px; }

/* ── App Header ─────────────────────────────────────────────────────────── */

.app-header {
    background: var(--header);
    display: flex;
    align-items: center;
    padding: 0 20px;
    height: 56px;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 1px 0 rgba(255,255,255,0.06);
}

.header-brand {
    font-size: 0.9375rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.01em;
    white-space: nowrap;
    padding-right: 16px;
    border-right: 1px solid rgba(255,255,255,0.1);
    margin-right: 4px;
    flex-shrink: 0;
}

/* ── Tabs ───────────────────────────────────────────────────────────────── */

.tabs { display: flex; flex: 1; gap: 2px; }

.tab {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.48);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    font-family: inherit;
}

.tab:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.8); }
.tab.active { background: rgba(255,255,255,0.12); color: white; }
.tab svg { flex-shrink: 0; }

.btn-ghost-header {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.16);
    color: rgba(255,255,255,0.55);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.8125rem;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
    margin-left: auto;
    flex-shrink: 0;
}
.btn-ghost-header:hover { background: rgba(255,255,255,0.08); color: white; }

/* ── Tab Panels ─────────────────────────────────────────────────────────── */

#app-view { min-height: calc(100vh - 56px); }

.tab-panel { padding: 32px 20px 60px; }

.panel-inner { max-width: 720px; margin: 0 auto; }

.panel-header { margin-bottom: 28px; }
.panel-header h2 {
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}
.panel-header p { color: var(--text-muted); }

/* ── Form Elements ──────────────────────────────────────────────────────── */

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; }

.form-group label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.01em;
}

input[type="text"],
input[type="date"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

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

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 34px;
    cursor: pointer;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 14px;
}

@media (max-width: 540px) {
    .form-row-3 { grid-template-columns: 1fr 1fr; }
    .form-row-3 .form-group:first-child { grid-column: 1 / -1; }
}

/* ── Pill Radio Group ───────────────────────────────────────────────────── */

.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }

.pill {
    display: inline-flex;
    align-items: center;
    padding: 7px 16px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    user-select: none;
}

.pill:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

.pill input[type="radio"] { display: none; }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn-primary {
    display: block;
    width: 100%;
    padding: 11px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-lg { padding: 14px 32px; font-size: 1rem; border-radius: var(--radius); }

.btn-sm-outline {
    padding: 6px 14px;
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.btn-sm-outline:hover { background: var(--primary-light); }

.btn-sm-ghost {
    padding: 6px 12px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.15s;
}
.btn-sm-ghost:hover { color: var(--text); }

.btn-facebook {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--facebook);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.btn-facebook:hover { background: var(--facebook-dark); }
.btn-facebook:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-download {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 14px;
    background: transparent;
    color: var(--text-muted);
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
    white-space: nowrap;
    text-decoration: none;
    flex-shrink: 0;
}
.btn-download:hover { border-color: var(--text-muted); color: var(--text); }

/* ── Loading ────────────────────────────────────────────────────────────── */

.loading-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 0;
}

.loading-label { font-size: 0.9rem; color: var(--text-muted); }

.dots { display: flex; gap: 5px; align-items: center; flex-shrink: 0; }
.dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary);
    animation: dotPulse 1.4s ease-in-out infinite;
}
.dots span:nth-child(2) { animation-delay: 0.16s; }
.dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes dotPulse {
    0%, 80%, 100% { transform: scale(0.55); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* ── Toolbars & Labels ──────────────────────────────────────────────────── */

.output-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.output-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
}

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

.edit-hint {
    font-size: 0.8rem;
    color: var(--text-faint);
    margin-top: 6px;
    text-align: right;
}

/* ── Rich Output (contenteditable) ──────────────────────────────────────── */

.rich-output {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 28px;
    min-height: 160px;
    font-size: 0.9375rem;
    line-height: 1.8;
    color: var(--text);
    outline: none;
    word-break: break-word;
    box-shadow: var(--shadow);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.rich-output:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.08), var(--shadow);
}

.rich-output p { margin-bottom: 0.8em; }
.rich-output p:last-child { margin-bottom: 0; }
.rich-output strong { font-weight: 650; }
.rich-output em { font-style: italic; }
.rich-output h1, .rich-output h2, .rich-output h3 {
    font-weight: 700;
    margin: 1.2em 0 0.5em;
    letter-spacing: -0.01em;
}
.rich-output h2 { font-size: 1.05rem; }
.rich-output h3 { font-size: 0.975rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.rich-output ul, .rich-output ol { padding-left: 1.5em; margin-bottom: 0.8em; }
.rich-output li { margin-bottom: 0.3em; }
.rich-output hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
.rich-output code { font-family: monospace; background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 0.875em; }

/* ── Output Log (monospace stream) ─────────────────────────────────────── */

.output-log {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    font-size: 0.8125rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    line-height: 1.65;
    color: var(--text-muted);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 340px;
    overflow-y: auto;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

/* ── Log details (collapsible) ──────────────────────────────────────────── */

.log-details { margin-bottom: 24px; }

.log-details summary {
    font-size: 0.875rem;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    padding: 6px 0;
    display: flex;
    align-items: center;
    gap: 6px;
    list-style: none;
}
.log-details summary::-webkit-details-marker { display: none; }
.log-details summary::before { content: '▶'; font-size: 0.65rem; transition: transform 0.15s; opacity: 0.5; }
.log-details[open] summary::before { transform: rotate(90deg); }
.log-details .output-log { margin-top: 8px; }

/* ── Files Grid ─────────────────────────────────────────────────────────── */

.files-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.file-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.file-preview {
    width: 100%;
    display: block;
    background: var(--bg);
    object-fit: cover;
}

.file-preview-img { aspect-ratio: 16/9; }
.file-preview-cover { max-height: 220px; object-fit: contain; background: #111; }
.file-preview-video {
    width: 100%;
    display: block;
    background: #0a0a0a;
    max-height: 300px;
    object-fit: contain;
}

.file-card-footer {
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.file-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* ── Section divider ────────────────────────────────────────────────────── */

.section-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 4px 0 20px;
}
.section-divider::before, .section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.section-divider span {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    white-space: nowrap;
}

/* ── Toast ──────────────────────────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #111827;
    color: white;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    z-index: 100;
    animation: toastIn 0.2s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.mt-20 { margin-top: 20px; }

/* ── Mobile tweaks ──────────────────────────────────────────────────────── */

@media (max-width: 480px) {
    .app-header { padding: 0 12px; gap: 4px; }
    .header-brand { display: none; }
    .tab { padding: 7px 10px; font-size: 0.8125rem; gap: 5px; }
    .tab-panel { padding: 24px 16px 48px; }
    .login-card { padding: 40px 28px; }
    .rich-output { padding: 18px 20px; }
    .files-grid { grid-template-columns: 1fr; }
}
