/* ============================================
   Pixia - Edit Image Metadata
   (loaded only on edit-metadata.html)
   Complements css/ai-tool.css (.at-* primitives)
   Scope: body.at-metadata
   Accent: amber / orange
   ============================================ */

body.at-metadata {
    --mt-accent: #f97316;
    --mt-accent-2: #f59e0b;
    --mt-accent-ink: #ffffff;
    --mt-ok: #22c55e;
    --mt-shadow: 0 16px 34px -18px rgba(249, 115, 22, .55);
}

body.at-metadata [hidden] { display: none !important; }

body.at-metadata .at-kicker {
    background: linear-gradient(135deg, #f97316, #f59e0b);
    color: #ffffff;
}
body.at-metadata .at-btn {
    background: linear-gradient(135deg, #f97316, #f59e0b);
    color: #ffffff;
    box-shadow: var(--mt-shadow);
}
body.at-metadata .at-btn-alt {
    background: var(--glass-bg);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    box-shadow: none;
}
body.at-metadata .at-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
    box-shadow: none;
}

/* ---------- Layout ---------- */
body.at-metadata .mt-layout {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr) 340px;
    gap: 20px;
    align-items: start;
}

.mt-left,
.mt-center,
.mt-right {
    min-width: 0;
    display: grid;
    gap: 16px;
    align-content: start;
}

.mt-center {
    position: sticky;
    inset-block-start: 84px;
    align-self: start;
}

body.at-metadata .at-panel { min-height: 0; min-width: 0; }

.mt-panel h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 12px;
    font-family: var(--font-display);
    font-size: 1.02rem;
    letter-spacing: -.015em;
}

.mt-hint { margin: 9px 0 0; font-size: 12px; line-height: 1.55; color: var(--text-muted); }
.mt-hint:first-child { margin-block-start: 0; }

/* ---------- Dropzone ---------- */
.mt-drop {
    display: grid;
    place-items: center;
    gap: 6px;
    padding: 26px 14px;
    border: 1.6px dashed var(--glass-border);
    border-radius: 14px;
    background: var(--glass-bg);
    text-align: center;
    cursor: pointer;
    transition: border-color .18s, background .18s, color .18s;
}
.mt-drop:hover, .mt-drop.is-dragover {
    border-color: var(--mt-accent);
    background: color-mix(in srgb, var(--mt-accent) 8%, var(--glass-bg));
    color: var(--mt-accent);
}
.mt-drop svg { width: 36px; height: 36px; }
.mt-drop strong { font-weight: 700; color: var(--text-secondary); display: block; font-size: 14px; }
.mt-drop em { font-style: normal; font-size: 12px; opacity: .85; }

.mt-btn-grid { margin-block-start: 12px; display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.mt-btn-grid .at-btn { width: 100%; padding: 12px 14px; font-size: 14px; }

/* ---------- Queue ---------- */
.mt-queue-head { display: flex; flex-direction: column; gap: 4px; margin-block-end: 10px; }
.mt-queue-head h2 { margin: 0; }
.mt-count { font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }

.mt-queue-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    padding: 8px;
    margin-block-end: 10px;
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    background: var(--glass-bg);
}
.mt-selcount {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    margin-inline-end: auto;
}
.mt-qbtn {
    appearance: none;
    border: 1px solid var(--glass-border);
    background: var(--bg-card-hover, var(--glass-bg));
    color: var(--text-secondary);
    font-size: 11.5px;
    font-weight: 600;
    padding: 5px 9px;
    border-radius: 8px;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}
.mt-qbtn:hover { color: var(--mt-accent); border-color: var(--mt-accent); }
.mt-qbtn-danger:hover { color: #ef4444; border-color: #ef4444; }

.mt-queue { display: grid; gap: 8px; max-height: 420px; overflow: auto; padding-inline-end: 2px; }

.mt-item {
    display: grid;
    grid-template-columns: auto 44px minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    padding: 8px;
    border: 1px solid var(--glass-border);
    border-radius: 11px;
    background: var(--glass-bg);
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.mt-item:hover { border-color: color-mix(in srgb, var(--mt-accent) 55%, var(--glass-border)); }
.mt-item.is-active {
    border-color: var(--mt-accent);
    background: color-mix(in srgb, var(--mt-accent) 9%, var(--glass-bg));
}
.mt-item.is-ok { border-color: color-mix(in srgb, var(--mt-ok) 60%, var(--glass-border)); }
.mt-item.is-error { border-color: #ef4444; }

.mt-item-check { accent-color: var(--mt-accent); width: 15px; height: 15px; cursor: pointer; }

.mt-item-thumb {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-card-hover, rgba(127, 127, 127, .12));
    display: grid;
    place-items: center;
    flex: none;
}
.mt-item-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mt-item-thumb svg { width: 20px; height: 20px; opacity: .5; }

.mt-item-body { min-width: 0; display: grid; gap: 2px; }
.mt-item-name {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mt-item-meta {
    font-style: normal;
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mt-item-x {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 17px;
    line-height: 1;
    width: 24px;
    height: 24px;
    border-radius: 7px;
    cursor: pointer;
    transition: color .15s, background .15s;
}
.mt-item-x:hover { color: #ef4444; background: color-mix(in srgb, #ef4444 12%, transparent); }

/* ---------- Stage / preview ---------- */
.mt-stage-panel { display: flex; flex-direction: column; }

.mt-stage {
    position: relative;
    min-height: 300px;
    max-height: 560px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    border: 1px solid var(--glass-border);
    background:
        repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--text-muted) 14%, transparent) 0% 25%, transparent 0% 50%)
        0 0 / 22px 22px;
    overflow: hidden;
}
.mt-stage-empty {
    display: grid;
    place-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 13px;
    padding: 24px;
    text-align: center;
}
.mt-stage-empty svg { width: 60px; height: 60px; opacity: .5; }
.mt-stage-empty span { color: var(--text-muted); }

.mt-stage-img { display: none; max-width: 100%; max-height: 540px; width: auto; height: auto; }
.mt-stage-img.is-visible { display: block; }

.mt-stage-busy {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 10px;
    background: color-mix(in srgb, var(--bg-card, #0f0f10) 62%, transparent);
    backdrop-filter: blur(3px);
    z-index: 3;
}
.mt-stage-busy em { font-style: normal; font-size: 13px; font-weight: 600; color: var(--text-secondary); }

.mt-spinner {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid color-mix(in srgb, var(--mt-accent) 30%, transparent);
    border-block-start-color: var(--mt-accent);
    animation: mtSpin .8s linear infinite;
}
@keyframes mtSpin { to { transform: rotate(360deg); } }

.mt-info {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    margin-block-start: 12px;
    padding-block-start: 11px;
    border-block-start: 1px solid var(--glass-border);
}
.mt-info-item { display: flex; align-items: baseline; gap: 7px; font-size: 12.5px; }
.mt-info-k { color: var(--text-muted); }
.mt-info-item strong {
    color: var(--text-secondary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    max-width: 240px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Results ---------- */
.mt-result-line { margin-block-end: 12px; font-size: 14px; color: var(--text-secondary); }
.mt-result-line strong { color: var(--mt-ok); font-weight: 700; }
.mt-actions { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.mt-actions .at-btn { width: 100%; padding: 12px 14px; font-size: 13.5px; justify-content: center; }

/* ---------- Form ---------- */
.mt-form { display: grid; gap: 14px; }

.mt-sec {
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 11px 13px 13px;
    margin: 0;
    min-width: 0;
}
.mt-sec > legend {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--mt-accent);
    padding-inline: 6px;
}

.mt-field { margin-block-start: 11px; }
.mt-field:first-of-type { margin-block-start: 2px; }
.mt-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mt-field-row .mt-field { margin-block-start: 0; }

.mt-field > label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--text-secondary);
    margin-block-end: 6px;
}

.mt-clear {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1;
    width: 20px;
    height: 20px;
    border-radius: 6px;
    cursor: pointer;
    transition: color .15s, background .15s;
    flex: none;
}
.mt-clear:hover { color: #ef4444; background: color-mix(in srgb, #ef4444 12%, transparent); }

.mt-field input[type="text"],
.mt-field input[type="number"],
.mt-field input[type="datetime-local"],
.mt-field textarea,
.mt-field select {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 11px;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 9px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.mt-field textarea { resize: vertical; min-height: 58px; line-height: 1.5; }
.mt-field input:focus,
.mt-field textarea:focus,
.mt-field select:focus {
    border-color: var(--mt-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--mt-accent) 22%, transparent);
}
.mt-field input::placeholder { color: var(--text-muted); opacity: .7; }
.mt-field select { cursor: pointer; }
.mt-field .mt-hint { margin-block-start: 5px; }

.mt-legend {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--text-secondary);
    margin-block-end: 9px;
}

/* ---------- Strip ---------- */
.mt-checks { display: grid; gap: 7px; margin-block-start: 12px; }
.mt-check {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 7px 9px;
    border: 1px solid var(--glass-border);
    border-radius: 9px;
    background: var(--glass-bg);
    cursor: pointer;
    transition: border-color .15s, color .15s;
}
.mt-check:hover { border-color: color-mix(in srgb, var(--mt-accent) 55%, var(--glass-border)); }
.mt-check:has(input:checked) {
    border-color: var(--mt-accent);
    color: var(--text-primary);
    background: color-mix(in srgb, var(--mt-accent) 8%, var(--glass-bg));
}
.mt-check input { position: absolute; opacity: 0; pointer-events: none; }
.mt-check i {
    position: relative;
    width: 34px; height: 20px;
    flex: 0 0 auto;
    border-radius: 999px;
    background: var(--bg-secondary);
    transition: background .2s ease;
}
.mt-check i::after {
    content: "";
    position: absolute;
    inset-block-start: 3px;
    inset-inline-start: 3px;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
    transition: transform .2s ease;
}
.mt-check input:checked + i { background: var(--mt-accent); }
.mt-check input:checked + i::after { transform: translateX(14px); }
[dir="rtl"] .mt-check input:checked + i::after { transform: translateX(-14px); }
.mt-check input:focus-visible + i { outline: 2px solid var(--mt-accent); outline-offset: 2px; }
.mt-check input:disabled + i { opacity: .45; }

/* ---------- Apply / progress ---------- */
.mt-export { display: grid; gap: 10px; }
.mt-apply { width: 100%; padding: 13px 16px; font-size: 15px; justify-content: center; }
.mt-apply:disabled { opacity: .45; box-shadow: none; }

.mt-progress { display: grid; gap: 7px; }
.mt-progress-bar {
    height: 8px;
    border-radius: 999px;
    background: var(--glass-border);
    overflow: hidden;
}
.mt-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, #f97316, #f59e0b);
    transition: width .18s ease-out;
}
.mt-progress-msg { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------- Tag inspector ---------- */
.mt-tags-head { display: flex; align-items: baseline; gap: 10px; margin-block-end: 12px; }
.mt-tags-head h2 { margin: 0; }
.mt-tags-count { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.mt-tags { max-height: 380px; overflow: auto; display: grid; gap: 11px; padding-inline-end: 2px; }
.mt-tags-empty { margin: 0; font-size: 13px; color: var(--text-muted); }

/* Left-column layout: stack name+hex over the value */
.mt-left .mt-tag { grid-template-columns: minmax(0, 1fr) auto; row-gap: 2px; }
.mt-left .mt-tag-val {
    grid-column: 1 / -1;
    text-align: start;
    white-space: normal;
    overflow-wrap: anywhere;
}
.mt-left .mt-tags {max-height: fit-content;}

.mt-tag-group { display: grid; gap: 3px; }
.mt-tag-group-t {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--mt-accent);
    padding-inline: 2px;
}

.mt-tag {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.3fr);
    gap: 10px;
    align-items: baseline;
    padding: 5px 8px;
    border-radius: 7px;
    font-size: 12px;
}
.mt-tag:nth-child(odd) { background: var(--glass-bg); }
.mt-keyfields .mt-tag { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); }
.mt-keyfields .mt-tag:first-of-type { background: none; }
.mt-tag-missing .mt-tag-val { color: var(--text-muted); font-style: italic; }
.mt-tag-name {
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mt-tag-hex {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 10.5px;
    color: var(--text-muted);
    white-space: nowrap;
}
.mt-tag-val {
    color: var(--text-primary);
    text-align: end;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
    direction: ltr;
}

.mt-keepori {
    margin-block-start: 10px;
    padding-block-start: 10px;
    border-block-start: 1px solid var(--glass-border);
}

/* ---------- Responsive ---------- */
@media (max-width: 1240px) {
    body.at-metadata .mt-layout { grid-template-columns: 280px minmax(0, 1fr); }
    .mt-right { grid-column: 1 / -1; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
    .mt-center { position: static; }
}
@media (max-width: 860px) {
    body.at-metadata .mt-layout { grid-template-columns: 1fr; }
    .mt-right { grid-template-columns: 1fr; }
    .mt-stage { min-height: 240px; }
    .mt-queue { max-height: 300px; }
}
