:root {
    --navy: #0f2f60;
    --royal: #1f5fc7;
    --blue: #2f73da;
    --light-blue: #eaf3ff;
    --pale: #f5f8fc;
    --white: #ffffff;
    --text: #152238;
    --muted: #6d7b91;
    --line: #dfe7f1;
    --green: #17835b;
    --red: #b42318;
    --amber: #9a6700;
    --shadow: 0 12px 36px rgba(23, 47, 83, .08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--pale); }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--pale);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.app-shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 26px 18px;
    background: linear-gradient(180deg, #0b2855 0%, #143c77 100%);
    color: white;
    display: flex;
    flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; }
.brand-mark {
    width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
    font-weight: 800; background: white; color: var(--navy); box-shadow: 0 8px 20px rgba(0,0,0,.15);
}
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; font-size: 11px; opacity: .7; margin-top: 3px; }
.nav-tabs { display: grid; gap: 8px; }
.nav-tab {
    width: 100%; border: 0; background: transparent; color: rgba(255,255,255,.78);
    display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; text-align: left;
}
.nav-tab:hover, .nav-tab.active { background: rgba(255,255,255,.12); color: white; }
.nav-icon {
    width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
    background: rgba(255,255,255,.1); font-size: 12px; font-weight: 800;
}
.sidebar-note {
    margin-top: auto; border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.08);
    border-radius: 12px; padding: 14px;
}
.sidebar-note strong, .sidebar-note span { display: block; }
.sidebar-note strong { font-size: 12px; }
.sidebar-note span { font-size: 10px; opacity: .7; margin-top: 4px; }

.main-content { min-width: 0; padding: 28px 34px 50px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 22px; margin-bottom: 24px; }
h1 { margin: 0; font-size: 27px; letter-spacing: -.4px; }
.topbar p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.account-area { display: flex; align-items: center; gap: 10px; }
.account-chip { display: flex; align-items: center; gap: 10px; background: white; border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px 6px 6px; }
.account-chip img, .avatar-fallback { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: grid; place-items: center; background: var(--light-blue); color: var(--royal); font-weight: 800; }
.account-chip strong, .account-chip span { display: block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-chip strong { font-size: 11px; }
.account-chip span { font-size: 9px; color: var(--muted); margin-top: 2px; }

.alert { padding: 13px 15px; border-radius: 11px; margin: 0 0 18px; font-size: 12px; border: 1px solid; }
.alert-warning { background: #fff8e7; border-color: #f0d083; color: #73510d; }
.alert-danger { background: #fff0ef; border-color: #efb6b1; color: #8b1c13; }
.alert-success { background: #edf9f4; border-color: #a8ddc9; color: #116844; }
code { padding: 2px 5px; background: rgba(0,0,0,.06); border-radius: 5px; }

.view { display: none; }
.view.active { display: block; }
.builder-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 22px; align-items: start; }
.builder-column { min-width: 0; display: grid; gap: 22px; }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.sticky-panel { position: sticky; top: 22px; }
.panel-heading { margin-bottom: 18px; }
.panel-heading.split { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.panel-heading h2 { margin: 3px 0 0; font-size: 18px; }
.eyebrow { color: var(--royal); font-size: 9px; font-weight: 800; letter-spacing: 1.3px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.field { display: grid; gap: 7px; }
.field-full { grid-column: 1 / -1; }
.field > span { font-size: 11px; font-weight: 700; color: #35455e; }
.field em { color: var(--red); font-style: normal; }
.field input, .field textarea, .field select, .compact-field select {
    width: 100%; border: 1px solid #cfd9e6; background: #fff; color: var(--text); border-radius: 9px;
    padding: 10px 11px; outline: none; transition: .15s border-color, .15s box-shadow;
}
.field input:focus, .field textarea:focus, .field select:focus, .compact-field select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47,115,218,.12); }
textarea { resize: vertical; }
.compact-field { margin: 18px 0; }
.compact-field select { margin-top: 7px; }
.helper { font-size: 10px; color: var(--muted); line-height: 1.45; }
.helper.center { text-align: center; margin: 11px 0 0; }

.btn { border: 1px solid transparent; border-radius: 9px; padding: 9px 13px; font-weight: 700; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; transition: .15s transform, .15s opacity, .15s background; }
.btn:hover:not(:disabled):not(.disabled) { transform: translateY(-1px); }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-primary { color: white; background: linear-gradient(135deg, var(--royal), var(--blue)); box-shadow: 0 7px 18px rgba(31,95,199,.2); }
.btn-secondary { color: var(--navy); background: var(--light-blue); border-color: #cfe2fb; }
.btn-ghost { color: #3d4f69; background: white; border-color: var(--line); }
.btn-google { color: white; background: #1a73e8; }
.btn-danger { color: var(--red); background: #fff4f3; border-color: #f4ceca; }
.btn-block { width: 100%; margin-top: 10px; padding: 11px 14px; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; }

.items-list { display: grid; gap: 13px; }
.item-card { border: 1px solid var(--line); border-radius: 13px; overflow: hidden; background: #fbfdff; }
.item-card.section-card { background: #f1f6fd; border-left: 4px solid var(--royal); }
.item-head { display: grid; grid-template-columns: 34px minmax(0,1fr) 190px auto; gap: 10px; align-items: center; padding: 13px 14px; border-bottom: 1px solid var(--line); background: white; }
.item-number { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 8px; background: var(--light-blue); color: var(--royal); font-size: 10px; font-weight: 800; }
.item-title-preview { min-width: 0; font-size: 12px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #3b4d65; }
.item-type { width: 100%; border: 1px solid #d7e0eb; border-radius: 8px; padding: 7px 8px; background: white; font-size: 10px; }
.item-actions { display: flex; gap: 5px; }
.icon-btn { width: 29px; height: 29px; border-radius: 8px; border: 1px solid var(--line); background: white; color: #5c6c82; display: grid; place-items: center; font-size: 11px; }
.icon-btn:hover { background: var(--light-blue); color: var(--royal); }
.icon-btn.delete:hover { background: #fff1f0; color: var(--red); }
.item-body { padding: 14px; display: grid; gap: 12px; }
.item-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.inline-grid.three { grid-template-columns: repeat(3,minmax(0,1fr)); }
.checkbox-line { display: flex; align-items: center; gap: 8px; font-size: 10px; color: #465970; }
.checkbox-line input { accent-color: var(--royal); }
.quiz-fields { border-top: 1px dashed #d9e2ec; padding-top: 12px; }

.toggle-row { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "text toggle"; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle-row > div { grid-area: text; }
.toggle-row strong, .toggle-row span { display: block; }
.toggle-row strong { font-size: 11px; }
.toggle-row div span { font-size: 9px; color: var(--muted); margin-top: 3px; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.toggle { grid-area: toggle; width: 38px; height: 22px; background: #cbd5e1; border-radius: 999px; position: relative; transition: .2s; }
.toggle::after { content: ""; width: 16px; height: 16px; border-radius: 50%; position: absolute; left: 3px; top: 3px; background: white; box-shadow: 0 2px 5px rgba(0,0,0,.2); transition: .2s; }
.toggle-row input:checked + .toggle { background: var(--royal); }
.toggle-row input:checked + .toggle::after { transform: translateX(16px); }
.summary-box { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: #f5f8fc; border: 1px solid var(--line); border-radius: 11px; padding: 12px; margin: 16px 0 4px; }
.summary-box div { display: grid; gap: 3px; }
.summary-box span { color: var(--muted); font-size: 9px; }
.summary-box strong { font-size: 13px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px,1fr)); gap: 14px; }
.template-card { border: 1px solid var(--line); border-radius: 12px; padding: 15px; background: #fbfdff; }
.template-card h3 { margin: 0 0 5px; font-size: 13px; }
.template-card p { margin: 0; color: var(--muted); font-size: 10px; }
.template-card .actions { display: flex; gap: 7px; margin-top: 14px; }
.history-list { display: grid; gap: 9px; }
.history-row { display: grid; grid-template-columns: minmax(0,1fr) 155px 110px auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 11px; padding: 12px 13px; }
.history-row strong { display: block; font-size: 11px; }
.history-row span { color: var(--muted); font-size: 9px; }
.status-pill { display: inline-flex; width: max-content; padding: 4px 8px; border-radius: 999px; font-size: 9px; font-weight: 800; background: #eaf8f1; color: var(--green); }
.status-pill.draft { background: #fff5df; color: var(--amber); }
.empty-state { min-height: 130px; place-items: center; color: var(--muted); font-size: 11px; text-align: center; }

.modal { position: fixed; inset: 0; display: none; place-items: center; z-index: 100; padding: 20px; }
.modal.open { display: grid; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,25,49,.52); backdrop-filter: blur(3px); }
.modal-card { position: relative; z-index: 1; width: min(520px,100%); background: white; border-radius: 18px; padding: 28px; box-shadow: 0 22px 70px rgba(5,25,55,.3); text-align: center; }
.modal-card.small { width: min(410px,100%); text-align: left; }
.modal-card h2 { margin: 8px 0; font-size: 21px; }
.modal-card p { color: var(--muted); font-size: 11px; }
.modal-close { position: absolute; right: 13px; top: 11px; border: 0; background: transparent; color: #6d7b91; font-size: 22px; }
.success-badge { width: 50px; height: 50px; display: grid; place-items: center; margin: 0 auto; border-radius: 50%; background: #e9f8f1; color: var(--green); font-size: 23px; font-weight: 900; }
.result-links { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 200; padding: 12px 15px; border-radius: 10px; background: #172d4d; color: white; font-size: 11px; box-shadow: 0 14px 35px rgba(0,0,0,.2); transform: translateY(25px); opacity: 0; pointer-events: none; transition: .22s; max-width: 360px; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #8e251d; }

@media (max-width: 1050px) {
    .app-shell { grid-template-columns: 78px 1fr; }
    .brand > div:last-child, .nav-tab:not(.active) span + *, .sidebar-note { display: none; }
    .brand { justify-content: center; padding-inline: 0; }
    .nav-tab { justify-content: center; font-size: 0; padding: 12px; }
    .builder-layout { grid-template-columns: 1fr; }
    .sticky-panel { position: static; }
}
@media (max-width: 720px) {
    .app-shell { display: block; }
    .sidebar { position: static; width: 100%; height: auto; padding: 11px 14px; flex-direction: row; align-items: center; }
    .brand { padding: 0; margin-right: 10px; }
    .brand-mark { width: 34px; height: 34px; border-radius: 9px; }
    .nav-tabs { display: flex; margin-left: auto; }
    .nav-tab { width: auto; }
    .main-content { padding: 18px 14px 40px; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .account-area { width: 100%; justify-content: space-between; }
    .account-chip { min-width: 0; }
    .panel { padding: 16px; border-radius: 13px; }
    .panel-heading.split { align-items: flex-start; flex-direction: column; }
    .form-grid, .item-grid, .inline-grid, .inline-grid.three { grid-template-columns: 1fr; }
    .item-head { grid-template-columns: 30px minmax(0,1fr); }
    .item-head .item-type { grid-column: 1 / -1; }
    .item-actions { grid-column: 1 / -1; justify-content: flex-end; }
    .history-row { grid-template-columns: 1fr; }
}
