/* ============================================================
   Cesivi Forms Designer — Custom Form Layout Styles
   PLAN-390: Core engine for tab/section/column form layouts
   Prefix: sp-form-* (avoids conflicts with existing ms-form* classes)
   ============================================================ */

/* === Layout Container === */

.sp-form-designer-layout {
    max-width: 800px;
}

/* --- Tab Navigation --- */
.sp-form-tabs-nav {
    list-style: none;
    margin: 0 0 -1px 0;
    padding: 0;
    display: flex;
    border-bottom: 1px solid #edebe9;
}
.sp-form-tabs-nav li {
    margin: 0;
}
.sp-form-tabs-nav li a {
    display: block;
    padding: 8px 16px;
    text-decoration: none;
    color: #323130;
    border: 1px solid transparent;
    border-bottom: none;
    cursor: pointer;
    font-size: 14px;
}
.sp-form-tabs-nav li a:hover {
    background: #f3f2f1;
}
.sp-form-tabs-nav li.sp-tab-active a {
    background: #fff;
    border-color: #edebe9;
    border-bottom-color: #fff;
    font-weight: 600;
    color: var(--sp-primary, #0078d4);
}
.sp-form-tabs-content {
    border: 1px solid #edebe9;
    border-top: none;
    padding: 16px;
    background: #fff;
}
/* Single tab: no border/padding needed */
.sp-form-designer-layout:not(:has(.sp-form-tabs-nav)) .sp-form-tabs-content {
    border: none;
    padding: 0;
}

/* --- Sections --- */
.sp-form-section {
    margin-bottom: 16px;
}
.sp-form-section:last-child {
    margin-bottom: 0;
}
.sp-section-header {
    margin-bottom: 8px;
    border-bottom: 1px solid #edebe9;
    padding-bottom: 4px;
}
.sp-section-title {
    font-size: 15px;
    font-weight: 600;
    color: #323130;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}
.sp-section-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: #605e5c;
    padding: 2px 6px;
    line-height: 1;
}
.sp-section-toggle:hover {
    color: #323130;
    background: #f3f2f1;
    border-radius: 2px;
}

/* --- Column Grid --- */
.sp-section-grid {
    display: grid;
    gap: 0 16px;
}
.sp-section-grid.sp-cols-1 { grid-template-columns: 1fr; }
.sp-section-grid.sp-cols-2 { grid-template-columns: 1fr 1fr; }
.sp-section-grid.sp-cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.sp-section-grid.sp-cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* Responsive: collapse to single column on small screens */
@media (max-width: 768px) {
    .sp-section-grid.sp-cols-2,
    .sp-section-grid.sp-cols-3,
    .sp-section-grid.sp-cols-4 {
        grid-template-columns: 1fr;
    }
}

/* --- Form Fields --- */
.sp-form-field {
    margin-bottom: 12px;
}
.sp-form-field:last-child {
    margin-bottom: 0;
}
.sp-form-field .ms-formlabel {
    display: block;
    margin-bottom: 4px;
}
.sp-form-field .ms-formbody {
    display: block;
}

/* Validation error state */
.sp-form-field.ms-formerror-row .field-editor {
    border-color: #a4262c;
}
.sp-form-field .ms-formvalidation {
    margin-top: 4px;
}
.sp-form-field .ms-error {
    color: #a4262c;
    font-size: 12px;
}

/* --- Dark Mode Support --- */
@media (prefers-color-scheme: dark) {
    .sp-form-tabs-nav {
        border-bottom-color: #484644;
    }
    .sp-form-tabs-nav li a {
        color: #d2d0ce;
    }
    .sp-form-tabs-nav li a:hover {
        background: #3b3a39;
    }
    .sp-form-tabs-nav li.sp-tab-active a {
        background: #1b1a19;
        border-color: #484644;
        border-bottom-color: #1b1a19;
        color: #2b88d8;
    }
    .sp-form-tabs-content {
        border-color: #484644;
        background: #1b1a19;
    }
    .sp-section-header {
        border-bottom-color: #484644;
    }
    .sp-section-title {
        color: #d2d0ce;
    }
    .sp-section-toggle {
        color: #a19f9d;
    }
    .sp-section-toggle:hover {
        color: #d2d0ce;
        background: #3b3a39;
    }
}

/* --- Print --- */
@media print {
    .sp-form-tabs-nav {
        display: none;
    }
    .sp-form-tabs-content {
        border: none;
        padding: 0;
    }
    .sp-form-tab {
        display: block !important;
        page-break-inside: avoid;
    }
    .sp-section-toggle {
        display: none;
    }
    .sp-section-body {
        display: block !important;
    }
}
