:root {
    --ink:   #1a1008;
    --paper: #faf7f2;
    --cream: #f0ead8;
    --accent:#c8501a;
    --muted: #7a6e60;
    --border:#d9d0be;
    --radius:6px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'DM Sans', sans-serif;
    background: var(--paper);
    color: var(--ink);
    min-height: 100vh;
}

/* ---- login ---- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ink);
}
.login-box {
    background: var(--paper);
    padding: 3rem 2.5rem;
    width: 360px;
    border-radius: var(--radius);
}
.login-box h1 {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    margin-bottom: .25rem;
}
.login-box p.sub { color: var(--muted); font-size: .85rem; margin-bottom: 2rem; }
.field { margin-bottom: 1.25rem; }
.field label { display: block; font-size: .8rem; font-weight: 500; text-transform: uppercase;
    letter-spacing: .08em; color: var(--muted); margin-bottom: .4rem; }
.field input {
    width: 100%; padding: .7rem .9rem;
    border: 1.5px solid var(--border); border-radius: var(--radius);
    font-family: inherit; font-size: .95rem; background: #fff;
    transition: border-color .2s;
}
.field input:focus { outline: none; border-color: var(--accent); }
.btn {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .7rem 1.4rem; border-radius: var(--radius);
    font-family: inherit; font-size: .9rem; font-weight: 500;
    cursor: pointer; border: none; transition: opacity .15s, transform .1s;
    text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: .88; }
.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--cream); }
.btn-danger { background: transparent; color: #b33; border: 1.5px solid #f0c0c0; font-size:.8rem; padding:.4rem .8rem; }
.btn-danger:hover { background: #fff0f0; }
.error-msg { background: #fff0f0; border: 1px solid #f0c0c0; color: #b33;
    padding: .7rem 1rem; border-radius: var(--radius); font-size: .85rem; margin-bottom: 1rem; }
.success-msg { background: #f0fff4; border: 1px solid #a0e0b0; color: #1a6a35;
    padding: .7rem 1rem; border-radius: var(--radius); font-size: .85rem; margin-bottom: 1rem; }

/* ---- layout ---- */
.topbar {
    background: var(--ink); color: var(--paper);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 2rem; height: 56px;
}
.topbar .logo { font-family: 'Playfair Display', serif; font-size: 1.25rem; letter-spacing: .02em; }
.topbar .logo span { color: var(--accent); }
.topbar-right { display: flex; gap: .75rem; align-items: center; }
.topbar a { color: var(--paper); text-decoration: none; font-size: .85rem; opacity: .7; }
.topbar a:hover { opacity: 1; }

.container { max-width: 860px; margin: 0 auto; padding: 2.5rem 1.5rem; }

/* ---- tabs ---- */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 2rem; }
.tab {
    padding: .6rem 1.4rem; font-size: .9rem; font-weight: 500;
    color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent;
    margin-bottom: -2px; transition: color .15s, border-color .15s;
}
.tab.active { color: var(--accent); border-color: var(--accent); }
.tab:hover:not(.active) { color: var(--ink); }

/* ---- article list ---- */
.article-card {
    border: 1.5px solid var(--border); border-radius: var(--radius);
    padding: 1.25rem 1.5rem; margin-bottom: 1rem;
    display: flex; justify-content: space-between; align-items: flex-start;
    background: #fff; transition: box-shadow .15s;
}
.article-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,.07); }
.article-card h3 { font-family: 'Playfair Display', serif; font-size: 1.1rem; margin-bottom: .25rem; }
.article-card .meta { font-size: .8rem; color: var(--muted); }
.badge-published {
    display: inline-block; margin-left: .5rem;
    background: #e6f7ed; color: #1a6a35;
    border: 1px solid #a0e0b0; border-radius: 20px;
    font-size: .72rem; font-weight: 500;
    padding: .1rem .55rem; vertical-align: middle;
}
.article-card .actions { display: flex; gap: .5rem; flex-shrink: 0; margin-left: 1rem; }
.empty-state { text-align: center; padding: 4rem 2rem; color: var(--muted); }
.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { font-size: .95rem; margin-bottom: 1.5rem; }

/* ---- write form ---- */
.form-field { margin-bottom: 1.5rem; }
.form-field label { display: block; font-size: .8rem; font-weight: 500;
    text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .5rem; }
.form-field input[type=text] {
    width: 100%; padding: .75rem 1rem;
    border: 1.5px solid var(--border); border-radius: var(--radius);
    font-family: 'Playfair Display', serif; font-size: 1.2rem; background: #fff;
    transition: border-color .2s;
}
.form-field input[type=text]:focus { outline: none; border-color: var(--accent); }
#editor-container {
    border: 1.5px solid var(--border); border-radius: var(--radius); background: #fff;
    min-height: 320px;
}
.ql-toolbar { border: none !important; border-bottom: 1.5px solid var(--border) !important;
    border-radius: var(--radius) var(--radius) 0 0; background: var(--cream); }
.ql-container { border: none !important; font-family: 'DM Sans', sans-serif; font-size: .95rem; }
.ql-editor { min-height: 280px; padding: 1rem 1.25rem; }
.form-actions { display: flex; gap: .75rem; margin-top: 1.5rem; }

/* ---- preview ---- */
.preview-box {
    background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius);
    padding: 2.5rem 3rem; margin-bottom: 2rem;
}
.preview-box h2 { font-family: 'Playfair Display', serif; font-size: 2rem;
    line-height: 1.2; margin-bottom: .5rem; }
.preview-box .meta { color: var(--muted); font-size: .85rem; margin-bottom: 1.5rem;
    padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.preview-box .body { line-height: 1.75; }
.preview-box .body p { margin-bottom: 1em; }
.preview-box .body h1,.preview-box .body h2,.preview-box .body h3 {
    font-family: 'Playfair Display', serif; margin-bottom: .5em; }
.preview-actions { display: flex; gap: .75rem; }

/* ---- AI panel ---- */
.ai-panel {
    border: 1.5px solid var(--border); border-radius: var(--radius);
    background: var(--cream); padding: 1rem 1.25rem; margin-bottom: 1.5rem;
}
.ai-panel-header {
    display: flex; align-items: center; gap: .5rem;
    font-size: .8rem; font-weight: 500; text-transform: uppercase;
    letter-spacing: .08em; color: var(--muted); margin-bottom: .75rem;
}
.ai-panel-header svg { width: 14px; height: 14px; opacity: .6; }
.ai-row { display: flex; gap: .5rem; align-items: flex-start; }
.ai-row input[type=text] {
    flex: 1; padding: .6rem .9rem;
    border: 1.5px solid var(--border); border-radius: var(--radius);
    font-family: inherit; font-size: .9rem; background: #fff;
    transition: border-color .2s;
}
.ai-row input[type=text]:focus { outline: none; border-color: var(--accent); }
.btn-ai { background: #fff; color: var(--ink); border: 1.5px solid var(--border); }
.btn-ai:hover { background: var(--cream); }
.btn-ai-send { background: var(--accent); color: #fff; border: none; }
.btn-ai-send:hover { opacity: .88; }
.ai-spinner { display:none; font-size:.8rem; color:var(--muted); margin-top:.5rem; }
.ai-spinner.active { display:block; }
.ai-roles { display:flex; gap:.5rem; margin-bottom:.75rem; }
.ai-role-btn {
    flex:1; padding:.55rem .75rem; border-radius:var(--radius);
    border:1.5px solid var(--border); background:#fff;
    font-family:inherit; font-size:.85rem; cursor:pointer;
    color:var(--muted); transition:all .15s; text-align:center;
}
.ai-role-btn.selected {
    border-color:var(--accent); background:var(--accent);
    color:#fff; font-weight:500;
}

/* ---- blocking loader overlay ---- */
.ai-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(26,16,8,.55);
    backdrop-filter: blur(3px);
    align-items: center; justify-content: center;
}
.ai-overlay.active { display: flex; }
.ai-overlay-box {
    background: var(--paper); border-radius: var(--radius);
    padding: 2rem 2.5rem; text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.ai-overlay-box strong { font-family:'Playfair Display',serif; font-size:1.1rem; }
.ai-overlay-box p { font-size: .9rem; color: var(--muted); margin-top: .5rem; }
.ai-dots { display: flex; gap: .4rem; justify-content: center; margin-top: 1rem; }
.ai-dots span {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--accent); animation: ai-bounce .9s infinite ease-in-out;
}
.ai-dots span:nth-child(2) { animation-delay: .15s; }
.ai-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes ai-bounce {
    0%,80%,100% { transform: scale(.6); opacity:.4; }
    40%          { transform: scale(1);  opacity:1;  }
}

/* ---- role choice modal ---- */
.role-modal {
    display: none;
    position: fixed; inset: 0; z-index: 9998;
    background: rgba(26,16,8,.5);
    backdrop-filter: blur(3px);
    align-items: center; justify-content: center;
}
.role-modal.active { display: flex; }
.role-modal-box {
    background: var(--paper); border-radius: var(--radius);
    padding: 2rem 2.5rem; width: 360px; max-width: 90vw;
    box-shadow: 0 8px 32px rgba(0,0,0,.22);
    text-align: center;
}
.role-modal-box h3 {
    font-family: 'Playfair Display', serif;
    font-size: 1.2rem; margin-bottom: .4rem;
}
.role-modal-box p {
    font-size: .85rem; color: var(--muted); margin-bottom: 1.5rem;
}
.role-modal-actions {
    display: flex; flex-direction: column; gap: .65rem;
}
.role-modal-actions .btn {
    justify-content: center; width: 100%;
}

@media (max-width: 600px) {
    .container { padding: 1.5rem 1rem; }
    .preview-box { padding: 1.5rem; }
    .article-card { flex-direction: column; }
    .article-card .actions { margin-left: 0; margin-top: .75rem; }
}
