/*
 * FORMA4 Imobiliária — Stylesheet principal
 * Design: Dashboard SaaS minimalista moderno
 * Compatível com todos os modernos navegadores
 */

/* ============================================================
   VARIÁVEIS & RESET
   ============================================================ */
:root {
    --primary:        #2563EB;
    --primary-dark:   #1d4ed8;
    --primary-light:  #eff6ff;
    --success:        #10b981;
    --success-light:  #ecfdf5;
    --warning:        #f59e0b;
    --warning-light:  #fffbeb;
    --danger:         #ef4444;
    --danger-light:   #fef2f2;
    --info:           #3b82f6;
    --info-light:     #eff6ff;

    --bg:             #f8fafc;
    --sidebar-bg:     #ffffff;
    --sidebar-hover:  #f1f5f9;
    --sidebar-active: var(--primary);
    --sidebar-width:  240px;

    --white:          #ffffff;
    --body-text:      #334155;
    --muted:          #94a3b8;
    --border:         #e2e8f0;
    --card-shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --card-shadow-hover: 0 4px 12px rgba(0,0,0,.10);

    --radius:         8px;
    --radius-lg:      12px;
    --font:           'Inter', system-ui, -apple-system, sans-serif;
    --topbar-h:       60px;
    --transition:     .18s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    color: var(--body-text);
    background: var(--bg);
}

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

img { max-width: 100%; display: block; }

/* ============================================================
   ADMIN LAYOUT (sidebar + main)
   ============================================================ */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    transition: transform var(--transition);
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 8px rgba(0,0,0,.04);
}

.sidebar-header {
    padding: 20px 16px 14px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand {
    font-size: 16px;
    font-weight: 700;
    color: var(--body-text);
    letter-spacing: .3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.sidebar-logo {
    max-height: 40px;
    max-width: 180px;
    object-fit: contain;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--body-text);
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    margin-bottom: 2px;
    cursor: pointer;
    text-decoration: none;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .65;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--primary);
    text-decoration: none;
}

.nav-item.active {
    background: var(--primary);
    color: #fff;
}

.nav-item.active svg { opacity: 1; }

.sidebar-footer {
    padding: 10px 10px 16px;
    border-top: 1px solid var(--border);
}

.nav-logout { color: var(--muted); }
.nav-logout:hover { background: var(--danger-light); color: var(--danger); }

/* ---- Main content ---- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---- Topbar ---- */
.topbar {
    height: var(--topbar-h);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-title {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--body-text);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--body-text);
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--body-text);
    padding: 4px;
}

.sidebar-toggle svg { width: 22px; height: 22px; }

/* ---- Page body ---- */
.page-body {
    padding: 28px 28px 40px;
    flex: 1;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.card-header {
    padding: 18px 22px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--body-text);
    margin: 0;
}

.card-body {
    padding: 22px;
}

.card-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    background: #fafbfc;
    font-size: 12.5px;
    color: var(--muted);
}

/* ---- Stat cards ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    box-shadow: var(--card-shadow);
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: box-shadow var(--transition);
}

.stat-card:hover { box-shadow: var(--card-shadow-hover); }

.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg { width: 22px; height: 22px; }

.stat-icon.blue   { background: var(--primary-light); color: var(--primary); }
.stat-icon.green  { background: var(--success-light); color: var(--success); }
.stat-icon.yellow { background: var(--warning-light); color: var(--warning); }
.stat-icon.red    { background: var(--danger-light);  color: var(--danger); }

.stat-info {}
.stat-value {
    font-size: 26px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1;
    margin-bottom: 4px;
}
.stat-label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
}

/* ============================================================
   TABELAS
   ============================================================ */
.table-responsive { overflow-x: auto; }

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.data-table thead th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    background: #fafbfc;
    white-space: nowrap;
}

.data-table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--body-text);
    vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover td { background: #f8fafc; }

/* ============================================================
   BADGES & STATUS
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-info    { background: var(--info-light);    color: var(--info); }
.badge-gray    { background: #f1f5f9; color: #64748b; }
.badge-primary { background: var(--primary-light); color: var(--primary); }

/* ============================================================
   BOTÕES
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius);
    font-size: 13.5px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
    white-space: nowrap;
    text-decoration: none;
    line-height: 1;
}

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }

.btn-secondary {
    background: var(--white);
    color: var(--body-text);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); text-decoration: none; }

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.btn-success:hover { background: #059669; text-decoration: none; color: #fff; }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover { background: #dc2626; text-decoration: none; color: #fff; }

.btn-ghost {
    background: transparent;
    color: var(--body-text);
    border-color: transparent;
}
.btn-ghost:hover { background: var(--bg); text-decoration: none; }

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-icon {
    padding: 7px;
    border-radius: var(--radius);
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--body-text);
    cursor: pointer;
    display: inline-flex;
    transition: background var(--transition);
}
.btn-icon:hover { background: var(--border); }
.btn-icon svg { width: 15px; height: 15px; }

/* ============================================================
   FORMULÁRIOS
   ============================================================ */
.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--body-text);
    margin-bottom: 6px;
}

.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
    display: block;
    width: 100%;
    padding: 9px 12px;
    font-size: 13.5px;
    font-family: var(--font);
    color: var(--body-text);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-control:disabled {
    background: var(--bg);
    color: var(--muted);
    cursor: not-allowed;
}

textarea.form-control {
    resize: vertical;
    min-height: 90px;
}

select.form-control { appearance: none; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.form-text {
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 4px;
}

.form-error {
    font-size: 11.5px;
    color: var(--danger);
    margin-top: 4px;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

/* Checkbox & Radio */
.form-check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}

.form-check input {
    margin-top: 3px;
    width: 15px;
    height: 15px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

.form-check label { cursor: pointer; font-size: 13.5px; }

/* Color picker */
input[type="color"].form-control {
    height: 40px;
    padding: 3px 6px;
    cursor: pointer;
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: 13.5px;
    margin: 0 28px 0;
    border: 1px solid transparent;
    position: relative;
}

.alert + .page-body { padding-top: 0; }
.alert { margin: 16px 28px; }

.alert-success { background: var(--success-light); color: #065f46; border-color: #a7f3d0; }
.alert-error   { background: var(--danger-light);  color: #991b1b; border-color: #fca5a5; }
.alert-warning { background: var(--warning-light); color: #92400e; border-color: #fcd34d; }
.alert-info    { background: var(--info-light);    color: #1e40af; border-color: #bfdbfe; }

.alert-close {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    opacity: .6;
    line-height: 1;
    align-self: center;
    padding: 0 2px;
}
.alert-close:hover { opacity: 1; }

/* ============================================================
   PAGE HEADERS
   ============================================================ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}

.page-header-left h2 {
    font-size: 20px;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.page-header-left p {
    font-size: 12.5px;
    color: var(--muted);
    margin: 3px 0 0;
}

/* ============================================================
   FORM BUILDER
   ============================================================ */
.builder-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 22px;
    align-items: start;
}

.fields-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 80px;
}

.field-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: box-shadow var(--transition);
    cursor: grab;
}

.field-card:hover { box-shadow: var(--card-shadow-hover); border-color: var(--primary); }

.field-card-drag {
    color: var(--muted);
    cursor: grab;
    flex-shrink: 0;
}

.field-card-info { flex: 1; min-width: 0; }

.field-card-label {
    font-weight: 600;
    font-size: 13.5px;
    color: var(--body-text);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.field-card-meta {
    font-size: 11.5px;
    color: var(--muted);
}

.field-card-actions {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

.fields-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--muted);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    font-size: 13px;
}

/* Field editor panel */
.field-editor {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: sticky;
    top: calc(var(--topbar-h) + 16px);
}

.field-editor h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--body-text);
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

/* Add field buttons */
.add-field-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.add-field-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 12px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--body-text);
    transition: background var(--transition), border-color var(--transition);
    font-family: var(--font);
}

.add-field-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

.add-field-btn svg { width: 18px; height: 18px; }

/* ============================================================
   PUBLIC FORM PAGE
   ============================================================ */
.public-form-wrapper {
    min-height: 100vh;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 40px 16px 60px;
}

.public-form-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--card-shadow);
    width: 100%;
    max-width: 820px;
    overflow: hidden;
}

.public-form-header {
    background: var(--primary);
    padding: 26px 30px;
    color: #fff;
}

.public-form-header h1 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.public-form-header p  { font-size: 13px; opacity: .85; margin: 0; }

.public-form-body { padding: 28px 36px; }

.public-form-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.public-form-logo img {
    max-height: 55px;
    object-fit: contain;
}

.form-success-state {
    text-align: center;
    padding: 50px 30px;
}

.form-success-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--success-light);
    color: var(--success);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.form-success-icon svg { width: 30px; height: 30px; }

.form-success-state h2 { font-size: 20px; font-weight: 700; color: #0f172a; margin-bottom: 8px; }
.form-success-state p  { font-size: 14px; color: var(--muted); }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    min-height: 100vh;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 20px rgba(0,0,0,.08);
    width: 100%;
    max-width: 400px;
    padding: 36px 32px;
}

.login-logo {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo img {
    max-height: 50px;
    margin: 0 auto 10px;
}

.login-logo h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
}

.login-logo p {
    font-size: 12.5px;
    color: var(--muted);
    margin: 3px 0 0;
}

/* ============================================================
   MISC UTILITIES
   ============================================================ */
.text-muted   { color: var(--muted) !important; }
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger) !important; }
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-bold    { font-weight: 700; }
.text-sm      { font-size: 12.5px; }

.d-flex       { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

.mb-0  { margin-bottom: 0; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

.w-full { width: 100%; }

.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
}

.empty-state svg { width: 48px; height: 48px; margin: 0 auto 16px; opacity: .35; }
.empty-state h3  { font-size: 15px; font-weight: 600; color: var(--body-text); margin-bottom: 6px; }
.empty-state p   { font-size: 13px; margin-bottom: 20px; }

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--muted);
    margin-bottom: 6px;
}

.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--primary); text-decoration: none; }
.breadcrumb span { opacity: .5; }

/* Field type icon */
.field-type-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10.5px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 4px;
    background: var(--primary-light);
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: .4px;
}

/* Settings section */
.settings-section {
    margin-bottom: 32px;
}

.settings-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--muted);
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* Upload logo preview */
.logo-preview {
    width: 120px;
    height: 60px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--bg);
    margin-top: 8px;
}

.logo-preview img { max-height: 54px; max-width: 110px; object-fit: contain; }
.logo-preview .no-logo { font-size: 11px; color: var(--muted); }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    width: 100%;
    max-width: 480px;
    transform: translateY(-16px);
    transition: transform .2s;
    overflow: hidden;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title { font-size: 15px; font-weight: 700; color: #0f172a; }

.modal-body    { padding: 22px; }
.modal-footer  { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ============================================================
   LAYOUT HELPERS (responsive grid classes)
   ============================================================ */

/* 2-column layout: main content + sidebar panel */
.grid-main-side {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 22px;
    align-items: start;
}

/* 2-column layout: main content + wide panel (charts) */
.grid-main-wide {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 22px;
    align-items: start;
}

/* 2 equal columns */
.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px;
    align-items: start;
}

/* 2-column layout for settings/submission panels */
.grid-detail {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 20px;
    align-items: start;
}

/* ============================================================
   RESPONSIVO
   ============================================================ */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,.25);
    }

    .main-content { margin-left: 0; }

    .sidebar-toggle { display: flex; }

    .builder-layout { grid-template-columns: 1fr; }

    .field-editor { position: static; }

    .form-grid-2,
    .form-grid-3 { grid-template-columns: 1fr; }

    .page-header { flex-direction: column; align-items: flex-start; }

    /* Collapse all dashboard/admin grids to single column */
    .grid-main-side,
    .grid-main-wide,
    .grid-2col,
    .grid-detail { grid-template-columns: 1fr; }

    /* Table: allow horizontal scroll on small screens */
    .table-responsive { -webkit-overflow-scrolling: touch; }

    /* Alert full-width on small screens */
    .alert { margin: 12px 14px; }

    /* Page body narrower padding */
    .page-body { padding: 16px 14px 32px; }

    /* Topbar title smaller */
    .topbar-title { font-size: 13px; }

    /* Card header wrap */
    .card-header { flex-wrap: wrap; gap: 8px; }

    /* Buttons in page-header wrap nicely */
    .page-header { gap: 10px; }
    .page-header > div:last-child { flex-wrap: wrap; }

    /* Submissions list: IP column hide on narrow */
    .col-hide-sm { display: none; }
}

@media (max-width: 600px) {
    .page-body { padding: 14px 10px 28px; }

    .stats-grid { grid-template-columns: 1fr 1fr; }

    .public-form-header { padding: 20px; }
    .public-form-body   { padding: 18px 16px; }

    .login-card { padding: 28px 18px; }

    .add-field-grid { grid-template-columns: repeat(3, 1fr); }

    /* Stack stat cards on very small screens */
    .stats-grid { gap: 10px; }
    .stat-card  { padding: 16px; gap: 12px; }
    .stat-value { font-size: 22px; }

    /* Charts shorter on phone */
    .chart-wrap { height: 180px !important; }

    /* Topbar: hide user name, keep avatar */
    .user-name { display: none; }

    /* Modal full-width */
    .modal { max-width: 100%; margin: 0 8px; border-radius: var(--radius); }

    /* IP list tighter */
    .ip-list li { padding: 8px 12px; font-size: 12px; }
    .ip-badge   { font-size: 11px; }
}

@media (max-width: 420px) {
    .stats-grid { grid-template-columns: 1fr; }
}

/* Overlay backdrop for mobile sidebar */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 199;
}

.sidebar-backdrop.open { display: block; }
