/* ========================================
   Digital Atelier — Viên Japan Content Writer
   Design System: "The Editorial Alchemist" V3
   Layout: Sidebar + Dual Panel (Stitch-inspired)
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif:ital,wght@0,400;0,600;0,700;1,400&family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
    /* ===== MIDNIGHT PALETTE ===== */
    --surface: #131313;
    --surface-container-lowest: #0e0e0e;
    --surface-container-low: #1c1b1b;
    --surface-container: #201f1f;
    --surface-container-high: #2a2a2a;
    --surface-container-highest: #353534;
    --surface-variant: #353534;
    
    /* Gold */
    --primary: #f2ca50;
    --primary-container: #d4af37;
    --primary-dim: #e9c349;
    --on-primary: #3c2f00;
    
    /* Secondary */
    --secondary: #dac58d;
    --secondary-container: #544519;
    
    /* Text */
    --on-surface: #e5e2e1;
    --on-surface-variant: #d0c5af;
    --outline: #99907c;
    --outline-variant: #4d4635;
    
    /* Tertiary */
    --tertiary: #bfcdff;
    
    /* Status */
    --success: #4ade80;
    --warning: #fbbf24;
    --error: #ffb4ab;
    
    /* Gradients & Effects */
    --gold-gradient: linear-gradient(135deg, #f2ca50 0%, #d4af37 100%);
    --gold-glow: rgba(212, 175, 55, 0.25);
    --gold-glow-soft: rgba(212, 175, 55, 0.08);
    --ambient-glow: rgba(242, 202, 80, 0.05);
    --ghost-border: rgba(77, 70, 53, 0.12);
    --glass-bg: rgba(53, 53, 52, 0.55);
    --glass-blur: blur(20px);
    
    /* Typography */
    --font-display: 'Noto Serif', Georgia, serif;
    --font-body: 'Manrope', -apple-system, sans-serif;
    
    /* Shape — Stitch-inspired: buttons sắc nét, panels mềm mại */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-pill: 999px;
}

/* ======== RESET ======== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-body);
    background: var(--surface);
    color: var(--on-surface);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ======== APP LAYOUT ======== */
.app-layout {
    min-height: 100vh;
}

/* ======== SIDEBAR (Stitch Style) ======== */
.sidebar {
    background: var(--surface-container-lowest);
    border-right: 1px solid var(--ghost-border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 24px 12px;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 220px;
    overflow-y: auto;
}

.sidebar-top { flex: 1; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px 24px;
}

.brand-logo {
    color: var(--primary);
    display: flex;
}

.brand-name {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 600;
    color: var(--on-surface);
    line-height: 1.2;
}

.brand-sub {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--outline);
    text-transform: uppercase;
}

/* Sidebar Nav — Stitch style: subtle bg on hover, solid bg on active */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--outline);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
}

.nav-item:hover {
    color: var(--on-surface);
    background: rgba(255, 255, 255, 0.04);
}

.nav-item.active {
    color: var(--on-primary);
    background: var(--gold-gradient);
    font-weight: 600;
}

.nav-item.active .nav-icon-svg {
    color: var(--on-primary);
}

/* SVG Icons */
.nav-icon-svg {
    color: currentColor;
    flex-shrink: 0;
}

.tab-icon {
    color: currentColor;
    flex-shrink: 0;
    vertical-align: middle;
}

.btn-icon-svg {
    color: currentColor;
    flex-shrink: 0;
}

.template-icon-svg {
    color: var(--primary);
    flex-shrink: 0;
}

.feature-icon-svg {
    color: var(--primary);
    display: block;
    margin-bottom: 12px;
}

/* Settings Panel */
.settings-panel {
    margin-top: 12px;
    padding: 0 4px;
}

.settings-inner {
    background: var(--surface-container);
    border-radius: var(--radius-md);
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

.btn-sm {
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-body);
    border: 1px solid var(--outline-variant);
    background: transparent;
    color: var(--on-surface-variant);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-sm:hover { background: var(--surface-container-high); }
.btn-sm.btn-accent {
    background: var(--gold-gradient);
    color: var(--on-primary);
    border-color: transparent;
}
.btn-sm.btn-success { border-color: var(--success); color: var(--success); }

/* History Panel */
.history-panel {
    margin-top: 12px;
    padding: 0 4px;
}

.history-list {
    background: var(--surface-container);
    border-radius: var(--radius-md);
    padding: 8px;
    max-height: calc(100vh - 300px);
    overflow-y: auto;
}

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb { background: var(--outline-variant); border-radius: 4px; }

.history-empty {
    text-align: center;
    padding: 24px 12px;
    color: var(--outline);
    font-size: 12px;
    font-style: italic;
}

.history-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid rgba(77, 70, 53, 0.06);
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.history-item:last-child { border-bottom: none; }

.history-item-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--on-surface);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 2px;
}

.history-item-time {
    font-size: 10px;
    color: var(--outline);
}

.history-item-preview {
    font-size: 11px;
    color: var(--on-surface-variant);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}

/* Sidebar Bottom */
.sidebar-bottom {
    padding-top: 16px;
}

.sidebar-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 11px;
    color: var(--outline);
    font-weight: 500;
}

.badge-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--error);
}

.badge-dot.active { background: var(--success); }

/* ======== MAIN CONTENT ======== */
.main-content {
    margin-left: 220px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ======== TOPBAR ======== */
.topbar {
    padding: 28px 24px 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.topbar-left { flex: 1; }

.topbar-version {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--primary);
    text-transform: uppercase;
}

.topbar-title {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    color: var(--on-surface);
    margin-top: 2px;
    white-space: nowrap;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    padding-top: 8px;
}

.model-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--outline-variant);
    background: var(--surface-container);
    font-size: 11px;
    font-weight: 600;
    color: var(--on-surface-variant);
    white-space: nowrap;
}

.model-badge svg { color: var(--primary); }

/* ======== WORKSPACE ======== */
.workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    margin: 20px 24px;
    flex: 1;
}

/* ======== PANELS ======== */
.panel {
    background: var(--surface-container-low);
    border: 1px solid var(--ghost-border);
}

.input-panel {
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    border-right: none;
    background: var(--surface);
}

.output-panel {
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    display: flex;
    flex-direction: column;
    background: var(--surface-container-low);
}

/* ======== INPUT TABS ======== */
.input-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 16px 16px 0;
    gap: 4px;
}

.input-tab {
    padding: 10px 16px;
    border: 1px solid var(--ghost-border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--outline);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.25s ease;
    letter-spacing: 0.03em;
}

.input-tab:hover {
    color: var(--on-surface);
    background: rgba(212, 175, 55, 0.05);
}

.input-tab.active {
    background: var(--gold-gradient);
    color: var(--on-primary);
    border-color: transparent;
}

.input-tab.active .tab-icon { color: var(--on-primary); }

/* ======== FORMS ======== */
.form { padding: 20px; }

.form-section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--outline);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.form-group {
    margin-bottom: 14px;
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--outline);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.form-group .optional {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

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

input[type="text"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--ghost-border);
    background: var(--surface-container);
    color: var(--on-surface);
    font-family: var(--font-body);
    font-size: 13px;
    transition: border-color 0.2s ease;
    outline: none;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
}

textarea { resize: vertical; }

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2399907c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

::placeholder { color: var(--outline); opacity: 0.6; }

/* ======== BUTTONS ======== */
.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn-gold {
    background: var(--gold-gradient);
    color: var(--on-primary);
    flex: 1;
}

.btn-gold:hover {
    box-shadow: 0 4px 20px var(--gold-glow);
    transform: translateY(-1px);
}

.btn-gold:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--outline-variant);
    color: var(--on-surface-variant);
}

.btn-ghost:hover {
    background: var(--surface-container-high);
    border-color: var(--outline);
}

.btn-icon-compact {
    padding: 10px 12px;
}

/* ======== OUTPUT PANEL ======== */
.panel-header-output {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--ghost-border);
}

.output-title {
    font-family: var(--font-display);
    font-size: 20px;
    color: var(--primary);
    font-weight: 600;
}

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

.btn-action {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--ghost-border);
    background: transparent;
    color: var(--on-surface-variant);
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.btn-action:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Output Tabs */
.output-tabs {
    display: flex;
    border-top: 1px solid var(--ghost-border);
}

.tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    color: var(--outline);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 0;
}

.tab:hover {
    color: var(--on-surface);
    background: rgba(212, 175, 55, 0.05);
}

.tab.active {
    background: rgba(212, 175, 55, 0.1);
    color: var(--primary);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.output-area {
    padding: 24px;
    min-height: 280px;
    flex: 1;
}

/* Placeholder — Quote style */
.output-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 250px;
}

.placeholder-quote {
    max-width: 320px;
    position: relative;
}

.quote-mark {
    font-family: var(--font-display);
    font-size: 48px;
    color: var(--primary);
    opacity: 0.25;
    line-height: 1;
    display: block;
}

.quote-mark:last-child {
    text-align: right;
}

.quote-text {
    font-family: var(--font-display);
    font-size: 14px;
    font-style: italic;
    color: var(--on-surface-variant);
    line-height: 1.7;
}

/* Generated content */
.generated-content {
    font-size: 14px;
    line-height: 1.8;
    color: var(--on-surface);
    white-space: pre-wrap;
    padding: 4px 0;
}

.generated-content::selection {
    background: rgba(242, 202, 80, 0.3);
    color: #fff;
}

/* Loading state */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    gap: 16px;
}

.loading-bloom {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--gold-gradient);
    animation: bloom 1.5s ease-in-out infinite;
}

@keyframes bloom {
    0%, 100% { transform: scale(1); opacity: 0.5; box-shadow: 0 0 0 0 var(--gold-glow); }
    50% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 30px var(--gold-glow); }
}

.loading-state p {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 14px;
    color: var(--on-surface-variant);
}

/* Cursor blink */
.cursor-blink::after {
    content: '▌';
    animation: blink 0.8s step-end infinite;
    color: var(--primary);
    text-shadow: 0 0 8px var(--gold-glow);
}

@keyframes blink { 50% { opacity: 0; } }

/* ======== TEMPLATES — Outside Output Card, Right Column (Stitch style) ======== */
.templates-section {
    grid-column: 2;
    padding: 12px 0 0 0;
    border-top: none;
    background: transparent;
}

.templates-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--outline);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    display: block;
    margin-bottom: 10px;
}

.templates-grid-inline {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.example-btn {
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--surface-container);
    color: var(--on-surface-variant);
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.example-btn:hover {
    background: var(--surface-container-high);
    color: var(--primary);
}

/* ======== MẪU NHANH — Standalone Section (Stitch-style) ======== */
.templates-section-standalone {
    background: var(--surface-container-low);
    border: 1px solid var(--ghost-border);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    margin: 16px 32px;
}

/* ======== FEATURE CARDS ======== */
.feature-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 16px 32px 20px;
}

.feature-card {
    background: var(--surface-container-low);
    border: 1px solid var(--ghost-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: border-color 0.3s;
}

.feature-card:hover { border-color: rgba(212, 175, 55, 0.2); }

.feature-card h3 {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    color: var(--on-surface);
    margin-bottom: 6px;
}

.feature-card p {
    font-size: 12px;
    color: var(--on-surface-variant);
    line-height: 1.6;
}

/* ======== FOOTER ======== */
.footer {
    text-align: center;
    padding: 16px 32px 24px;
}

.footer p {
    font-size: 11px;
    color: var(--outline);
    letter-spacing: 0.02em;
}

/* ======== TOAST ======== */
.toast {
    position: fixed;
    bottom: 32px;
    right: 32px;
    padding: 12px 24px;
    background: var(--gold-gradient);
    color: var(--on-primary);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 8px 32px var(--gold-glow);
    opacity: 0;
    transform: translateY(16px);
    transition: all .35s cubic-bezier(.4,0,.2,1);
    z-index: 9999;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* ======== Input Mode Toggle ======== */
.input-mode {
    display: none;
}
.input-mode.active {
    display: block;
}

/* ======== Scrollbar ======== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--outline-variant); border-radius: 4px; }

/* ======== Hamburger Menu (mobile/tablet only) ======== */
.hamburger-btn {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 1100;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(20, 20, 25, 0.9);
    color: var(--accent-gold);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}
.hamburger-btn:hover {
    background: var(--bg-elevated);
    color: var(--accent-gold);
    border-color: var(--accent-gold);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ======== Responsive — Tablet ======== */
@media (max-width: 1024px) {
    .hamburger-btn { display: flex; }

    .app-layout { grid-template-columns: 1fr; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 260px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-right: 1px solid var(--ghost-border);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
    }
    .sidebar.open {
        transform: translateX(0);
        display: flex !important;
    }
    .main-content { margin-left: 0; }
    .workspace { grid-template-columns: 1fr; margin: 16px; gap: 16px; }
    .input-panel { border-radius: var(--radius-lg); border-right: 1px solid var(--ghost-border); }
    .output-panel { border-radius: var(--radius-lg); }
    .templates-section { grid-column: auto; }
    .feature-cards { grid-template-columns: 1fr; padding: 16px; }
    .topbar { padding: 16px; padding-left: 64px; }
}

/* ======== Responsive — Mobile ======== */
@media (max-width: 640px) {
    .app-layout { grid-template-columns: 1fr; }
    .sidebar {
        width: 280px;
    }
    .main-content { margin-left: 0; padding: 0; }

    .topbar {
        padding: 12px 16px 12px 64px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .topbar-title { font-size: 1.25rem; }

    .workspace {
        grid-template-columns: 1fr;
        margin: 12px;
        gap: 12px;
    }

    .input-panel,
    .output-panel {
        border-radius: var(--radius-lg);
        border: 1px solid var(--ghost-border);
    }
    .input-panel { border-right: 1px solid var(--ghost-border); }

    .panel { padding: 16px; }

    /* Form elements stack vertically */
    .form-row {
        flex-direction: column;
        gap: 12px;
    }
    .form-row .form-group { width: 100%; }

    /* Action buttons — compact on mobile */
    .form-actions {
        flex-wrap: nowrap;
        gap: 8px;
    }
    .form-actions .btn {
        font-size: 11px;
        padding: 10px 12px;
        white-space: nowrap;
    }
    .form-actions .btn .btn-icon-svg {
        display: none;
    }
    .form-actions .btn-icon-compact {
        padding: 10px 12px;
    }

    /* Action buttons stack */
    .action-row {
        flex-direction: column;
        gap: 8px;
    }
    .action-row .btn { width: 100%; }

    /* Output tabs */
    .output-tabs { flex-direction: row; }
    .output-tabs .tab { font-size: 11px; padding: 8px 12px; }

    /* Templates section */
    .templates-section {
        grid-column: auto;
        padding: 8px 0 0 0;
    }
    .templates-grid-inline {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .example-btn {
        padding: 10px 12px;
        font-size: 10px;
    }

    /* Feature cards */
    .feature-cards {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 12px;
    }

    /* Model badge */
    .model-badge { font-size: 10px; padding: 4px 10px; }
}
