/* EaseForm Builder — admin + auth UI foundation. Phase 1.
   Card-based, responsive (desktop / tablet / mobile), accessible focus states. */

:root {
    --ef-bg: #eef1f6;
    --ef-surface: #ffffff;
    --ef-surface-2: #f7f9fc;
    --ef-border: #e2e7ef;
    --ef-text: #1f2733;
    --ef-muted: #6b7688;
    --ef-primary: #3559e0;
    --ef-primary-600: #2c48b8;
    --ef-primary-050: #eaf0ff;
    --ef-success: #1f9d68;
    --ef-success-bg: #e6f6ee;
    --ef-error: #c0392b;
    --ef-error-bg: #fdecea;
    --ef-info-bg: #eaf2fb;
    --ef-warn-bg: #fff6e5;
    --ef-radius: 12px;
    --ef-radius-sm: 8px;
    --ef-shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 8px 24px rgba(20, 30, 50, .06);
    --ef-sidebar-w: 244px;
    --ef-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--ef-font);
    color: var(--ef-text);
    background: var(--ef-bg);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--ef-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
    outline: 3px solid var(--ef-primary-050);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---------- Buttons ---------- */
.ef-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .62rem 1.05rem;
    border: 1px solid transparent;
    border-radius: var(--ef-radius-sm);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    background: var(--ef-surface-2);
    color: var(--ef-text);
    transition: background .15s, box-shadow .15s, transform .05s;
    text-decoration: none;
}
.ef-btn:hover { text-decoration: none; }
.ef-btn:active { transform: translateY(1px); }
.ef-btn-primary { background: var(--ef-primary); color: #fff; }
.ef-btn-primary:hover { background: var(--ef-primary-600); }
.ef-btn-ghost { background: transparent; border-color: var(--ef-border); color: var(--ef-text); }
.ef-btn-ghost:hover { background: var(--ef-surface-2); }
.ef-btn-block { width: 100%; }
.ef-btn.is-disabled,
.ef-quick.is-disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }

/* ---------- Cards / alerts ---------- */
.ef-card {
    background: var(--ef-surface);
    border: 1px solid var(--ef-border);
    border-radius: var(--ef-radius);
    box-shadow: var(--ef-shadow);
    padding: 1.25rem 1.35rem;
    margin-bottom: 1.15rem;
}
.ef-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.ef-card-title { font-size: 1.02rem; margin: 0; }
.ef-card-sub { color: var(--ef-muted); margin: .15rem 0 1.1rem; }

.ef-alert { padding: .75rem .95rem; border-radius: var(--ef-radius-sm); margin-bottom: 1rem; font-size: .95rem; }
.ef-alert-error { background: var(--ef-error-bg); color: var(--ef-error); border: 1px solid #f3c9c4; }
.ef-alert-success { background: var(--ef-success-bg); color: var(--ef-success); border: 1px solid #bfe6d1; }
.ef-alert-info { background: var(--ef-info-bg); color: #2c5a92; border: 1px solid #cfe0f2; }
.ef-alert-warn { background: var(--ef-warn-bg); color: #8a5a00; border: 1px solid #f2dfb0; }

/* ---------- Forms ---------- */
.ef-field { margin-bottom: 1rem; }
.ef-field label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .92rem; }
.ef-field input[type=text],
.ef-field input[type=email],
.ef-field input[type=password],
.ef-field input[type=number],
.ef-field select {
    width: 100%;
    padding: .62rem .7rem;
    border: 1px solid var(--ef-border);
    border-radius: var(--ef-radius-sm);
    font: inherit;
    background: #fff;
    color: var(--ef-text);
}
.ef-field input:focus, .ef-field select:focus { border-color: var(--ef-primary); outline: none; box-shadow: 0 0 0 3px var(--ef-primary-050); }
.ef-field .ef-hint { color: var(--ef-muted); font-size: .82rem; margin-top: .3rem; }
.ef-field.has-error input { border-color: var(--ef-error); }
.ef-field-error { color: var(--ef-error); font-size: .82rem; margin-top: .3rem; }
.ef-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ---------- Logo ---------- */
.ef-logo-mark {
    display: inline-grid; place-items: center;
    width: 34px; height: 34px; border-radius: 9px;
    background: var(--ef-primary); color: #fff; font-weight: 800; letter-spacing: .5px;
}
.ef-logo-text { font-weight: 600; }
.ef-logo-text strong { color: var(--ef-primary); }

/* ---------- Auth ---------- */
.ef-auth-body { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem;
    background: radial-gradient(1200px 500px at 50% -10%, #dfe7fb 0%, var(--ef-bg) 55%); }
.ef-auth-shell { width: 100%; max-width: 400px; }
.ef-auth-brand { display: flex; align-items: center; gap: .6rem; justify-content: center; margin-bottom: 1.1rem; font-size: 1.1rem; }
.ef-auth-card { padding: 1.6rem 1.6rem 1.7rem; }
.ef-auth-foot { text-align: center; color: var(--ef-muted); font-size: .82rem; margin-top: 1rem; }

/* ---------- App shell ---------- */
.ef-shell { display: flex; min-height: 100vh; }
.ef-sidebar {
    width: var(--ef-sidebar-w); flex: 0 0 var(--ef-sidebar-w);
    background: #12182a; color: #c7d0e0;
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}
.ef-sidebar-brand { display: flex; align-items: center; gap: .6rem; padding: 1.05rem 1.1rem; color: #fff; border-bottom: 1px solid rgba(255,255,255,.07); }
.ef-sidebar-brand .ef-logo-text, .ef-sidebar-brand .ef-logo-text strong { color: #fff; }
.ef-nav { padding: .7rem .6rem; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.ef-nav-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: .6rem .75rem; border-radius: 8px; color: #c7d0e0; font-weight: 500;
}
.ef-nav-item:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.ef-nav-item.is-active { background: var(--ef-primary); color: #fff; }
.ef-nav-item.is-disabled { opacity: .55; cursor: not-allowed; }
.ef-nav-item.is-disabled:hover { background: transparent; color: #c7d0e0; }
.ef-badge-soon { font-size: .62rem; text-transform: uppercase; letter-spacing: .5px; background: rgba(255,255,255,.12); padding: .1rem .35rem; border-radius: 20px; }
.ef-sidebar-foot { padding: .8rem 1.1rem; font-size: .78rem; color: #7c88a1; border-top: 1px solid rgba(255,255,255,.07); }

.ef-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ef-topbar {
    display: flex; align-items: center; gap: 1rem;
    padding: .75rem 1.3rem; background: var(--ef-surface);
    border-bottom: 1px solid var(--ef-border); position: sticky; top: 0; z-index: 20;
}
.ef-topbar-title { font-size: 1.05rem; margin: 0; flex: 1; }
.ef-topbar-right { display: flex; align-items: center; gap: 1rem; }
.ef-user { display: flex; align-items: center; gap: .55rem; }
.ef-avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--ef-primary-050); color: var(--ef-primary); font-weight: 700; }
.ef-user-name { font-weight: 600; font-size: .92rem; }
.ef-inline { display: inline; margin: 0; }
.ef-icon-btn { display: none; background: none; border: 1px solid var(--ef-border); border-radius: 8px; padding: .35rem .55rem; font-size: 1.1rem; cursor: pointer; }

.ef-content { padding: 1.5rem 1.6rem; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ---------- Page head ---------- */
.ef-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.ef-page-title { margin: 0; font-size: 1.4rem; }
.ef-page-sub { margin: .2rem 0 0; color: var(--ef-muted); }

/* ---------- Grid ---------- */
.ef-grid-main { display: grid; grid-template-columns: minmax(0,1fr) 320px; gap: 1.2rem; align-items: start; }
.ef-col-side { position: relative; }
.ef-sticky { position: sticky; top: 84px; }

/* ---------- Stats ---------- */
.ef-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.15rem; }
.ef-stat-card { background: var(--ef-surface); border: 1px solid var(--ef-border); border-radius: var(--ef-radius); box-shadow: var(--ef-shadow); padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .2rem; }
.ef-stat-label { color: var(--ef-muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .4px; }
.ef-stat-value { font-size: 1.7rem; font-weight: 700; }
.ef-stat-note { color: var(--ef-muted); font-size: .8rem; }

/* ---------- Quick actions ---------- */
.ef-quick-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.ef-quick { padding: .6rem .9rem; border: 1px dashed var(--ef-border); border-radius: var(--ef-radius-sm); font-weight: 600; background: var(--ef-surface-2); }

/* ---------- Table ---------- */
.ef-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.ef-table th, .ef-table td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--ef-border); }
.ef-table th { color: var(--ef-muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .3px; }
.ef-tag { background: var(--ef-primary-050); color: var(--ef-primary-600); padding: .12rem .5rem; border-radius: 20px; font-size: .8rem; font-weight: 600; }

/* ---------- Status list / chips ---------- */
.ef-status-list { list-style: none; margin: 0; padding: 0; }
.ef-status-list li { display: flex; align-items: center; justify-content: space-between; padding: .5rem 0; border-bottom: 1px solid var(--ef-border); font-size: .92rem; }
.ef-status-list li:last-child { border-bottom: 0; }
.ef-pill { padding: .12rem .55rem; border-radius: 20px; font-size: .78rem; font-weight: 700; }
.ef-pill-ok { background: var(--ef-success-bg); color: var(--ef-success); }
.ef-pill-warn { background: var(--ef-warn-bg, #fff6e5); color: #8a5a00; }
.ef-pill-muted { background: var(--ef-surface-2); color: var(--ef-muted); }
.ef-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.ef-chip { background: var(--ef-surface-2); border: 1px solid var(--ef-border); border-radius: 20px; padding: .2rem .6rem; font-size: .82rem; font-weight: 600; }

/* ---------- Utilities ---------- */
.ef-muted { color: var(--ef-muted); }
.ef-mt { margin-top: .8rem; }
.ef-mb { margin-bottom: .6rem; }
.ef-alert-info { background: #eaf2fb; color: #2c5a92; border: 1px solid #cfe0f2; padding: .75rem .95rem; border-radius: 8px; margin-bottom: 1rem; font-size: .95rem; }

/* ---------- Card variants ---------- */
.ef-card-narrow { max-width: 640px; }
.ef-empty-state { text-align: center; padding: 2.4rem 1.5rem; }
.ef-empty-state .ef-btn { margin-top: .8rem; }
.ef-actions-row { display: flex; justify-content: flex-end; gap: .7rem; margin-top: .4rem; }
.ef-btn-sm { padding: .38rem .7rem; font-size: .85rem; }
.ef-btn-danger { color: var(--ef-error); border-color: #f3c9c4; }
.ef-btn-danger:hover { background: var(--ef-error-bg); }

/* ---------- Filter bar ---------- */
.ef-filter-bar { display: flex; flex-wrap: wrap; align-items: end; gap: 1rem; }
.ef-field-grow { flex: 1; min-width: 200px; margin-bottom: 0; }
.ef-field-btn { margin-bottom: 0; }
.ef-filter-bar .ef-field { margin-bottom: 0; min-width: 160px; }

/* ---------- Forms table ---------- */
.ef-table-card { overflow-x: auto; }
.ef-table-forms { min-width: 720px; }
.ef-form-name { font-weight: 600; }
.ef-form-slug { font-size: .82rem; }
.ef-table-actions { white-space: nowrap; display: flex; gap: .4rem; flex-wrap: wrap; }
.ef-table-actions-head { white-space: nowrap; }

/* ---------- Pagination ---------- */
.ef-pagination { display: flex; gap: .35rem; margin: 1rem 0; flex-wrap: wrap; }
.ef-page-link {
    display: inline-flex; align-items: center; justify-content: center; min-width: 32px; height: 32px;
    border: 1px solid var(--ef-border); border-radius: 8px; color: var(--ef-text); font-size: .88rem; font-weight: 600;
}
.ef-page-link:hover { background: var(--ef-surface-2); text-decoration: none; }
.ef-page-link.is-active { background: var(--ef-primary); border-color: var(--ef-primary); color: #fff; }

/* ---------- Submission detail ---------- */
.ef-value-list { margin: 0; }
.ef-value-list dt { font-weight: 600; font-size: .85rem; color: var(--ef-muted); margin-top: .8rem; }
.ef-value-list dt:first-child { margin-top: 0; }
.ef-value-list dd { margin: .2rem 0 0; font-size: .95rem; word-break: break-word; }
.ef-ua { word-break: break-word; max-width: 220px; display: inline-block; }
.ef-note-list { list-style: none; margin: 0; padding: 0; }
.ef-note-list li { border-top: 1px solid var(--ef-border); padding: .7rem 0; }
.ef-note-list li:first-child { border-top: 0; }
.ef-note-body { font-size: .92rem; white-space: pre-wrap; }
.ef-note-meta { font-size: .78rem; margin-top: .3rem; }

/* =====================================================================
   Builder foundation
   ===================================================================== */
.ef-builder { display: grid; grid-template-columns: 260px minmax(0,1fr) 300px; gap: 1.1rem; align-items: start; }
.ef-builder-left, .ef-builder-right { display: flex; flex-direction: column; gap: 1rem; }
.ef-builder-panel {
    background: var(--ef-surface); border: 1px solid var(--ef-border); border-radius: var(--ef-radius);
    box-shadow: var(--ef-shadow); padding: 1.1rem 1.15rem;
}
.ef-builder-panel-grow { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.ef-builder-panel-title { margin: 0 0 .5rem; font-size: .98rem; }
.ef-builder-hint { margin: 0 0 .7rem; font-size: .82rem; }

.ef-palette { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.ef-palette-item {
    padding: .55rem .5rem; border: 1px dashed var(--ef-border); border-radius: 8px;
    background: var(--ef-surface-2); font: inherit; font-weight: 600; font-size: .85rem; cursor: pointer; text-align: center;
}
.ef-palette-item:hover { border-color: var(--ef-primary); color: var(--ef-primary-600); }

.ef-structure-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; max-height: 420px; }
.ef-structure-item {
    display: flex; align-items: center; justify-content: space-between; gap: .4rem;
    border-radius: 8px; padding: .1rem .1rem .1rem .2rem; margin-bottom: .2rem;
}
.ef-structure-item.is-active { background: var(--ef-primary-050); }
.ef-structure-label {
    flex: 1; text-align: left; background: none; border: none; font: inherit; padding: .5rem .3rem;
    cursor: pointer; color: var(--ef-text); border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ef-structure-item.is-active .ef-structure-label { color: var(--ef-primary-600); font-weight: 600; }
.ef-structure-controls { display: flex; gap: 2px; flex-shrink: 0; }
.ef-icon-mini {
    width: 24px; height: 24px; border: none; background: transparent; border-radius: 6px;
    cursor: pointer; color: var(--ef-muted); font-size: .9rem; line-height: 1;
}
.ef-icon-mini:hover { background: var(--ef-surface-2); color: var(--ef-text); }
.ef-structure-empty { font-size: .85rem; margin: .3rem 0 0; }

.ef-builder-canvas { min-width: 0; }
.ef-canvas-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: .8rem; }
.ef-canvas-status { color: var(--ef-muted); font-size: .85rem; }
.ef-canvas-status.is-dirty { color: #8a5a00; font-weight: 600; }
.ef-canvas-surface {
    background: var(--ef-surface); border: 1px solid var(--ef-border); border-radius: var(--ef-radius);
    box-shadow: var(--ef-shadow); padding: 1.3rem; display: flex; flex-wrap: wrap; gap: 1rem; min-height: 320px; align-content: flex-start;
}
.ef-canvas-empty { color: var(--ef-muted); text-align: center; width: 100%; padding: 3rem 1rem; }
.ef-canvas-block {
    border: 1px solid transparent; border-radius: 8px; padding: .7rem .8rem; cursor: pointer;
    width: 100%; transition: border-color .1s, background .1s;
}
.ef-canvas-block:hover { background: var(--ef-surface-2); }
.ef-canvas-block.is-selected { border-color: var(--ef-primary); background: var(--ef-primary-050); }
.ef-canvas-block.ef-width-half { width: calc(50% - .5rem); }
.ef-canvas-block.ef-width-third { width: calc(33.333% - .667rem); }
.ef-canvas-block.ef-width-two-third { width: calc(66.666% - .334rem); }
.ef-canvas-block.ef-width-quarter { width: calc(25% - .75rem); }
.ef-canvas-label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.ef-canvas-help { color: var(--ef-muted); font-size: .8rem; margin-top: .3rem; }
.ef-canvas-heading { font-size: 1.15rem; font-weight: 700; }
.ef-canvas-hidden { color: var(--ef-muted); font-size: .85rem; font-style: italic; }
.ef-canvas-block input, .ef-canvas-block textarea, .ef-canvas-block select {
    width: 100%; padding: .5rem .6rem; border: 1px solid var(--ef-border); border-radius: 6px;
    background: #fbfcfe; font: inherit; color: var(--ef-muted); pointer-events: none;
}
.ef-canvas-choices { display: flex; flex-direction: column; gap: .3rem; }
.ef-canvas-choice { font-size: .88rem; color: var(--ef-muted); display: flex; align-items: center; gap: .4rem; pointer-events: none; }

.ef-field-toggle { display: flex; align-items: center; }
.ef-toggle-label { display: flex; align-items: center; gap: .5rem; font-weight: 600; font-size: .92rem; cursor: pointer; }
.ef-builder-danger { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--ef-border); }

/* ---------- Admin preview render ---------- */
.ef-preview-card { max-width: 780px; }
.ef-preview-form { display: flex; flex-wrap: wrap; gap: 1.1rem; }
.ef-preview-block { width: 100%; }
.ef-preview-block.ef-width-half { width: calc(50% - .55rem); }
.ef-preview-block.ef-width-third { width: calc(33.333% - .734rem); }
.ef-preview-block.ef-width-two-third { width: calc(66.666% - .367rem); }
.ef-preview-block.ef-width-quarter { width: calc(25% - .825rem); }
.ef-preview-label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .92rem; }
.ef-preview-heading { margin: 0; }
.ef-preview-choice { display: flex; align-items: center; gap: .4rem; font-size: .92rem; margin-bottom: .3rem; }
.ef-req { color: var(--ef-error); }
.ef-preview-form input, .ef-preview-form select, .ef-preview-form textarea {
    width: 100%; padding: .6rem .7rem; border: 1px solid var(--ef-border); border-radius: 8px; font: inherit;
}

/* ---------- Error page ---------- */
.ef-center-page { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.ef-error-card { background: var(--ef-surface); border: 1px solid var(--ef-border); border-radius: var(--ef-radius); box-shadow: var(--ef-shadow); padding: 2.2rem; text-align: center; max-width: 420px; }
.ef-error-code { font-size: 3rem; font-weight: 800; color: var(--ef-primary); }
.ef-error-message { color: var(--ef-muted); margin: .3rem 0 1.4rem; }

/* ---------- Responsive ---------- */
@media (max-width: 992px) {
    .ef-grid-main { grid-template-columns: 1fr; }
    .ef-stats { grid-template-columns: repeat(2, 1fr); }
    .ef-sticky { position: static; }
    .ef-builder { grid-template-columns: 220px minmax(0,1fr) 260px; }
}
@media (max-width: 900px) {
    .ef-builder { grid-template-columns: 1fr; }
    .ef-builder-left, .ef-builder-right { flex-direction: row; flex-wrap: wrap; }
    .ef-builder-left .ef-builder-panel, .ef-builder-right .ef-builder-panel { flex: 1; min-width: 260px; }
    .ef-structure-list { max-height: 220px; }
}
@media (max-width: 768px) {
    .ef-sidebar {
        position: fixed; z-index: 40; left: 0; top: 0; height: 100vh;
        transform: translateX(-100%); transition: transform .2s ease;
        box-shadow: 0 0 40px rgba(0,0,0,.35);
    }
    .ef-app.ef-nav-open .ef-sidebar { transform: translateX(0); }
    .ef-icon-btn { display: inline-block; }
    .ef-user-name { display: none; }
    .ef-content { padding: 1.1rem; }
    .ef-canvas-block.ef-width-half,
    .ef-canvas-block.ef-width-third,
    .ef-canvas-block.ef-width-two-third,
    .ef-canvas-block.ef-width-quarter,
    .ef-preview-block.ef-width-half,
    .ef-preview-block.ef-width-third,
    .ef-preview-block.ef-width-two-third,
    .ef-preview-block.ef-width-quarter { width: 100%; }
}
@media (max-width: 520px) {
    .ef-stats { grid-template-columns: 1fr; }
    .ef-row { grid-template-columns: 1fr; }
    .ef-page-head { flex-direction: column; align-items: flex-start; }
    .ef-builder-left, .ef-builder-right { flex-direction: column; }
    .ef-palette { grid-template-columns: 1fr 1fr; }
    .ef-table-actions { flex-direction: column; align-items: flex-start; }
}
