@import url('open-iconic/font/css/open-iconic-bootstrap.min.css');
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Suppress default Blazor error bar (replaced by custom reconnect overlay) ── */
#blazor-error-ui {
    display: none !important;
}

/* ── Blazor Reconnect Overlay ───────────────────────────────────────────── */
#reconnect-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}
#reconnect-box {
    background: #fff;
    border-radius: 0.75rem;
    padding: 2rem 2.5rem;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    max-width: 340px;
    width: 90%;
}

/* Blazor sets these classes on <body> automatically */
body.components-reconnect-show    #reconnect-overlay { display: flex; }
body.components-reconnect-failed  #reconnect-overlay { display: flex; }
body.components-reconnect-rejected #reconnect-overlay { display: flex; }

/* On failed/rejected — hide spinner, show reload button, update message */
body.components-reconnect-failed  #reconnect-spinner  { display: none !important; }
body.components-reconnect-rejected #reconnect-spinner { display: none !important; }
body.components-reconnect-failed  #reconnect-reload   { display: inline-block !important; }
body.components-reconnect-rejected #reconnect-reload  { display: inline-block !important; }
body.components-reconnect-failed  #reconnect-message::after  { content: 'Could not reconnect. Please reload the page.'; }
body.components-reconnect-rejected #reconnect-message::after { content: 'Your session has expired. Please reload to sign back in.'; }
body.components-reconnect-failed  #reconnect-message,
body.components-reconnect-rejected #reconnect-message { font-size: 0; } /* hide original text, show ::after */

/* ── HTML Editor ────────────────────────────────────────────────────────── */
.html-editor-wrapper {
    background: #fff;
}
.html-editor-toolbar .btn {
    padding: 0.2rem 0.45rem;
    font-size: 0.85rem;
}
.html-editor-body {
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.6;
}
.html-editor-body:focus {
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.25);
    border-radius: 0 0 0.375rem 0.375rem;
}

/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
    --brand-primary:    #3b6fcf;   /* softer steel blue */
    --brand-secondary:  #2980a8;   /* muted cyan */
    --brand-dark:       #f1f5f9;
    --brand-sidebar:    #ffffff;
    --brand-sidebar-hover: rgba(59,111,207,0.07);
    --brand-sidebar-active: rgba(59,111,207,0.11);
    --brand-active-bar: #3b6fcf;

    --surface:          #f8fafc;
    --surface-card:     #ffffff;
    --border:           #e2e8f0;
    --text-primary:     #0f172a;
    --text-secondary:   #64748b;
    --text-muted:       #94a3b8;

    --sidebar-width:    260px;
    --topbar-height:    56px;
    --radius:           10px;
    --shadow-sm:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md:        0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.05);
    --shadow-lg:        0 10px 30px rgba(0,0,0,.10);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background-color: var(--surface);
    margin: 0;
    padding: 0;
    height: 100%;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { font-weight: 600; letter-spacing: -0.01em; }
h1:focus { outline: none; }

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

/* ============================================================
   PAGE SHELL
   ============================================================ */
.page {
    display: flex;
    flex-direction: row;
    min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    background: var(--brand-sidebar);
    width: var(--sidebar-width);
    min-height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: 1px 0 0 var(--border), 4px 0 16px rgba(0,0,0,.04);
}

.nav-version {
    margin-top: auto;
    padding: 0.75rem 1rem;
    font-size: 0.72rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    white-space: nowrap;
}

/* Sidebar top brand row */
.top-row {
    background: var(--brand-dark);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.navbar-brand {
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.02em;
    text-decoration: none;
    display: flex;
    align-items: center;
}
.navbar-brand:hover { color: var(--brand-primary); text-decoration: none; }

.navbar-logo {
    height: 30px;
    width: auto;
    max-width: 130px;
    object-fit: contain;
}

.navbar-toggler {
    appearance: none;
    cursor: pointer;
    width: 2.5rem;
    height: 2.5rem;
    color: var(--text-secondary);
    position: absolute;
    top: 0.6rem;
    right: 0.75rem;
    border: 1px solid var(--border);
    background: none;
    border-radius: 6px;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Nav items */
.nav-scrollable {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0 1rem;
}

.nav-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-muted);
    padding: 1rem 1.25rem 0.35rem;
}

.nav-item {
    padding: 0 0.75rem 0.1rem;
}

.nav-item a.nav-link,
.nav-item button.nav-link {
    color: var(--text-secondary) !important;
    border-radius: 8px;
    height: 2.6rem;
    display: flex;
    align-items: center;
    padding: 0 0.85rem;
    font-size: 0.875rem;
    font-weight: 450;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    gap: 0.6rem;
    border: none;
    width: 100%;
    background: none;
    text-align: left;
    cursor: pointer;
}

.nav-item a.nav-link i,
.nav-item button.nav-link i { font-size: 1rem; opacity: 0.65; }

.nav-item a.nav-link:hover,
.nav-item button.nav-link:hover {
    background: var(--brand-sidebar-hover);
    color: var(--brand-primary) !important;
}
.nav-item a.nav-link:hover i,
.nav-item button.nav-link:hover i { opacity: 1; }

.nav-item a.nav-link.active {
    background: var(--brand-sidebar-active);
    color: var(--brand-primary) !important;
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--brand-active-bar);
}
.nav-item a.nav-link.active i { opacity: 1; }

.nav-item .text-muted {
    color: var(--text-muted) !important;
    font-size: 0.8rem;
    padding: 0.5rem 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-item hr { border-color: var(--border); margin: 0.5rem 0; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.page > main {
    flex: 1;
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.content {
    padding: 1.75rem 2rem;
    max-width: 1400px;
}

/* ============================================================
   BOOTSTRAP OVERRIDES â€” cards, buttons, forms
   ============================================================ */

/* Cards */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    background: var(--surface-card);
}
.card-header {
    background: var(--surface-card);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
    /* Top corners always rounded; bottom corners rounded only when collapsed (no body follows) */
    border-radius: var(--radius) var(--radius) var(--radius) var(--radius);
}
/* When a card-body follows the header, flatten the header's bottom corners */
.card-header:has(+ .card-body),
.card-header:has(+ div > .card-body) {
    border-radius: var(--radius) var(--radius) 0 0;
}
.card-header h5 { margin: 0; font-size: 0.95rem; font-weight: 600; }
.card:hover { box-shadow: var(--shadow-md); transition: box-shadow 0.2s; }

/* ── Editor tab bar ──────────────────────────────────────────────────────── */
/* All tab corners square at the bottom, flush against the panel */
.nav-tabs .nav-link,
.nav-tabs .nav-link:hover,
.nav-tabs .nav-link.active,
.nav-tabs .nav-link:focus {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
}
.nav-tabs .nav-link.active {
    background: var(--surface);
}
/* Remove the default left margin/padding Bootstrap puts on the first tab item */
.nav-tabs .nav-item:first-child {
    margin-left: 0;
    padding-left: 0;
}
.nav-tabs {
    padding-left: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 0.5rem 0.5rem 0;
    background: #ffffff;
}

/* ── Sticky save bar ─────────────────────────────────────────────────────── */
.editor-save-bar {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    z-index: 1001;
    background: var(--surface-card);
    border-top: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    border-radius: 0;
    box-shadow: 0 -2px 8px rgba(0,0,0,.08);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Buttons */
.btn { border-radius: 8px; font-weight: 500; font-size: 0.875rem; letter-spacing: 0.01em; transition: all 0.15s; }
.btn-sm { border-radius: 6px; }
.btn-lg { border-radius: 10px; }

/* Primary — softer steel blue */
.btn-primary { background: #3b6fcf; border-color: #3b6fcf; }
.btn-primary:hover { background: #2f5bb8; border-color: #2f5bb8; box-shadow: 0 3px 10px rgba(59,111,207,.25); }

.btn-outline-primary { color: #3b6fcf; border-color: #3b6fcf; }
.btn-outline-primary:hover { background: #3b6fcf; border-color: #3b6fcf; box-shadow: 0 3px 10px rgba(59,111,207,.18); }

/* Success — muted teal-green */
.btn-success { background: #2e7d64; border-color: #2e7d64; }
.btn-success:hover { background: #266858; border-color: #266858; box-shadow: 0 3px 10px rgba(46,125,100,.25); }

.btn-outline-success { color: #2e7d64; border-color: #2e7d64; }
.btn-outline-success:hover { background: #2e7d64; border-color: #2e7d64; }

/* Info — muted cyan-blue */
.btn-info { background: #2980a8; border-color: #2980a8; color: #fff; }
.btn-info:hover { background: #236d90; border-color: #236d90; color: #fff; box-shadow: 0 3px 10px rgba(41,128,168,.25); }

.btn-outline-info { color: #2980a8; border-color: #2980a8; }
.btn-outline-info:hover { background: #2980a8; border-color: #2980a8; color: #fff; }

/* Danger — softer red, less alarming */
.btn-danger { background: #c0392b; border-color: #c0392b; }
.btn-danger:hover { background: #a93226; border-color: #a93226; box-shadow: 0 3px 10px rgba(192,57,43,.25); }

.btn-outline-danger { color: #c0392b; border-color: #c0392b; }
.btn-outline-danger:hover { background: #c0392b; border-color: #c0392b; }

/* Secondary — neutral grey */
.btn-outline-secondary { color: var(--text-secondary); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--surface); color: var(--text-primary); border-color: #94a3b8; }

.btn:focus, .btn:active:focus,
.form-control:focus, .form-check-input:focus, .form-select:focus {
    box-shadow: 0 0 0 3px rgba(59,111,207,.18);
    outline: none;
}

/* Forms */
.form-control, .form-select {
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus { border-color: var(--brand-primary); }
.form-label { font-weight: 500; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.35rem; }

/* Badges */
.badge { border-radius: 6px; font-weight: 600; font-size: 0.7rem; letter-spacing: 0.03em; }

/* Alerts */
.alert { border-radius: var(--radius); border: none; font-size: 0.875rem; }
.alert-info    { background: #eff6ff; color: #1e40af; }
.alert-success { background: #ecfdf5; color: #065f46; }
.alert-warning { background: #fffbeb; color: #92400e; }
.alert-danger  { background: #fef2f2; color: #991b1b; }

/* Tables */
.table { font-size: 0.875rem; }
.table th { font-weight: 600; color: var(--text-secondary); font-size: 0.75rem; text-transform: uppercase; letter-spacing: .05em; border-bottom: 2px solid var(--border); }
.table-light th { background: var(--surface); }
.table-hover tbody tr:hover td { background: #f8fafc; }

/* Breadcrumbs */
.breadcrumb { font-size: 0.8rem; }
.breadcrumb-item.active { color: var(--text-muted); }

/* Spinners */
.spinner-border { border-width: 2px; }

/* ============================================================
   PAGE HEADER PATTERN (used in list/editor pages)
   ============================================================ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
}
.page-header h2 { font-size: 1.4rem; margin: 0 0 0.15rem; }
.page-header p  { font-size: 0.85rem; color: var(--text-muted); margin: 0; }

/* ============================================================
   VALIDATION
   ============================================================ */
.valid.modified:not([type=checkbox]) { outline: 1px solid #059669; }
.invalid { outline: 1px solid #dc2626; }
.validation-message { color: #dc2626; font-size: 0.8rem; margin-top: 0.2rem; }

/* ============================================================
   BLAZOR ERROR UI
   ============================================================ */
#blazor-error-ui {
    background: #fffbeb;
    border-top: 2px solid #f59e0b;
    bottom: 0; left: 0; right: 0;
    padding: 0.75rem 1.5rem;
    position: fixed;
    display: none;
    z-index: 2000;
    font-size: 0.875rem;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 1rem; top: 0.75rem; font-size: 1.25rem; }
.blazor-error-boundary {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: var(--radius);
    padding: 1rem 1rem 1rem 3.5rem;
    color: #991b1b;
}
.blazor-error-boundary::after { content: "An error has occurred." }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 767.98px) {
    .page { flex-direction: column; }
    .sidebar { width: 100%; min-height: auto; position: relative; }
    .page > main { margin-left: 0; width: 100%; }
    .navbar-toggler { display: flex; }
    .nav-collapsed { display: none; }
    .content { padding: 1rem; }
}
@media (min-width: 768px) {
    .navbar-toggler { display: none; }
    .nav-collapsed { display: flex !important; flex-direction: column; }
}

/* ============================================================
   DRAG & DROP â€” question editor
   ============================================================ */
.question-card { transition: box-shadow 0.2s, transform 0.15s; }
.question-card:hover { box-shadow: var(--shadow-md); }
.question-card[draggable="true"]:active { opacity: 0.55; cursor: grabbing; transform: scale(0.99); }
.drag-handle { color: var(--text-muted); cursor: grab; display: flex; align-items: center; }
.drag-handle:hover { color: var(--text-secondary); }
.drag-handle:active { cursor: grabbing; }
.question-card.drag-over { border: 2px dashed var(--brand-primary); background: #eff6ff; }

/* ============================================================
   SURVEY QUESTION TYPES
   ============================================================ */

/* Rating */
.rating-container { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn-rating {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 8px 14px;
    border: 1.5px solid var(--border);
    background: #fff; color: var(--text-secondary);
    border-radius: 8px; transition: all 0.2s; font-weight: 500;
}
.btn-rating:hover { border-color: #f59e0b; background: #fffbeb; color: #92400e; transform: translateY(-2px); }
.btn-rating.selected { border-color: #f59e0b; background: #f59e0b; color: #fff; }
.btn-rating i { font-size: 1.1rem; }

/* Slider */
.slider-container { padding: 10px 0; }
.slider-value { text-align: center; margin-top: 10px; }
.slider-value .badge { font-size: 1rem; padding: 8px 16px; }
input[type="range"] {
    width: 100%; height: 6px; border-radius: 5px;
    background: var(--border); outline: none; -webkit-appearance: none;
    accent-color: var(--brand-primary);
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--brand-primary); cursor: pointer; transition: all 0.2s;
}
input[type="range"]::-webkit-slider-thumb:hover { background: #1d4ed8; transform: scale(1.2); }
input[type="range"]::-moz-range-thumb {
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--brand-primary); cursor: pointer; border: none;
}

/* Yes/No Toggle */
.yes-no-toggle .btn-group { max-width: 400px; box-shadow: var(--shadow-sm); border-radius: 8px; overflow: hidden; }
.yes-no-toggle .btn { flex: 1; padding: 10px 24px; font-weight: 500; border: none; transition: all 0.25s; }
.yes-no-toggle .btn:not(.btn-success):not(.btn-danger) { background: var(--surface); color: var(--text-secondary); }
.yes-no-toggle .btn:hover:not(.btn-success):not(.btn-danger) { background: var(--border); }
.yes-no-toggle .btn-success, .yes-no-toggle .btn-danger { box-shadow: 0 4px 8px rgba(0,0,0,.12); }

/* ============================================================
   PUBLIC FORM LAYOUT
   ============================================================ */
.public-form-page { min-height: 100vh; display: flex; flex-direction: column; background: var(--surface); }
.public-form-header { background: #fff; border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.form-logo { height: 40px; width: auto; max-width: 150px; object-fit: contain; }
.brand-name { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.public-form-main { flex: 1; padding: 2rem 0; }
.public-form-footer { background: transparent; margin-top: auto; }

/* ── Powered by MemForms branding badge ───────────────────────────────── */
.memforms-branding { text-align: center; padding: 0.75rem 0 1rem; }
.memforms-branding-link {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.3rem 0.9rem;
    border-radius: 999px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: #64748b;
    font-size: 0.72rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.memforms-branding-link:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
    color: #334155;
    text-decoration: none;
}

/* Public form intro */
.form-intro {
    background: #fff; border-radius: var(--radius);
    padding: 2rem; margin-bottom: 2rem; box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--brand-primary);
}
.form-intro h1 { color: var(--text-primary); margin-bottom: 0.75rem; font-size: 1.75rem; }
.form-intro-content { color: var(--text-secondary); line-height: 1.7; }
.form-intro-content a { color: var(--brand-primary); text-decoration: underline; }
.form-intro-content p:last-child { margin-bottom: 0; }


h1:focus {
    outline: none;
}
