/* --- General Resets & WordPress Alignment --- */
.smart-alt-text-wrap {
    background: #f0f0f1;
    padding: 24px;
    border-radius: 6px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

h1,
h2 {
    color: #1d2327;
    font-weight: 600;
    line-height: 1.2;
    margin-top: 0;
}

h1 {
    font-size: 1.8em;
}

h2 {
    font-size: 1.5em;
    padding-bottom: 8px;
    border-bottom: 1px solid #e2e4e7;
    margin-top: 24px;
    margin-bottom: 16px;
}

/* --- Buttons --- */
.button-primary {
    background: #007cba;
    border-color: #007cba;
    color: #fff;
    box-shadow: 0 1px 0 rgba(0, 0, 0, .1);
    text-shadow: none;
    font-weight: 500;
    transition: all 0.1s ease-in-out;
}

.button-primary:hover,
.button-primary:focus {
    background: #006fa1;
    border-color: #006fa1;
    color: #fff;
}

.button-large {
    padding: 8px 16px;
    height: 38px;
    font-size: 14px;
}

/* --- Layout: Header and Grid --- */
.smart-alt-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.smart-alt-grid {
    display: grid;
    grid-template-columns: 1fr minmax(280px, 320px);
    gap: 32px;
    align-items: start;
}

@media (max-width: 900px) {
    .smart-alt-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Panel & Card Styles (Elevated UI) --- */
.smart-alt-panel,
.smart-alt-aside .card {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    padding: 24px;
}

.smart-alt-panel form {
    background: none;
    padding: 0;
    box-shadow: none;
}

.smart-alt-panel>p.description {
    margin-top: 0;
    margin-bottom: 24px;
    color: #50575e;
    font-style: italic;
    padding-bottom: 12px;
    border-bottom: 1px solid #e2e4e7;
}

/* --- API Status Badges --- */
.smart-alt-badges .smart-alt-badge {
    padding: 8px 12px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 13px;
    border-width: 1px;
    border-style: solid;
}

.smart-alt-badge.status-ok {
    background: #e7f5e8;
    color: #137b3d;
    border-color: #b8e3c1;
}

/* --- Form Table --- */
.form-table th {
    width: 250px;
    padding: 12px 10px 12px 0;
    vertical-align: top;
    font-weight: 500;
    color: #1d2327;
}

.form-table td {
    padding: 12px 10px;
    vertical-align: top;
}

.form-table td input[type="text"],
.form-table td input[type="password"] {
    width: 100%;
    max-width: 400px;
    border-radius: 4px;
    border: 1px solid #8c8f94;
    padding: 8px 10px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07);
    transition: border-color 0.1s ease;
}

.form-table td input[type="text"]:focus,
.form-table td input[type="password"]:focus {
    border-color: #007cba;
    box-shadow: 0 0 0 1px #007cba;
    outline: 2px solid transparent;
}

/* --- Toggle Switch: Universal Style Refinement --- */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #e2e4e7;
    transition: .4s;
    border-radius: 12px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

input:checked+.slider {
    background-color: #007cba;
}

input:checked+.slider:before {
    -webkit-transform: translateX(20px);
    -ms-transform: translateX(20px);
    transform: translateX(20px);
}

/* --- Apply Alt To Section Specific Styles (Toggles) --- */
.smart-alt-subsection {
    display: grid;
    gap: 12px;
    /* Remove padding/margin from default form style */
    padding: 10px 0;
}

.smart-alt-subsection h3 {
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 0;
    /* H3 is now part of the grid flow */
    color: #1d2327;
    grid-column: 1 / -1;
    /* Span full width if needed */
}

.sat-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Important: Align text to the right and switch to the left */
    width: 100%;
    max-width: 400px;
    /* Constrain width for clean layout */
    padding: 6px 0;
}

.sat-toggle-label {
    font-weight: 400;
    color: #32373c;
    font-size: 14px;
    /* Ensure label takes up necessary space */
    flex-grow: 1;
}

/* Fix for the main "Generate Alt on Upload" row */
tr:has(#generate_on_upload) td .switch {
    /* Align this switch to the left for standard placement */
    margin-left: 0;
}


/* --- Other Component Styles (Same as previous revision for consistency) --- */
.submit {
    padding-top: 24px;
    margin-top: 24px;
    border-top: 1px solid #e2e4e7;
}

/* --- Image Types Input/Tags --- */
.smart-alt-types {
    /* Updated Container Styles */
    display: flex;
    /* CRITICAL: Allows tags and input to sit side-by-side cleanly */
    flex-wrap: wrap;
    align-items: center;
    /* Vertically center the tags and input */
    padding: 8px;
    border: 1px solid #8c8f94;
    border-radius: 4px;
    min-height: 44px;
    background: #fff;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07);
    transition: border-color 0.1s ease;
}

.smart-alt-types:focus-within {
    /* Focus state for the container when typing */
    border-color: #007cba;
    box-shadow: 0 0 0 1px #007cba;
}

.smart-alt-tags {
    /* Container for all tags */
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    /* Reduced gap for a tighter look */
    margin-bottom: 0;
    /* Remove margin, relying on padding/gap for spacing */
}

.smart-alt-tag {
    /* Individual Tag Style */
    display: inline-flex;
    align-items: center;
    background: #e9f4ff;
    /* Light blue background for visual interest */
    border: 1px solid #79b0dc;
    /* Subtle border for definition */
    color: #007cba;
    /* Text color matching primary theme */
    border-radius: 4px;
    /* Square/soft edges (modern) */
    padding: 4px 8px;
    /* Slightly more vertical padding */
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    /* Ensure consistent vertical alignment */
}

.smart-alt-tag-remove {
    /* Tag Removal Button */
    margin-left: 8px;
    background: none;
    border: 0;
    color: #007cba;
    /* Matching primary color */
    cursor: pointer;
    line-height: 1;
    font-size: 16px;
    /* Slightly larger icon */
    padding: 0;
    opacity: 0.8;
    transition: opacity 0.1s ease, color 0.1s ease;
}

.smart-alt-tag-remove:hover {
    color: #d63638;
    /* Red on hover for delete action */
    opacity: 1;
}

#altninja-types-input {
    /* Input field inside the tag container */
    flex-grow: 1;
    /* Allows input to take up remaining space */
    border: none;
    outline: none;
    padding: 5px;
    font-size: 14px;
    width: auto;
    /* Let flex-grow handle width */
    min-width: 100px;
    /* Ensure a minimum typing width */
    background: transparent;
    box-shadow: none;
    /* Override any general input styles */
    /* Adjust margin to align with tags */
    margin-left: 6px;
}

/* Ensure the tags are displayed properly inside the flex container */
.form-table tr:has(#altninja-types-list) td>div {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- Language Select (Combobox) --- */
.smart-alt-select {
    position: relative;
    /* CRITICAL: Sets the positioning context for the absolute dropdown */
    width: 100%;
    max-width: 400px;
    border: 1px solid #8c8f94;
    border-radius: 4px;
    padding: 4px;
    background: #fff;
    /* Ensure background is white */
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07);
}

/* Ensure the search input is styled to fit within the combobox look */
#alt_text_language_search {
    width: 100%;
    padding: 4px 8px;
    border: none;
    outline: none;
    font-size: 14px;
    /* Reset any unwanted styles from the general input rules */
    box-shadow: none;
    max-width: none;
}

.smart-alt-options {
    position: absolute;
    /* Already set, but confirming */
    top: 100%;
    /* Position it right below the search input field */
    left: 0;
    right: 0;
    margin-top: 1px;
    /* Small gap/separation from the input border */
    border: 1px solid #ddd;
    background: #fff;
    z-index: 1000;
    /* CRITICAL: Ensures it stacks on top of other form elements */
    max-height: 250px;
    overflow-y: auto;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    /* Slightly stronger shadow for floating effect */
    border-radius: 4px;
}

.smart-alt-option {
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.1s ease;
}

.smart-alt-option:hover,
.smart-alt-option.selected {
    background: #f3f4f6;
    color: #1d2327;
}

.smart-alt-option.hover {
    background: #eef5ff;
    color: #007cba;
}

/* --- General Admin Wrapper --- */
.smart-alt-text-wrap {
    background: #f0f0f1;
    padding: 1px 20px 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

/* --- Main Header & Notices --- */
.smart-alt-text-wrap h1 {
    font-size: 1.8em;
    font-weight: 600;
    color: #1d2327;
    margin: 20px 0 10px;
}

/* --- Navigation Tabs --- */
.nav-tab-wrapper {
    margin: 0 0 20px 0;
    padding-bottom: 0;
    border-bottom: 2px solid #e2e4e7;
    /* Thicker, softer divider */
}

.nav-tab {
    font-size: 15px;
    /* Slightly larger font */
    padding: 10px 14px;
    /* More padding */
    line-height: 1;
    border: none;
    /* Rely on the wrapper border */
    background: transparent;
    color: #50575e;
    font-weight: 500;
    transition: color 0.1s ease;
}

.nav-tab:hover {
    color: #007cba;
}

.nav-tab-active {
    color: #007cba;
    /* Highlight color for active tab */
    font-weight: 600;
    position: relative;
    /* CRITICAL: Create an active line under the tab */
}

.nav-tab-active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    /* Position it exactly over the wrapper border */
    left: 0;
    right: 0;
    height: 2px;
    background: #007cba;
}


/* --- Table Navigation (tablenav top/bottom) --- */
.tablenav {
    height: auto;
    padding: 10px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    /* Space between the bulk actions and search */
}

.tablenav.top {
    margin-bottom: 15px;
}

.tablenav.bottom {
    margin-top: 15px;
}

.tablenav .alignleft.actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Input Consistency */
.tablenav select,
.tablenav input[type="text"],
.tablenav input[type="search"],
.tablenav .button {
    border-radius: 4px;
    border: 1px solid #c3c4c7;
    /* Softer border color */
    box-shadow: none;
    padding: 5px 10px;
    height: 34px;
    /* Slightly taller for better touch targets */
    line-height: 1.5;
}

.tablenav input[type="search"] {
    min-width: 250px;
    border-color: #8c8f94;
    transition: border-color 0.1s ease;
}

.tablenav input[type="search"]:focus {
    border-color: #007cba;
    box-shadow: 0 0 0 1px #007cba;
}

.tablenav .button.action,
.tablenav .button {
    background: #f6f7f7;
    color: #1d2327;
    cursor: pointer;
    transition: background 0.1s ease;
}

/* Grouping the bulk actions and search */
.tablenav>.alignleft:first-child {
    /* Styles for the bulk actions group */
    margin-right: auto;
}

.tablenav>.alignleft:last-child {
    /* Styles for the search group */
    margin-left: auto;
}


/* --- Main List Table (wp-list-table) --- */
.wp-list-table {
    border: 1px solid #e2e4e7;
    /* Lighter table border */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    /* More noticeable but soft lift */
    width: 100%;
    margin: 0;
    background: #fff;
    border-radius: 4px;
}

.wp-list-table thead th {
    padding: 12px 12px;
    /* Increased vertical padding */
    font-size: 14px;
    font-weight: 600;
    color: #1d2327;
    background-color: #f7f7f7;
    /* Light grey header for contrast */
    border-bottom: 1px solid #c3c4c7;
    line-height: 1.4;
    text-align: left;
}

.wp-list-table tbody tr:hover {
    background-color: #f9f9f9;
}

.wp-list-table td,
.wp-list-table th.check-column {
    padding: 10px 12px;
    /* Good vertical padding */
    vertical-align: middle;
    font-size: 13px;
    color: #32373c;
    border-top: 1px solid #eee;
}

/* Image Column Styling */
.wp-list-table .sat-thumb {
    width: 80px;
    padding: 8px 12px;
    /* Reduced vertical padding here to fit image */
}

.wp-list-table .sat-thumb-img {
    display: block;
    width: 60px;
    height: 60px;
    border-radius: 3px;
    object-fit: cover;
    border: 1px solid #eee;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* Link Column Styling */
.wp-list-table td a {
    color: #007cba;
    text-decoration: none;
    word-break: break-all;
    /* CRITICAL: Prevent long URLs from breaking the table */
}

.wp-list-table td a:hover {
    color: #006fa1;
    text-decoration: underline;
}

/* Action Button Refinement */
.wp-list-table td .sat-copy-btn {
    margin-left: 8px;
    font-size: 12px;
    /* Slightly larger for readability */
    padding: 4px 8px;
    /* Better padding */
    height: auto;
    background: #f0f0f1;
    /* Softer background */
    border-color: #dcdcde;
    color: #50575e;
    transition: all 0.1s ease;
}

.wp-list-table td .sat-copy-btn:hover {
    background: #e9e9eb;
    color: #1d2327;
}

.wp-list-table td .sat-generate {
    background: #2271b1;
    /* Standard WP blue for strong action */
    border-color: #2271b1;
    color: #fff;
    font-weight: 500;
    box-shadow: 0 1px 0 rgba(0, 0, 0, .1);
    padding: 6px 12px;
    font-size: 13px;
    height: 32px;
    line-height: 1.5;
    transition: all 0.1s ease;
}

.wp-list-table td .sat-generate:hover {
    background: #ffffff;
    border-color: #135e96;
}

/* Column Width Adjustments for better use of space */
.wp-list-table th.column-cb {
    width: 30px;
}

.wp-list-table th:nth-child(2) {
    /* Image */
    width: 90px;
}

.wp-list-table th:nth-child(5),
/* Type */
.wp-list-table th:nth-child(6) {
    /* Size */
    width: 100px;
}

.wp-list-table th:nth-child(7) {
    /* Uploaded */
    width: 130px;
}

.wp-list-table th:last-child {
    /* Actions */
    width: 180px;
}

/* --- Table Navigation (tablenav top/bottom) --- */
.tablenav {
    height: auto;
    padding: 10px 0;
    display: flex;
    justify-content: space-between;
    /* Distributes space between elements */
    align-items: center;
    gap: 20px;
}

.tablenav.top {
    margin-bottom: 15px;
}

.tablenav.bottom {
    margin-top: 15px;
}

.tablenav .alignleft.actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Ensure the elements are positioned correctly: Bulk Actions on Left, Pagination/Search on Right */
.tablenav>.alignleft:first-child {
    margin-right: auto;
    /* Push Bulk Actions to the far left */
}

/* The search group is the last `.alignleft`, if present */
.tablenav>.alignleft:last-child {
    /* No margin auto here, let the flexbox handle the gap */
}


/* --- Pagination Styling (.tablenav-pages) --- */
.tablenav-pages {
    display: flex;
    align-items: center;
    /* Move pagination slightly to the right side, between search and bulk actions */
    margin-left: auto;
    font-size: 13px;
    line-height: 1.5;
}

.page-numbers {
    display: inline-block;
    min-width: 32px;
    /* Set a minimum width for button shape */
    height: 32px;
    /* Set a fixed height */
    line-height: 30px;
    /* Vertically center the text */
    text-align: center;
    padding: 0 8px;
    margin: 0 2px;
    text-decoration: none;
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    color: #1d2327;
    transition: background-color 0.1s ease, border-color 0.1s ease;
}

.page-numbers:hover {
    background: #f0f0f1;
    border-color: #8c8f94;
    color: #007cba;
}

.page-numbers.current {
    background: #007cba;
    border-color: #007cba;
    color: #fff;
    cursor: default;
    font-weight: 600;
}

.page-numbers.current:hover {
    /* No change on hover for the current page */
    background: #007cba;
    border-color: #007cba;
    color: #fff;
}

.page-numbers.next,
.page-numbers.prev {
    /* Style for arrows (Next/Previous) */
    font-weight: 500;
    padding: 0 10px;
}


/* --- Input Consistency (Retained from prior updates) --- */
.tablenav select,
.tablenav input[type="text"],
.tablenav input[type="search"],
.tablenav .button {
    border-radius: 4px;
    border: 1px solid #c3c4c7;
    box-shadow: none;
    padding: 5px 10px;
    height: 34px;
    line-height: 1.5;
}

.tablenav input[type="search"] {
    min-width: 250px;
    border-color: #8c8f94;
    transition: border-color 0.1s ease;
}

.tablenav input[type="search"]:focus {
    border-color: #007cba;
    box-shadow: 0 0 0 1px #007cba;
}

.tablenav .button.action,
.tablenav .button {
    background: #f6f7f7;
    color: #1d2327;
}

/* Cleanup for the old HTML structure */
.tablenav .clear {
    display: none;
}

.pagination-top {
    margin-bottom: 15px;
    float: right;
}

.sat-loading {
  position: relative;
  opacity: 0.7;
  pointer-events: none;
}

.sat-loading::after {
  content: "";
  position: absolute;
  right: 40px;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border: 2px solid #ccc;
  border-top-color: #000;
  border-radius: 50%;
  animation: sat-spin 0.7s linear infinite;
}

@keyframes sat-spin {
  to {
    transform: rotate(360deg);
  }
}
