:root {
    --bg: #09060d;
    --card: rgba(20, 12, 28, 0.78);
    --line: rgba(217, 38, 98, 0.18);
    --line-strong: rgba(217, 38, 98, 0.62);
    --red: #d92662;
    --violet: #8e2de2;
    --gold: #e6c27a;
    --text: #f6f1fa;
    --muted: #a89bb8;
    --faint: #6f6280;
    --ok: #7dcea0;
    --warn: #e6c27a;
    --font-display: "Playfair Display", serif;
    --font-body: "Outfit", sans-serif;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.5;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.glow {
    position: fixed; inset: -20% auto auto 15%;
    width: 70vw; height: 70vh;
    background: radial-gradient(circle, rgba(142, 45, 226, 0.18), rgba(217, 38, 98, 0.05) 42%, transparent 70%);
    pointer-events: none; z-index: 0;
}
.grain {
    position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: 0.18;
    background-image: radial-gradient(rgba(255,255,255,.35) 0.6px, transparent 0.7px);
    background-size: 3px 3px;
}

.app-header, .app-footer, .workspace { position: relative; z-index: 1; }
.app-header, .app-footer {
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    padding: 1.1rem 1.6rem;
}
.app-header { border-bottom: 1px solid rgba(255,255,255,.06); background: rgba(9, 6, 13, .72); backdrop-filter: blur(12px); }
.app-footer { color: var(--faint); font-size: .82rem; justify-content: center; }
.brand { font-family: var(--font-display); font-size: 2rem; font-weight: 800; letter-spacing: .02em; }
.brand span { color: var(--red); }
.tagline { color: var(--muted); letter-spacing: .14em; text-transform: uppercase; font-size: .72rem; margin-top: .15rem; }
.header-actions, .user-badge { display: flex; align-items: center; gap: .6rem; }

.icon-btn, .btn {
    border: 1px solid rgba(255,255,255,.1);
    background: rgba(255,255,255,.04);
    border-radius: 999px;
    padding: .55rem 1rem;
    display: inline-flex; align-items: center; gap: .45rem;
    transition: .2s ease;
}
.icon-btn:hover, .btn:hover { border-color: var(--line-strong); }
.btn-primary, .action-btn {
    background: linear-gradient(135deg, var(--red), #8e244c);
    border-color: transparent; font-weight: 600;
}
.btn-danger { color: #ffb4c8; }
.user-badge {
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 999px; padding: .4rem .8rem; color: var(--muted); font-size: .9rem;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
    gap: 1.1rem;
    padding: 1.1rem;
    align-items: start;
}
.glass {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}
.panel { padding: 1.15rem 1.2rem 1.3rem; }
.panel-head, .display-head, .archive-head {
    display: flex; justify-content: space-between; align-items: center; gap: .8rem; margin-bottom: 1rem;
}
h2, h3 { font-family: var(--font-display); font-weight: 600; }
.section-title { font-size: 1.35rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.span-2 { grid-column: span 2; }
label, .group-label {
    display: block; color: var(--muted); font-size: .78rem;
    letter-spacing: .08em; text-transform: uppercase; margin-bottom: .35rem;
}
input[type="text"], input[type="password"], textarea, select {
    width: 100%;
    background: rgba(0,0,0,.28);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 12px;
    padding: .7rem .8rem;
    outline: none;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--line-strong); }
.field-help { color: var(--faint); font-size: .78rem; margin-top: .3rem; }

.dropdown { position: relative; }
.dropdown-toggle, .check {
    width: 100%; text-align: left;
    background: rgba(0,0,0,.28);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 12px;
    padding: .65rem .75rem;
    display: flex; justify-content: space-between; align-items: center; gap: .5rem;
}
.dropdown.open .dropdown-toggle, .check:hover { border-color: var(--line-strong); }
.dropdown-menu {
    display: none; position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 6px);
    max-height: 280px; overflow: auto;
    background: #160d1d; border: 1px solid var(--line); border-radius: 14px; padding: .35rem;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item, .check {
    border-radius: 10px;
}
.dropdown-item {
    width: 100%; text-align: left; background: transparent; border: 0; padding: .55rem .6rem;
    display: flex; gap: .6rem; align-items: flex-start;
}
.dropdown-item.active, .dropdown-item:hover { background: rgba(217, 38, 98, .12); }
.opt-icon {
    width: 1.7rem; flex: none; color: var(--gold); font-family: var(--font-display);
}
.opt-title { display: block; font-weight: 600; }
.opt-desc { display: block; color: var(--muted); font-size: .78rem; }

.clauses { display: flex; flex-direction: column; gap: .55rem; margin: .2rem 0 1rem; }
.clause-group h3 { font-size: 1rem; margin: .7rem 0 .35rem; color: var(--gold); }
.check {
    gap: .7rem; align-items: flex-start;
}
.check input { margin-top: .25rem; accent-color: var(--red); }
.check small { display: block; color: var(--muted); font-size: .78rem; text-transform: none; letter-spacing: 0; }
.check.locked { opacity: .85; }

.action-btn {
    width: 100%; justify-content: center; border-radius: 14px; padding: .9rem 1rem; margin-top: .4rem;
}
.action-btn:disabled { opacity: .6; cursor: progress; }
.legal-note { color: var(--faint); font-size: .78rem; margin-top: .7rem; }

.badge {
    border-radius: 999px; padding: .25rem .7rem; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase;
    border: 1px solid rgba(255,255,255,.1); color: var(--muted);
}
.badge.live { color: var(--ok); border-color: rgba(125, 206, 160, .4); }
.badge.demo { color: var(--warn); border-color: rgba(230, 194, 122, .4); }

.contract-scroll {
    min-height: 68vh; max-height: calc(100vh - 180px); overflow: auto;
    padding: 1.4rem 1.6rem 2rem;
    background:
        linear-gradient(180deg, rgba(255,255,255,.025), transparent 80px),
        rgba(8, 5, 12, .45);
}
.contract-article { max-width: 74ch; margin: 0 auto; }
.contract-article h1 { font-size: 2.1rem; line-height: 1.15; margin-bottom: .8rem; }
.contract-article h2 { font-size: 1.35rem; margin: 1.4rem 0 .45rem; color: var(--gold); }
.contract-article h3 { font-size: 1.05rem; margin: 1rem 0 .35rem; }
.contract-article p, .contract-article li { color: #efe8f4; margin-bottom: .7rem; }
.contract-article ul, .contract-article ol { padding-left: 1.2rem; margin-bottom: .8rem; }
.contract-article blockquote {
    border-left: 2px solid var(--red); padding-left: .9rem; color: var(--muted); margin: 0 0 1rem;
}
.contract-article hr { border: 0; border-top: 1px solid rgba(255,255,255,.08); margin: 1.2rem 0; }
#contract-source { width: 100%; min-height: 68vh; border: 0; background: transparent; padding: 1.4rem 1.6rem 2rem; }
.empty-state, .loading-state { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.empty-mark {
    font-family: var(--font-display); font-size: 3rem; color: var(--gold); display: block; margin-bottom: .4rem;
}
.spinner {
    width: 46px; height: 46px; margin: 0 auto 1rem; border-radius: 50%;
    border: 2px solid rgba(255,255,255,.1); border-top-color: var(--red);
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.meta { color: var(--faint); font-size: .82rem; padding: .7rem 1rem 0; }

.archive-drawer {
    position: fixed; z-index: 30; top: 0; right: 0; height: 100%; width: min(420px, 100%);
    border-radius: 0; border-right: 0; padding: 1rem; overflow: auto;
    transform: translateX(104%); transition: transform .25s ease;
}
.archive-drawer.open { transform: none; }
.archive-item, .archive-empty {
    width: 100%; text-align: left; background: rgba(255,255,255,.03);
    border: 1px solid rgba(255,255,255,.06); border-radius: 12px; padding: .75rem; margin-bottom: .5rem;
}
.archive-item strong { display: block; }
.archive-item span { color: var(--muted); font-size: .78rem; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 25; }

.modal {
    position: fixed; inset: 0; z-index: 40; display: none;
    align-items: center; justify-content: center; padding: 1rem;
    background: rgba(0,0,0,.55);
}
.modal.active { display: flex; }
.modal-card { width: min(560px, 100%); padding: 1.2rem; }
.modal-card header, .modal-card footer { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.modal-card p { color: var(--muted); margin: .8rem 0; }
.close { background: transparent; border: 0; font-size: 1.5rem; line-height: 1; }

.login-overlay {
    position: fixed; inset: 0; z-index: 50; display: none;
    align-items: center; justify-content: center; padding: 1rem;
    background: rgba(5, 2, 8, .82);
}
.login-overlay.active { display: flex; }
.login-card { width: min(440px, 100%); padding: 1.6rem; text-align: center; }
.login-card form { text-align: left; display: flex; flex-direction: column; gap: .8rem; margin-top: 1rem; }
.login-error { color: #ffb4c8; font-size: .9rem; }
.pass-wrap { position: relative; }
.pass-wrap button {
    position: absolute; right: .4rem; top: 50%; transform: translateY(-50%);
    background: transparent; border: 0; color: var(--muted);
}

.toast {
    position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
    background: #1a101f; border: 1px solid var(--line); color: var(--text);
    padding: .7rem 1rem; border-radius: 999px; z-index: 60;
}

@media (max-width: 980px) {
    .workspace { grid-template-columns: 1fr; }
    .contract-scroll { max-height: none; }
    .app-header { align-items: flex-start; flex-direction: column; }
}
@media print {
    body { background: white; color: black; }
    .app-header, .app-footer, .criteria, .archive-drawer, .backdrop, .toast, .modal, .login-overlay, .glow, .grain, .display-head .tools { display: none !important; }
    .workspace { display: block; padding: 0; }
    .glass { box-shadow: none; border: 0; background: white; }
    .contract-article, .contract-article p, .contract-article li { color: black; }
}
