@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&display=swap');

:root {
    --bg: #F3F4F0;
    --surface: #FFFFFF;
    --text: #1F241F;
    --muted: #6C7268;
    --border: #DFE1D9;
    --brand: #23392F;
    --accent: #3E6259;
    --accent-hover: #345349;
    --danger: #A8493E;
    --draft: #9A7B2E;
    --font-head: 'Space Grotesk', 'Segoe UI', sans-serif;
    --font-body: 'Inter', 'Segoe UI', sans-serif;
    --radius-s: 6px;
    --radius-m: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}
h1, h2, h3 { font-family: var(--font-head); font-weight: 600; margin: 0 0 6px; color: var(--brand); }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---------- buttons & form controls ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-s);
    padding: 9px 16px; font-size: 14px; font-family: var(--font-body); font-weight: 500;
    cursor: pointer; text-decoration: none; transition: border-color .15s ease, background .15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-small { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.btn-danger-text { color: var(--danger); border-color: var(--border); }
.btn-danger-text:hover { border-color: var(--danger); }
.inline { display: inline-block; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 12px; color: var(--text); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=tel], input[type=date], input[type=file], select, textarea {
    display: block; width: 100%; margin-top: 5px;
    padding: 10px 12px; font-size: 14px; font-family: var(--font-body);
    border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--surface); color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.checkbox-row input { width: auto; margin: 0; }

.alert { padding: 10px 14px; border-radius: var(--radius-s); font-size: 14px; margin: 0 0 16px; }
.alert-error { background: #F7E7E4; color: var(--danger); }
.alert-success { background: #E6EEE9; color: var(--accent); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; text-transform: capitalize; }
.badge-published { background: #E1EFE7; color: #276145; }
.badge-draft { background: #F4EEDD; color: #8A6D1D; }
.badge-closed { background: #EFEAE5; color: #7B7369; }

.link { color: var(--accent); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }
.link-muted { color: var(--muted); text-decoration: none; font-size: 14px; }
.logo-mark { display: inline-block; width: 18px; height: 18px; border-radius: 5px; background: var(--accent); margin-right: 8px; vertical-align: -3px; }

/* ---------- auth pages ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 36px; width: 100%; max-width: 380px; }
.auth-brand { font-family: var(--font-head); font-weight: 700; font-size: 15px; color: var(--brand); margin-bottom: 20px; }
.auth-page h1 { font-size: 22px; margin-bottom: 18px; }

/* ---------- app shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 230px; flex-shrink: 0; background: var(--brand); color: #EAEDE9;
    display: flex; flex-direction: column; padding: 22px 16px; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { font-family: var(--font-head); font-weight: 700; font-size: 16px; color: #fff; margin-bottom: 28px; padding: 0 8px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-nav a { color: #C7D0C9; text-decoration: none; padding: 9px 10px; border-radius: var(--radius-s); font-size: 14px; font-weight: 500; }
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav a.active { background: var(--accent); color: #fff; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; margin-top: 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-chip .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.user-chip strong { display: block; font-size: 13px; color: #fff; }
.user-chip small { color: #9FAB9F; font-size: 12px; }
.sidebar-footer .link-muted { color: #9FAB9F; font-size: 13px; display: block; margin-top: 4px; }

.main-content { flex: 1; padding: 32px 40px; max-width: 1100px; }
.page-head { margin-bottom: 24px; }
.page-head-row { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.page-head h1 { font-size: 24px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 18px; }
.stat-number { display: block; font-family: var(--font-head); font-size: 28px; font-weight: 700; color: var(--brand); }
.stat-label { color: var(--muted); font-size: 13px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 22px; margin-bottom: 20px; }
.panel-head { margin-bottom: 14px; }
.panel-head-row { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { font-size: 16px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.table-scroll { overflow-x: auto; }
.nowrap { white-space: nowrap; }

.quick-links { display: flex; gap: 10px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 18px; display: flex; flex-direction: column; }
.form-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.form-card h3 { font-size: 16px; margin-bottom: 2px; }
.form-card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.template-card {
    display: block; width: 100%; text-align: left; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-m); padding: 18px;
    cursor: pointer; font-family: var(--font-body);
}
.template-card:hover { border-color: var(--accent); }
.template-card h3 { font-size: 16px; }
.template-card p { margin: 4px 0 10px; }
.template-card-ai { border-color: var(--accent); text-decoration: none; color: var(--text); }

.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 4px; }
.bar-label { font-size: 10px; color: var(--muted); margin-top: 4px; }

/* ---------- builder ---------- */
.builder-page { margin: 0; background: var(--bg); }
.builder-topbar { display: flex; align-items: center; gap: 18px; padding: 12px 22px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.builder-title-input { border: 1px solid transparent; background: transparent; font-family: var(--font-head); font-size: 17px; font-weight: 600; padding: 6px 8px; border-radius: var(--radius-s); flex: 1; max-width: 420px; }
.builder-title-input:hover, .builder-title-input:focus { border-color: var(--border); background: var(--bg); outline: none; }
.builder-topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.builder-body { display: grid; grid-template-columns: 210px 1fr 300px; gap: 0; align-items: start; }
.palette, .properties { background: var(--surface); padding: 18px; height: calc(100vh - 57px); overflow-y: auto; position: sticky; top: 57px; }
.palette { border-right: 1px solid var(--border); }
.properties { border-left: 1px solid var(--border); }
.palette h3, .properties h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-bottom: 12px; }
.palette-item {
    display: block; width: 100%; text-align: left; margin-bottom: 6px; padding: 9px 10px;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-s);
    font-size: 13px; cursor: grab; font-family: var(--font-body);
}
.palette-item:hover { border-color: var(--accent); color: var(--accent); }

.canvas-wrap { padding: 24px; min-height: calc(100vh - 57px); }
.canvas-form-meta textarea { min-height: 60px; margin-bottom: 18px; }
.canvas { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.canvas-empty { text-align: center; padding: 40px 10px; border: 1.5px dashed var(--border); border-radius: var(--radius-m); }
.field-row {
    display: flex; align-items: center; gap: 10px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-s); padding: 12px 14px; cursor: pointer;
}
.field-row:hover { border-color: var(--accent); }
.field-row.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.field-row.dragging { opacity: .4; }
.field-row-main { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.drag-handle { color: var(--muted); cursor: grab; font-size: 13px; letter-spacing: -2px; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; line-height: 1; padding: 4px; }
.icon-btn:hover { color: var(--danger); }
.conditional-block { margin-top: 4px; }

.modal-backdrop {
    position: fixed; inset: 0; background: rgba(20,24,20,.45);
    display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal { background: var(--surface); border-radius: var(--radius-m); padding: 24px; width: 100%; max-width: 440px; max-height: 86vh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; }
.modal input[type=color] { width: 60px; height: 36px; padding: 2px; cursor: pointer; }
.modal textarea[readonly], .modal input[readonly] { background: var(--bg); cursor: pointer; font-family: monospace; font-size: 12px; }
.social-share-row { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.social-btn {
    width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border);
    background: var(--surface); font-weight: 700; font-size: 15px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; color: var(--brand);
}
.social-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- public form ---------- */
.public-form-page { background: var(--bg); }
.public-form-wrap { max-width: 620px; margin: 0 auto; padding: 40px 18px 80px; }
.preview-banner { background: var(--draft); color: #fff; text-align: center; padding: 8px; font-size: 13px; }
.public-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 32px; border-top: 5px solid var(--form-accent, var(--accent)); }
.form-card-plain { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 40px 32px; }
.field-block { margin-bottom: 20px; }
.form-logo { max-height: 48px; margin-bottom: 14px; display: block; }
.field-label { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.field-help { margin: 0 0 6px; }
.req { color: var(--danger); }
.section-heading { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 18px; font-size: 17px; }
.choice-group { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.choice { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 14px; }
.choice input { width: auto; }
.rating-group { display: flex; gap: 8px; margin-top: 6px; }
.rating-choice { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border: 1px solid var(--border); border-radius: var(--radius-s); font-weight: 500; cursor: pointer; }
.rating-choice input { position: absolute; opacity: 0; }
.rating-choice:has(input:checked) { background: var(--form-accent, var(--accent)); border-color: var(--form-accent, var(--accent)); color: #fff; }
.signature-pad-wrap { border: 1px dashed var(--border); border-radius: var(--radius-s); padding: 8px; background: var(--bg); }
.signature-pad { width: 100%; height: 160px; background: #fff; border-radius: var(--radius-s); touch-action: none; cursor: crosshair; }
.signature-clear { margin-top: 8px; }
.payment-amount { font-size: 18px; font-weight: 600; color: var(--brand); }
.public-form button[type=submit] { margin-top: 8px; background: var(--form-accent, var(--accent)); border-color: var(--form-accent, var(--accent)); }
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.privacy-footer { text-align: center; margin-top: 12px; font-size: 12px; }
.powered-by-footer { text-align: center; margin-top: 14px; font-size: 12px; }
.powered-by-footer a { color: var(--muted); text-decoration: none; }
.powered-by-footer a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
    .builder-body { grid-template-columns: 1fr; }
    .palette, .properties { position: relative; top: 0; height: auto; border: none; border-bottom: 1px solid var(--border); }
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; align-items: center; flex-wrap: wrap; }
    .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
    .sidebar-footer { display: flex; align-items: center; gap: 14px; border: none; margin: 0 0 0 auto; padding: 0; }
    .main-content { padding: 20px; }
}
@media (max-width: 480px) {
    .public-form, .form-card-plain { padding: 22px 18px; }
    .auth-card { padding: 26px; }
}
