/**
 * Fredo Missing Alt Text Manager — Admin Stylesheet
 *
 * Scoped to #matm-root to avoid conflicts with other plugins or WordPress core styles.
 * Uses CSS custom properties (variables) for easy theming.
 */

/* ==========================================================================
   1. Reset & Scope
   ========================================================================== */

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

/* ==========================================================================
   2. CSS Custom Properties (Design Tokens)
   ========================================================================== */

#matm-root {
    --bg:           #0f1623;
    --bg-card:      #161f2e;
    --bg-row-even:  #161f2e;
    --bg-row-odd:   #131b28;
    --bg-hover:     #1e2d44;
    --border:       #1e2d44;
    --border-mid:   #243350;
    --text:         #e2e8f0;
    --text-muted:   #64748b;
    --accent:       #3b82f6;
    --accent-soft:  #1d3a6e;
    --green:        #10b981;
    --red:          #ef4444;
    --red-soft:     #2d1212;
    --radius:       10px;
    --radius-sm:    6px;
    --shadow:       0 4px 24px rgba(0, 0, 0, 0.4);
    --font-mono:    "JetBrains Mono", "Fira Code", Consolas, monospace;
    --font:         "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

    font-family: var(--font);
    background:  var(--bg);
    color:       var(--text);
    min-height:  100vh;
    padding:     24px 28px 60px;
    font-size:   14px;
    line-height: 1.5;
}

/* Override WordPress admin background and padding, scoped to this plugin's page only.
 * WordPress adds the body class .toplevel_page_{slug} when this page is active,
 * so these rules never affect any other admin screen.
 * Using literal hex values here because CSS custom properties defined on #matm-root
 * are not in scope at the body/document level. */
body.toplevel_page_fredo-missing-alt-text-manager #wpwrap,
body.toplevel_page_fredo-missing-alt-text-manager #wpcontent,
body.toplevel_page_fredo-missing-alt-text-manager #wpbody,
body.toplevel_page_fredo-missing-alt-text-manager #wpbody-content {
    background: #0f1623;
}

/* Note: #wpcontent padding-left is intentionally left at the WordPress default
 * so the layout stays intact on all screen sizes and sidebar states. */

/* ==========================================================================
   3. Header
   ========================================================================== */

.matm-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    flex-wrap:       wrap;
    gap:             16px;
    padding:         20px 24px;
    background:      var(--bg-card);
    border:          1px solid var(--border);
    border-radius:   var(--radius);
    margin-bottom:   12px;
    box-shadow:      var(--shadow);
}

.matm-header-left {
    display:     flex;
    align-items: center;
    gap:         14px;
}

.matm-logo-icon {
    flex-shrink: 0;
    display:     flex;
}

.matm-title {
    font-size:      20px;
    font-weight:    700;
    letter-spacing: -0.3px;
    color:          var(--text);
    line-height:    1.2;
}

.matm-subtitle {
    font-size:  12px;
    color:      var(--text-muted);
    margin-top: 4px;
}

.matm-header-right {
    display:     flex;
    align-items: center;
    gap:         12px;
    flex-wrap:   wrap;
}

/* ==========================================================================
   4. Stats Block
   ========================================================================== */

.matm-stat {
    text-align: center;
    min-width:  60px;
}

.matm-stat-num {
    display:     block;
    font-size:   22px;
    font-weight: 700;
    font-family: var(--font-mono);
    color:       var(--text);
    line-height: 1.1;
}

.matm-stat-label {
    display:        block;
    font-size:      10px;
    color:          var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top:     2px;
}

.matm-stat--red   .matm-stat-num { color: var(--red);   }
.matm-stat--green .matm-stat-num { color: var(--green); }

/* ==========================================================================
   5. Export CSV Button
   ========================================================================== */

.matm-export-btn {
    display:         inline-flex;
    align-items:     center;
    gap:             6px;
    padding:         9px 16px;
    background:      var(--accent-soft);
    border:          1.5px solid var(--accent);
    border-radius:   var(--radius-sm);
    color:           #93c5fd;
    font-size:       13px;
    font-weight:     500;
    text-decoration: none;
    transition:      all 0.15s;
}

.matm-export-btn:hover {
    background:      var(--accent);
    color:           #fff;
    text-decoration: none;
}

/* ==========================================================================
   6. Toolbar (Search + Filters + Per-Page)
   ========================================================================== */

.matm-toolbar {
    display:       flex;
    align-items:   center;
    gap:           12px;
    flex-wrap:     wrap;
    padding:       12px 16px;
    background:    var(--bg-card);
    border:        1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
}

/* Search */
.matm-search-form {
    flex:      1;
    min-width: 160px;
    max-width: 300px;
}

.matm-search-wrap {
    position: relative;
    display:  flex;
    align-items: center;
}

.matm-search-icon {
    position:        absolute;
    left:            12px;
    top:             50%;
    transform:       translateY(-50%);
    color:           var(--text-muted);
    pointer-events:  none;
    flex-shrink:     0;
    display:         flex;
    align-items:     center;
}

.matm-search-input {
    width:         100%;
    padding:       9px 12px 9px 38px;
    background:    var(--bg);
    border:        1.5px solid var(--border-mid);
    border-radius: var(--radius-sm);
    color:         var(--text);
    font-size:     13px;
    font-family:   var(--font);
    transition:    border-color 0.15s;
}

.matm-search-input:focus {
    outline:      none;
    border-color: var(--accent);
}

.matm-search-input::placeholder {
    color: var(--text-muted);
}

.matm-search-clear {
    position:        absolute;
    right:           8px;
    color:           var(--text-muted);
    display:         flex;
    align-items:     center;
    text-decoration: none;
}

.matm-search-clear:hover {
    color: var(--red);
}

/* Filter Buttons */
.matm-filterbar {
    display:     flex;
    align-items: center;
    gap:         8px;
    flex-wrap:   wrap;
    flex:        1;
}

.matm-filter-btn {
    display:         inline-flex;
    align-items:     center;
    gap:             7px;
    padding:         8px 14px;
    background:      var(--bg);
    border:          1.5px solid var(--border-mid);
    border-radius:   var(--radius-sm);
    color:           var(--text-muted);
    font-size:       13px;
    font-weight:     500;
    text-decoration: none;
    transition:      all 0.15s;
    white-space:     nowrap;
    cursor:          pointer;
}

.matm-filter-btn:hover {
    background:      var(--bg-hover);
    color:           var(--text);
    border-color:    var(--accent);
    text-decoration: none;
}

.matm-filter-btn.is-active {
    background:   var(--accent-soft);
    border-color: var(--accent);
    color:        #93c5fd;
    font-weight:  600;
}

.matm-filter-btn--red:hover,
.matm-filter-btn--red.is-active {
    background:   var(--red-soft);
    border-color: var(--red);
    color:        #fca5a5;
}

.matm-filter-count {
    display:         inline-flex;
    align-items:     center;
    justify-content: center;
    min-width:       22px;
    padding:         1px 6px;
    background:      rgba(255, 255, 255, 0.07);
    border-radius:   20px;
    font-size:       11px;
    font-weight:     700;
    font-family:     var(--font-mono);
}

/* Per-Page Selector */
.matm-perpage-form {
    margin-left: auto;
}

.matm-perpage-label {
    display:     flex;
    align-items: center;
    gap:         6px;
    color:       var(--text-muted);
    font-size:   12px;
    white-space: nowrap;
}

.matm-perpage-select {
    background:    var(--bg);
    border:        1.5px solid var(--border-mid);
    border-radius: var(--radius-sm);
    color:         var(--text);
    padding:       5px 8px;
    font-size:     13px;
}

/* ==========================================================================
   7. Sub-bar (Range indicator + Save status)
   ========================================================================== */

.matm-subbar {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    flex-wrap:       wrap;
    gap:             8px;
    padding:         10px 14px;
    background:      var(--bg-card);
    border:          1px solid var(--border);
    border-radius:   var(--radius-sm);
    margin-bottom:   12px;
    font-size:       13px;
    color:           var(--text-muted);
}

.matm-subbar strong { color: var(--text);   }
.matm-subbar em     { font-style: normal; color: var(--accent); }

.matm-save-status            { font-size: 13px; font-weight: 500; }
.matm-save-status--success   { color: var(--green); }
.matm-save-status--error     { color: var(--red);   }

/* ==========================================================================
   8. Image Table — Card-style rows
   ========================================================================== */

/* Table wrapper uses CSS Grid so each row is a separate card. */
.matm-table-wrap {
    display:               grid;
    gap:                   16px;
    grid-template-columns: 1fr;
}

/* Hide the actual <table> structure — rows are displayed as grid items via CSS. */
.matm-table          { width: 100%; border-collapse: separate; border-spacing: 0; display: contents; }
.matm-table thead    { display: none; }
.matm-table th       { display: none; }

/* Each row is a 4-column grid card. */
.matm-row {
    display:               grid;
    grid-template-columns: 80px 1fr 1fr 80px;
    background:            var(--bg-card);
    border:                1px solid var(--border);
    border-radius:         var(--radius);
    transition:            all 0.12s;
    overflow:              hidden;
}

.matm-row:hover {
    background:   var(--bg-hover);
    border-color: var(--accent);
}

.matm-table td {
    padding:        0;
    border:         none;
    vertical-align: top;
}

/* --- Thumbnail cell --- */
.td-thumb {
    width:   80px;
    padding: 16px;
}

.matm-img-wrap {
    width:        70px;
    height:       70px;
    overflow:     hidden;
    border-radius: 6px;
    flex-shrink:  0;
}

.matm-thumb {
    width:       100%;
    height:      100%;
    object-fit:  cover;
    display:     block;
}

.matm-img-placeholder {
    width:           70px;
    height:          70px;
    display:         flex;
    align-items:     center;
    justify-content: center;
    border-radius:   6px;
    border:          1px solid var(--border-mid);
    background:      var(--bg);
}

/* --- File info cell --- */
.td-info {
    padding:       16px;
    border-right:  1px solid var(--border-mid);
    min-width:     0;
}

.matm-filename {
    font-size:         13px;
    font-weight:       600;
    color:             var(--text);
    word-break:        break-word;
    overflow-wrap:     break-word;
    line-height:       1.3;
    margin-bottom:     8px;
    max-height:        2.6em;
    display:           -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow:          hidden;
}

.matm-meta {
    display:       flex;
    flex-wrap:     wrap;
    gap:           6px 12px;
    font-size:     11px;
    color:         var(--text-muted);
    margin-bottom: 8px;
    font-family:   var(--font-mono);
}

.matm-edit-link {
    font-size:       11px;
    color:           var(--accent);
    text-decoration: none;
    display:         inline-flex;
    align-items:     center;
    gap:             4px;
    white-space:     nowrap;
}

.matm-edit-link:hover {
    text-decoration: underline;
}

/* --- Alt text cell --- */
.td-alt {
    padding:   16px;
    min-width: 0;
}

.matm-alt-text {
    font-size:    13px;
    color:        var(--text);
    line-height:  1.5;
    word-break:   break-word;
    display:      block;
    max-height:   60px;
    overflow-y:   auto;
}

.matm-char-count {
    display:     block;
    font-size:   10px;
    color:       var(--text-muted);
    font-family: var(--font-mono);
    margin-top:  6px;
}

.matm-missing {
    display:     inline-flex;
    align-items: center;
    gap:         5px;
    font-size:   12px;
    color:       var(--red);
    opacity:     0.8;
    font-weight: 500;
}

/* --- Inline editor --- */
.matm-alt-input {
    width:         100%;
    padding:       12px 14px;
    background:    var(--bg);
    border:        1.5px solid var(--accent);
    border-radius: var(--radius-sm);
    color:         var(--text);
    font-size:     13px;
    font-family:   var(--font);
    line-height:   1.5;
    resize:        vertical;
    min-height:    140px;
}

.matm-alt-input:focus {
    outline:      none;
    border-color: #60a5fa;
}

.matm-editor-footer {
    display:     flex;
    align-items: center;
    justify-content: space-between;
    margin-top:  12px;
    gap:         12px;
    flex-wrap:   wrap;
}

.matm-live-count {
    font-size:   11px;
    color:       var(--text-muted);
    font-family: var(--font-mono);
    white-space: nowrap;
}

.matm-editor-btns {
    display: flex;
    gap:     10px;
}

.matm-hint {
    font-size:  11px;
    color:      var(--text-muted);
    margin-top: 10px;
}

/* --- Actions cell --- */
.td-actions {
    padding:         16px;
    display:         flex;
    align-items:     center;
    justify-content: center;
}

/* ==========================================================================
   9. Buttons
   ========================================================================== */

.matm-btn {
    display:         inline-flex;
    align-items:     center;
    justify-content: center;
    padding:         8px 16px;
    border-radius:   var(--radius-sm);
    font-size:       13px;
    font-weight:     500;
    cursor:          pointer;
    border:          1.5px solid;
    transition:      all 0.14s;
    gap:             6px;
    white-space:     nowrap;
}

.matm-btn-cancel {
    background:   transparent;
    border-color: var(--border-mid);
    color:        var(--text);
}

.matm-btn-cancel:hover {
    background:   var(--bg);
    border-color: var(--text-muted);
}

.matm-btn-save {
    background:   var(--accent);
    border-color: var(--accent);
    color:        #fff;
    font-weight:  600;
}

.matm-btn-save:hover:not(:disabled) {
    background:   #2563eb;
    border-color: #2563eb;
}

.matm-btn-save:disabled {
    opacity: 0.5;
    cursor:  default;
}

.matm-btn-edit-toggle,
.matm-action-btn {
    display:         inline-flex;
    align-items:     center;
    justify-content: center;
    gap:             6px;
    padding:         9px 14px;
    border-radius:   var(--radius-sm);
    background:      transparent;
    border:          1.5px solid var(--border-mid);
    color:           var(--text);
    cursor:          pointer;
    text-decoration: none;
    transition:      all 0.14s;
    font-size:       13px;
    font-weight:     500;
}

.matm-btn-edit-toggle:hover,
.matm-action-btn:hover {
    background:      var(--bg-hover);
    border-color:    var(--accent);
    color:           var(--accent);
    text-decoration: none;
}

.matm-btn-edit-toggle.is-active,
.matm-action-btn.is-active {
    background:   var(--accent-soft);
    border-color: var(--accent);
    color:        #93c5fd;
}

/* ==========================================================================
   10. Empty State
   ========================================================================== */

.matm-empty {
    padding:       80px 20px;
    text-align:    center;
    color:         var(--text-muted);
    background:    var(--bg-card);
    border:        1px solid var(--border);
    border-radius: var(--radius);
}

.matm-empty svg     { margin-bottom: 16px; }
.matm-empty p       { font-size: 15px; }

.matm-reset-link {
    display:         inline-block;
    margin-top:      12px;
    font-size:       13px;
    color:           var(--accent);
    text-decoration: none;
}

.matm-reset-link:hover {
    text-decoration: underline;
}

/* ==========================================================================
   11. Pagination
   ========================================================================== */

.matm-pagination {
    display:         flex;
    align-items:     center;
    justify-content: center;
    gap:             8px;
    margin-top:      22px;
    flex-wrap:       wrap;
}

.matm-page-btn {
    display:         inline-flex;
    align-items:     center;
    gap:             5px;
    padding:         7px 14px;
    background:      var(--bg-card);
    border:          1px solid var(--border-mid);
    border-radius:   var(--radius-sm);
    color:           var(--text);
    text-decoration: none;
    font-size:       13px;
    font-weight:     500;
    transition:      all 0.14s;
}

.matm-page-btn:hover:not(.matm-page-disabled) {
    background:      var(--bg-hover);
    border-color:    var(--accent);
    text-decoration: none;
}

.matm-page-disabled {
    opacity: 0.35;
    cursor:  default;
}

.matm-page-numbers {
    display:     flex;
    align-items: center;
    gap:         3px;
}

.matm-page-num {
    display:         inline-flex;
    align-items:     center;
    justify-content: center;
    min-width:       34px;
    height:          34px;
    padding:         0 4px;
    border-radius:   var(--radius-sm);
    font-size:       13px;
    font-weight:     500;
    text-decoration: none;
    color:           var(--text-muted);
    border:          1px solid transparent;
    transition:      all 0.14s;
}

.matm-page-num:hover {
    background:      var(--bg-hover);
    color:           var(--text);
    border-color:    var(--border-mid);
    text-decoration: none;
}

.matm-page-numbers .matm-page-current,
.matm-page-numbers .matm-page-current:hover {
    background:   var(--accent);
    color:        #fff;
    border-color: var(--accent);
    font-weight:  700;
}

.matm-page-ellipsis {
    color:    var(--text-muted);
    padding:  0 2px;
    font-size: 14px;
}

/* ==========================================================================
   12. New feature additions — Bulk Title to ALT
   ========================================================================== */

/* "Bulk: Title to ALT" button in the header */
.matm-btn-bulk {
    display:         inline-flex;
    align-items:     center;
    gap:             6px;
    padding:         9px 16px;
    background:      var(--green);
    border:          1.5px solid var(--green);
    border-radius:   var(--radius-sm);
    color:           #fff;
    font-size:       13px;
    font-weight:     600;
    font-family:     var(--font);
    cursor:          pointer;
    transition:      all 0.15s;
    white-space:     nowrap;
}

.matm-btn-bulk:hover {
    opacity: 0.85;
}

/* Article title badge shown below the filename in the file-info column */
.matm-attached-to {
    font-size:     11px;
    color:         var(--text-muted);
    margin-top:    6px;
    margin-bottom: 4px;
    padding:       3px 8px;
    background:    rgba(59, 130, 246, 0.08);
    border-left:   2px solid var(--accent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    line-height:   1.4;
}

.matm-attached-to strong {
    color: var(--text);
}

/* ==========================================================================
   13. New additions (v1.1 update) — labels, badges, quickfill, nosave
   ========================================================================== */

/* "File name:" / "Related article:" muted inline label prefix */
.matm-info-label {
    display:        inline-block;
    font-size:      10px;
    font-weight:    600;
    color:          var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-right:   4px;
    vertical-align: middle;
}

/* Red "Image not published" badge shown under the media library link */
.matm-not-published {
    display:     inline-flex;
    align-items: center;
    margin-top:  6px;
    font-size:   11px;
    font-weight: 600;
    color:       var(--red);
    line-height: 1.3;
}

/* Green "Image published" badge */
.matm-is-published {
    display:     inline-flex;
    align-items: center;
    margin-top:  6px;
    font-size:   11px;
    font-weight: 600;
    color:       var(--green);
    line-height: 1.3;
}

/* Container for the two per-row quick-fill buttons */
.matm-quickfill-btns {
    display:    flex;
    flex-wrap:  wrap;
    gap:        5px;
    margin-top: 10px;
}

/* Individual quick-fill button ("File name to ALT" / "Title to ALT") */
.matm-quickfill-btn {
    display:         inline-flex;
    align-items:     center;
    gap:             4px;
    padding:         5px 10px;
    background:      transparent;
    border:          1px solid var(--border-mid);
    border-radius:   var(--radius-sm);
    color:           var(--text-muted);
    font-size:       11px;
    font-family:     var(--font);
    cursor:          pointer;
    transition:      all 0.13s;
    white-space:     nowrap;
}

.matm-quickfill-btn:hover {
    background:   var(--bg-hover);
    border-color: var(--accent);
    color:        var(--accent);
}

/* Bulk buttons row in the toolbar */
.matm-bulkbar {
    display:     flex;
    align-items: center;
    gap:         8px;
    flex-wrap:   wrap;
}

/* "(No saving)" label inside bulk buttons */
.matm-nosave-label {
    font-size:   10px;
    font-weight: 400;
    opacity:     0.7;
    margin-left: 2px;
    font-style:  italic;
}
