/* layout-form-row.styles.scss */

/**
 * Surface tokens (light/dark)
 * - --imex-form-surface: the main section background (circled area)
 * - --imex-form-surface-head: slightly different strip for the Card header
 * - --imex-form-surface-border: border color for the card
 *
 * Update the dark selector(s) to match whatever you use (body class, data-theme, etc).
 */

:root {
  --imex-form-surface: #fafafa; /* subtle contrast vs white page */
  --imex-form-surface-head: #f5f5f5; /* header strip */
  --imex-form-surface-border: #d9d9d9; /* matches AntD-ish border */
  --imex-form-title-input-bg: rgba(255, 255, 255, 0.96);
  --imex-form-title-input-border: rgba(0, 0, 0, 0.08);
  --imex-form-title-group-bg: rgba(255, 255, 255, 0.72);
  --imex-form-title-group-border: rgba(0, 0, 0, 0.08);
  --imex-form-title-label-bg: rgba(0, 0, 0, 0.04);
  --imex-form-title-label-border: rgba(0, 0, 0, 0.06);
}

/* Pick the selector that matches your app and remove the rest */
html[data-theme="dark"] {
  --imex-form-surface: rgba(255, 255, 255, 0.01); /* subtle lift off page bg */
  --imex-form-surface-head: rgba(255, 255, 255, 0.06); /* slightly stronger for header strip */
  --imex-form-surface-border: rgba(5, 5, 5, 0.12);
  --imex-form-title-input-bg: rgba(255, 255, 255, 0.12);
  --imex-form-title-input-border: rgba(255, 255, 255, 0.2);
  --imex-form-title-group-bg: rgba(255, 255, 255, 0.08);
  --imex-form-title-group-border: rgba(255, 255, 255, 0.16);
  --imex-form-title-label-bg: rgba(255, 255, 255, 0.06);
  --imex-form-title-label-border: rgba(255, 255, 255, 0.12);
}

.imex-form-row {
  width: 100%;

  /* Match old Divider title typography */
  .ant-card-head-title {
    font-weight: 500;
    font-size: var(--ant-font-size-lg);
    line-height: 1.2; /* optional, makes it feel like a section header */
  }

  /* Make the whole section read as its own surface */
  &.ant-card {
    background: var(--imex-form-surface);
    border-color: var(--imex-form-surface-border);
  }

  &.imex-form-row--error.ant-card {
    border-color: var(--ant-color-error);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--ant-color-error) 24%, transparent);
  }

  .ant-card-head {
    background: var(--imex-form-surface-head);
    border-bottom-color: var(--imex-form-surface-border);
  }

  &.imex-form-row--error {
    .ant-card-head,
    .ant-card-actions {
      border-color: color-mix(in srgb, var(--ant-color-error) 34%, var(--imex-form-surface-border));
    }
  }

  &.imex-form-row--compact {
    .ant-card-head {
      min-height: 40px;
    }

    .ant-card-head-title,
    .ant-card-extra {
      padding-block: 2px;
    }

    .ant-form-item {
      margin-bottom: 12px;
    }
  }

  &.imex-form-row--title-only {
    .ant-card-head {
      min-height: auto;
      padding-inline: 6px;
      padding-block: 0;
      border-radius: inherit;
    }

    .ant-card-head-wrapper {
      gap: 2px;
      align-items: center;
    }

    .ant-card-head-title,
    .ant-card-extra {
      padding-block: 0;
      display: flex;
      align-items: center;
    }

    .ant-card-head-title {
      white-space: normal;
      overflow: visible;
      text-overflow: unset;
      font-size: var(--ant-font-size);
      line-height: 1.1;
      padding-inline: 4px;
    }

    .ant-card-body {
      display: none;
      padding: 0;
    }

    .ant-input,
    .ant-input-number,
    .ant-input-affix-wrapper,
    .ant-select-selector,
    .ant-picker {
      background: var(--imex-form-title-input-bg);
      border-color: var(--imex-form-title-input-border);
    }

    .ant-input-number-input {
      background: transparent;
    }
  }

  .ant-card-body {
    background: var(--imex-form-surface);
  }

  .ant-card-actions {
    background: var(--imex-form-surface-head);
    border-top-color: var(--imex-form-surface-border);
  }

  .ant-card-actions > li {
    margin: 10px 0;
    padding-inline: 12px;
  }

  .ant-card-actions .ant-btn {
    width: 100%;
  }

  .ant-form-item:last-child {
    margin-bottom: 4px;
  }

  /* Optional: tighter spacing on phones for better space usage */
  @media (max-width: 575px) {
    &:not(.imex-form-row--title-only) .ant-card-head {
      padding-inline: 12px;
      padding-block: 12px;
    }
    .ant-card-body {
      padding: 12px;
    }
  }

  /* Tablet optimization: slightly reduce padding */
  @media (min-width: 576px) and (max-width: 991px) {
    .ant-card-body {
      padding: 14px;
    }
  }

  /* Ensure form items use full column width */
  .ant-col > * {
    width: 100%;
  }

  .ant-form-item:has(.imex-form-row--compact) {
    margin-bottom: 8px;
  }

  .ant-form-item:has(.imex-form-row--title-only) {
    margin-bottom: 4px;
  }

  /* Better form item spacing on mobile */
  @media (max-width: 575px) {
    .ant-form-item {
      margin-bottom: 12px;
    }
  }
}

.imex-form-row-empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  text-align: center;
  color: var(--ant-color-text-description);
  font-size: var(--ant-font-size);
  line-height: 1.5;
}

.imex-inline-form-row-errors {
  color: var(--ant-color-error);

  .ant-form-item-explain,
  .ant-form-item-explain-error,
  .ant-form-item-additional {
    color: var(--ant-color-error);
  }
}
