/* Entity Form Container Styles */
/* These styles mimic the D365 form layout */

.entity-form-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: #faf9f8;
}

/* Loading Overlay */
.entity-form-container .loading-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

/* Command Bar / Toolbar - mimics D365 command bar */
.entity-form-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background-color: #fff;
    border-bottom: 1px solid #e1dfdd;
    min-height: 44px;
}

.entity-form-toolbar .toolbar-left {
    display: flex;
    align-items: center;
    gap: 4px;
}

.entity-form-toolbar .toolbar-button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #323130;
    font-size: 13px;
    border-radius: 2px;
    transition: background-color 0.1s ease;
}

.entity-form-toolbar .toolbar-button:hover:not(:disabled) {
    background-color: #f3f2f1;
}

.entity-form-toolbar .toolbar-button:active:not(:disabled) {
    background-color: #edebe9;
}

.entity-form-toolbar .toolbar-button:disabled {
    color: #a19f9d;
    cursor: not-allowed;
}

.entity-form-toolbar .toolbar-button.saving {
    color: #0078d4;
}

.entity-form-toolbar .toolbar-button-text {
    font-weight: 400;
}

.entity-form-toolbar .toolbar-divider {
    width: 1px;
    height: 24px;
    background-color: #e1dfdd;
    margin: 0 8px;
}

/* Form Header - mimics D365 header style */
.entity-form-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px 20px;
    background-color: #fff;
    border-bottom: 1px solid #e1dfdd;
}

.entity-form-header .header-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
}

.entity-form-header .entity-title-section {
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.2;
}

.entity-form-header .entity-title {
    font-size: 18px;
    font-weight: 600;
    color: #323130;
    margin: 0;
    padding: 0;
    line-height: 1.2;
}

.entity-form-header .unsaved-indicator {
    color: #797775;
    font-weight: normal;
    font-size: 14px;
}

.entity-form-header .saved-indicator {
    color: #107c10;
    font-weight: normal;
    font-size: 14px;
}

.entity-form-header .entity-subtitle {
    font-size: 12px;
    color: #605e5c;
    margin: 0;
    padding: 0;
    line-height: 1.2;
    text-align: left;
}

.entity-form-header .header-right {
    display: flex;
    gap: 0;
    align-items: flex-start;
}

.entity-form-header .status-section,
.entity-form-header .related-entity-section {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    padding: 0 24px;
    border-left: 1px solid #e1dfdd;
}

.entity-form-header .related-entity-section:first-child {
    padding-left: 0;
    border-left: none;
}

.entity-form-header .status-value,
.entity-form-header .related-entity-value {
    font-size: 14px;
    font-weight: 600;
    color: #323130;
}

.entity-form-header .status-label,
.entity-form-header .related-entity-label {
    font-size: 11px;
    color: #605e5c;
}

/* Header Edit Flyout */
.header-edit-flyout {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 10;
    background-color: #fff;
    border: 1px solid #e1dfdd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 16px 20px;
    min-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.header-edit-flyout .header-edit-field {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-edit-flyout .header-edit-field label {
    font-size: 13px;
    font-weight: 600;
    color: #323130;
    min-width: 100px;
    text-align: left;
}

.header-edit-flyout .header-edit-field .required-indicator {
    color: #a4262c;
    margin-left: 2px;
}

.header-edit-flyout .header-edit-field .field-control {
    flex: 1;
    min-width: 0;
}


/* Tab Navigation - mimics D365 tabs */
.entity-form-tabs {
    display: flex;
    gap: 0;
    padding: 0 20px;
    background-color: #fff;
    border-bottom: 1px solid #e1dfdd;
}

.entity-form-tabs .tab-button {
    padding: 12px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    color: #323130;
    position: relative;
    transition: color 0.15s ease;
}

.entity-form-tabs .tab-button:hover:not(:disabled) {
    color: #0078d4;
}

.entity-form-tabs .tab-button.active {
    color: #0078d4;
    font-weight: 600;
}

.entity-form-tabs .tab-button.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background-color: #0078d4;
}

.entity-form-tabs .tab-button:disabled {
    color: #a19f9d;
    cursor: not-allowed;
}

/* Tab Content Area */
.entity-form-content {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
}

/* Form Actions Footer */
.entity-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    background-color: #fff;
    border-top: 1px solid #e1dfdd;
}

/* Form Tab Content Layout */
.form-tab-content {
    width: 100%;
}

.form-tab-content .tab-columns {
    display: grid;
    grid-template-columns: 2fr 3fr;
    gap: 20px;
}

.form-tab-content .tab-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.form-tab-content .tab-content-single {
    width: 100%;
    min-width: 0;
    overflow: hidden;
}

/* Form Section Styles */
.form-section {
    background-color: #fff;
    border: 1px solid #e1dfdd;
    border-radius: 4px;
    min-width: 0;
}

.form-section .section-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #e1dfdd;
    background-color: #faf9f8;
}

.form-section .section-header[role="button"] {
    cursor: pointer;
}

.form-section .section-header[role="button"]:hover {
    background-color: #f3f2f1;
}

.form-section .section-title {
    font-size: 14px;
    font-weight: 600;
    color: #323130;
    margin: 0;
}

.form-section .section-header-actions {
    margin-left: auto;
    padding-left: 24px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-section .section-content {
    padding: 16px;
    overflow: hidden;
}

.form-section .section-content.columns-1 {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-section .section-content.columns-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-section.collapsed .section-header {
    border-bottom: none;
}

/* Form Field Styles */
.form-field {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

/* Full-width fields (e.g., long text areas, Region Summary) keep the
   label-above-value layout because their controls need the full row to themselves. */
.form-field.full-width {
    grid-column: 1 / -1;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
}

.form-field .field-label {
    display: flex;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    color: #605e5c;
    flex: 0 0 160px;
    min-width: 0;
}

.form-field.full-width .field-label {
    flex: 0 0 auto;
}

.form-field .field-label .required-indicator {
    color: #a4262c;
    margin-left: 2px;
}

.form-field .field-value {
    flex: 1 1 auto;
    min-width: 0;
}

.form-field.read-only .field-value {
    background-color: #f3f2f1;
    border-radius: 2px;
}

/* Narrow viewports: fall back to the original stacked layout so labels and
   values don't get crushed side-by-side. */
@media (max-width: 640px) {
    .form-field {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }

    .form-field .field-label {
        flex: 0 0 auto;
    }
}

/* Override Fluent UI styles for form fields */
.form-field fluent-text-field,
.form-field fluent-select,
.form-field fluent-date-picker,
.form-field fluent-number-field,
.form-field fluent-text-area {
    width: 100%;
}

/* fluent-select ships with a built-in min-width (~250px) on its host and internal
   control, which width:100% doesn't override, so it overflows narrow columns and
   gets clipped. Force both to respect the column width. Author rules on the host
   win over the component's shadow :host rule. */
.form-field fluent-select {
    min-width: 0;
    box-sizing: border-box;
}

.form-field fluent-select::part(control) {
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

/* Background and border overrides - target only the correct parts per component */
.form-field fluent-text-field::part(root),
.form-field fluent-select::part(control),
.form-field fluent-date-picker::part(control),
.form-field fluent-number-field::part(root),
.form-field fluent-text-area::part(control) {
    background-color: #fff;
    border-color: #8a8886;
}

/* Remove box-shadow from all Fluent UI component parts and states */
.form-field fluent-text-field::part(root),
.form-field fluent-text-field::part(control),
.form-field fluent-select::part(control),
.form-field fluent-select::part(listbox),
.form-field fluent-date-picker::part(root),
.form-field fluent-date-picker::part(control),
.form-field fluent-number-field::part(root),
.form-field fluent-number-field::part(control),
.form-field fluent-text-area::part(root),
.form-field fluent-text-area::part(control) {
    box-shadow: none !important;
}

.form-field fluent-text-field:hover::part(root),
.form-field fluent-text-field:focus-within::part(root),
.form-field fluent-select:hover::part(control),
.form-field fluent-select:focus-within::part(control),
.form-field fluent-date-picker:hover::part(control),
.form-field fluent-date-picker:focus-within::part(control),
.form-field fluent-number-field:hover::part(root),
.form-field fluent-number-field:focus-within::part(root),
.form-field fluent-text-area:hover::part(control),
.form-field fluent-text-area:focus-within::part(control) {
    box-shadow: none !important;
}

.form-field.read-only fluent-text-field::part(root),
.form-field.read-only fluent-select::part(control) {
    background-color: #f3f2f1;
    border-color: #e1dfdd;
    box-shadow: none !important;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .form-tab-content .tab-columns {
        grid-template-columns: 1fr;
    }
    
    .form-section .section-content.columns-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .entity-form-header {
        flex-direction: column;
        gap: 12px;
    }
    
    .entity-form-header .header-right {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .entity-form-header .status-section,
    .entity-form-header .related-entity-section {
        align-items: flex-start;
        text-align: left;
    }
}
