/* ===============================================================
   HUVIENA TOOLS — tool.css
   Shared UI for every image tool: dropzone, file info, controls,
   results, batch tables, cropper, image-to-PDF list.
   Loaded only on tool pages (layout: tool).
   ============================================================== */

/* ---------------------------------------------------------------
   1. Tool page chrome
   -------------------------------------------------------------- */
.tool-page__head {
    display: flex;
    align-items: flex-start;
    gap: 2rem;
    padding-top: .5rem;
}
.tool-page__head-text { flex: 1 1 auto; min-width: 0; }
.tool-page__head h1 { margin-bottom: .45rem; }
.tool-page__head .lede { margin-bottom: .9rem; }
.tool-page__head .eyebrow a { color: inherit; text-decoration: none; }
.tool-page__head .eyebrow a:hover { text-decoration: underline; }
.tool-page__badge { flex: none; padding-top: .15rem; }

@media (max-width: 760px) {
    .tool-page__head { flex-direction: column; gap: 1.1rem; }
    .tool-page__badge { order: -1; padding-top: 0; }
    .tool-page__badge .icon-tile { width: 56px; height: 56px; border-radius: 16px; }
    .tool-page__badge .icon { width: 28px; height: 28px; }
    .tool-page__badge .icon-tile__badge { font-size: .55rem; }
}

.feature-chips {
    display: flex; flex-wrap: wrap; gap: .5rem .6rem;
    list-style: none; padding: 0; margin: 0 0 1.25rem;
}
.feature-chips li {
    display: inline-flex; align-items: center; gap: .35rem;
    font-size: .82rem; font-weight: 550; color: var(--ink-2);
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .3rem .7rem;
}
.feature-chips .icon { color: var(--ink-3); }

.tool-page__body { padding-bottom: 1rem; }
.tool-page__main { max-width: 100%; }

/* ---------------------------------------------------------------
   2. Tool shell / panel
   -------------------------------------------------------------- */
.tool-shell {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: clamp(1.1rem, 2.6vw, 1.85rem);
    box-shadow: var(--shadow-md);
    margin-bottom: 1.25rem;
}

.tool-app { display: block; }

.tool-block { margin-top: 1.5rem; }
.tool-block:first-child { margin-top: 0; }

.tool-block__title {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    font-size: .95rem; font-weight: 700; margin: 0 0 .75rem;
    color: var(--ink);
}
.tool-block__title .count { font-weight: 500; color: var(--ink-3); font-size: .85rem; }

/* ---------------------------------------------------------------
   3. Dropzone
   -------------------------------------------------------------- */
.dropzone {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: .5rem;
    text-align: center;
    padding: clamp(1.6rem, 5vw, 3rem) 1.25rem;
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--bg-soft);
    cursor: pointer;
    transition: border-color .16s ease, background .16s ease, transform .16s ease;
    min-height: 190px;
    width: 100%;
    font: inherit;
    color: inherit;
}
.dropzone:hover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone.is-dragover {
    border-color: var(--brand);
    background: var(--brand-soft);
    transform: scale(1.008);
}
.dropzone__icon {
    display: grid; place-items: center;
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--brand-soft);
    color: var(--brand-strong);
    margin-bottom: .25rem;
}
.dropzone__icon .icon { width: 26px; height: 26px; }
.dropzone__title { font-size: 1.05rem; font-weight: 700; margin: 0; }
.dropzone__sub { color: var(--ink-3); font-size: .88rem; margin: 0; }
.dropzone__formats {
    margin-top: .35rem;
    font-size: .78rem; letter-spacing: .04em; text-transform: uppercase;
    color: var(--ink-4); font-weight: 600;
}
.dropzone input[type="file"] {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    opacity: 0; cursor: pointer;
}
.dropzone.is-compact { min-height: 110px; padding: 1.1rem; }
.dropzone.is-compact .dropzone__icon { display: none; }
.dropzone.is-compact .dropzone__title { font-size: .95rem; }
.dropzone.is-compact .dropzone__formats { display: none; }

/* ---------------------------------------------------------------
   4. Alerts
   -------------------------------------------------------------- */
.tool-alert {
    display: flex; align-items: flex-start; gap: .55rem;
    padding: .7rem .9rem;
    border-radius: var(--radius);
    font-size: .9rem;
    margin: .85rem 0 0;
    border: 1px solid transparent;
}
.tool-alert[hidden] { display: none; }
.tool-alert--error { background: var(--err-bg); color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, transparent); }
.tool-alert--warn  { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.tool-alert--info  { background: var(--brand-soft); color: var(--brand-strong); border-color: var(--brand-border); }
.tool-alert--ok    { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }

.privacy-note {
    display: flex; align-items: flex-start; gap: .5rem;
    margin: 1.1rem 0 0;
    padding: .7rem .9rem;
    font-size: .85rem;
    color: var(--ink-2);
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.privacy-note .icon { color: var(--ink-3); margin-top: .15rem; }

/* ---------------------------------------------------------------
   5. Workspace (preview + controls)
   -------------------------------------------------------------- */
.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(260px, .95fr);
    gap: 1.5rem;
    margin-top: 1.25rem;
    align-items: start;
}
@media (max-width: 860px) { .workspace { grid-template-columns: 1fr; } }

.preview-pane {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: .75rem;
    display: flex; flex-direction: column; gap: .75rem;
}
.preview-frame {
    position: relative;
    display: grid; place-items: center;
    min-height: 200px;
    max-height: 460px;
    overflow: hidden;
    border-radius: var(--radius);
    background:
        linear-gradient(45deg, var(--bg-muted) 25%, transparent 25%, transparent 75%, var(--bg-muted) 75%) 0 0 / 20px 20px,
        linear-gradient(45deg, var(--bg-muted) 25%, transparent 25%, transparent 75%, var(--bg-muted) 75%) 10px 10px / 20px 20px,
        var(--surface);
}
.preview-frame img {
    max-width: 100%;
    max-height: 440px;
    width: auto; height: auto;
    object-fit: contain;
    border-radius: 6px;
}
.preview-empty { color: var(--ink-3); font-size: .9rem; padding: 2rem 1rem; text-align: center; }

.file-info {
    display: flex; flex-wrap: wrap; gap: .4rem .6rem;
    list-style: none; margin: 0; padding: 0;
    font-size: .82rem;
}
.file-info li {
    display: inline-flex; align-items: center; gap: .35rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .28rem .65rem;
    color: var(--ink-2);
}
.file-info strong { font-weight: 650; color: var(--ink); }

/* Controls ----------------------------------------------------- */
.control-pane { display: flex; flex-direction: column; gap: 1.15rem; }

.control { display: flex; flex-direction: column; gap: .45rem; }
.control__label {
    display: flex; align-items: baseline; justify-content: space-between; gap: .75rem;
    font-size: .87rem; font-weight: 650; color: var(--ink);
}
.control__value { font-variant-numeric: tabular-nums; color: var(--brand-strong); font-weight: 700; }
.control__help { font-size: .8rem; color: var(--ink-3); margin: 0; }

.range-row { display: flex; align-items: center; gap: .85rem; }
.range-row input[type="range"] { flex: 1; accent-color: var(--brand); height: 26px; }

input[type="number"], input[type="text"], select {
    font: inherit;
    font-size: .92rem;
    padding: .55rem .7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-muted);
    color: var(--ink);
    width: 100%;
    min-height: 44px;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input:focus, select:focus { border-color: var(--ink-3); background: var(--bg-soft); }
input::placeholder { color: var(--ink-4); }

.field-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: .6rem; align-items: end; }
.field-grid .field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field-grid .field label { font-size: .78rem; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.field-grid .field-sep { padding-bottom: .55rem; color: var(--ink-4); font-weight: 700; }

.field { display: flex; flex-direction: column; gap: .35rem; }
.field label { font-size: .84rem; font-weight: 650; color: var(--ink-2); }

.check {
    display: flex; align-items: center; gap: .55rem;
    font-size: .89rem; color: var(--ink-2);
    cursor: pointer;
    min-height: 44px;
}
.check input[type="checkbox"], .check input[type="radio"] {
    width: 18px; height: 18px; accent-color: var(--brand); flex: none;
}
.check--inline { min-height: 0; }

.segmented {
    display: inline-flex; flex-wrap: wrap; gap: .3rem;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .3rem;
}
.segmented button {
    font: inherit; font-size: .87rem; font-weight: 600;
    padding: .45rem .8rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent; color: var(--ink-3);
    cursor: pointer;
    min-height: 38px;
}
.segmented button:hover { background: var(--bg-muted); color: var(--ink); }
.segmented button[aria-pressed="true"] {
    background: var(--bg-muted); color: var(--brand-strong);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-xs);
}

.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .45rem; }
.preset {
    font: inherit; font-size: .84rem; text-align: left;
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
    line-height: 1.35;
}
.preset:hover { border-color: var(--brand-border); color: var(--ink); }
.preset[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-strong); font-weight: 650; }
.preset small { display: block; color: var(--ink-3); font-size: .76rem; }

/* ---------------------------------------------------------------
   6. Results
   -------------------------------------------------------------- */
.result-card {
    margin-top: 1.5rem;
    border: 1px solid var(--ok);
    border-radius: var(--radius-lg);
    background: var(--ok-bg);
    padding: 1.15rem;
}
.result-card__head { display: flex; align-items: center; gap: .5rem; margin-bottom: .85rem; }
.result-card__head h3 { margin: 0; font-size: 1rem; color: var(--ok); }

.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: .75rem;
    margin-bottom: 1rem;
}
.metric {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .7rem .8rem;
}
.metric__label {
    display: block;
    font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
    color: var(--ink-3); font-weight: 700;
}
.metric__value { font-size: 1.15rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.metric--good .metric__value { color: var(--ok); }

/* Batch table -------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 560px; }
.data-table th, .data-table td {
    padding: .65rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table thead th {
    background: var(--bg-soft);
    font-size: .74rem; text-transform: uppercase; letter-spacing: .07em;
    color: var(--ink-3); font-weight: 700;
    white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--bg-soft); }
.data-table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .file-cell { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.data-table .thumb {
    width: 42px; height: 42px; flex: none;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-muted);
}
.data-table .fname {
    display: block;
    max-width: 230px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-weight: 600;
}
.data-table .fmeta { display: block; font-size: .76rem; color: var(--ink-3); }
.savings { font-weight: 700; color: var(--ok); }
.savings--none { color: var(--ink-3); font-weight: 500; }

/* Progress ----------------------------------------------------- */
.progress {
    height: 6px;
    border-radius: 999px;
    background: var(--bg-muted);
    overflow: hidden;
    margin: .75rem 0 0;
}
.progress__bar {
    height: 100%;
    width: 0;
    background: var(--brand);
    border-radius: inherit;
    transition: width .2s ease;
}
.progress[hidden] { display: none; }

/* ---------------------------------------------------------------
   7. Cropper
   -------------------------------------------------------------- */
.crop-stage {
    position: relative;
    display: block;
    background: #000000;
    border-radius: var(--radius-lg);
    overflow: hidden;
    touch-action: none;
    height: min(60vh, 480px);
    min-height: 300px;
}
.crop-stage .crop-image {
    position: absolute;
    top: 0; left: 0;
    max-width: none;
    max-height: none;
    user-select: none;
    -webkit-user-drag: none;
    cursor: grab;
}
.crop-stage.is-panning .crop-image { cursor: grabbing; }
.crop-box {
    position: absolute;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, .68);
    cursor: move;
    touch-action: none;
}
.crop-box::before,
.crop-box::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.crop-box::before {
    border-left: 1px solid rgba(255, 255, 255, .35);
    border-right: 1px solid rgba(255, 255, 255, .35);
    margin-inline: 33.33%;
}
.crop-box::after {
    border-top: 1px solid rgba(255, 255, 255, .35);
    border-bottom: 1px solid rgba(255, 255, 255, .35);
    margin-block: 33.33%;
}
.crop-handle {
    position: absolute;
    width: 20px; height: 20px;
    background: #fff;
    border: 1px solid var(--ink-3);
    border-radius: 4px;
    touch-action: none;
}
.crop-handle[data-handle="nw"] { top: -10px; left: -10px; cursor: nwse-resize; }
.crop-handle[data-handle="ne"] { top: -10px; right: -10px; cursor: nesw-resize; }
.crop-handle[data-handle="sw"] { bottom: -10px; left: -10px; cursor: nesw-resize; }
.crop-handle[data-handle="se"] { bottom: -10px; right: -10px; cursor: nwse-resize; }

.crop-toolbar { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: center; margin-top: 1rem; }
.crop-toolbar .control { flex: 1 1 190px; }

/* ---------------------------------------------------------------
   8. Image → PDF page list
   -------------------------------------------------------------- */
.page-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .55rem; }
.page-item {
    display: flex; align-items: center; gap: .8rem;
    padding: .6rem .7rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.page-item.is-dragging { opacity: .5; }
.page-item.is-over { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-border); }
.page-item__grip {
    flex: none;
    cursor: grab;
    color: var(--ink-4);
    background: none; border: 0; padding: .25rem;
    min-height: 40px;
    display: grid; place-items: center;
}
.page-item__grip:active { cursor: grabbing; }
.page-item__thumb {
    width: 52px; height: 52px; flex: none;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-muted);
}
.page-item__info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.page-item__name {
    display: block; font-weight: 600; font-size: .89rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.page-item__meta { font-size: .78rem; color: var(--ink-3); }
.page-item__num {
    flex: none;
    display: grid; place-items: center;
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--brand-soft); color: var(--brand-strong);
    font-size: .78rem; font-weight: 700;
}
.page-item__actions { display: flex; gap: .25rem; flex: none; }
.icon-btn {
    display: grid; place-items: center;
    width: 36px; height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
    font: inherit;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--ink); border-color: var(--border-strong); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------------------------------------------------------------
   9. Misc
   -------------------------------------------------------------- */
.tool-note {
    font-size: .85rem; color: var(--ink-3);
    margin: 1rem 0 0;
}
kbd {
    font-family: var(--mono);
    font-size: .8em;
    background: var(--bg-muted);
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 5px;
    padding: .05em .35em;
}
.format-badge {
    display: inline-flex; align-items: center; gap: .3rem;
    font-size: .74rem; font-weight: 700; letter-spacing: .05em;
    text-transform: uppercase;
    padding: .2rem .5rem;
    border-radius: 6px;
    background: var(--bg-muted); color: var(--ink-2);
}
.format-badge--to { background: var(--brand-soft); color: var(--brand-strong); }

@media (max-width: 640px) {
    .tool-shell { border-radius: var(--radius-lg); }
    .segmented { width: 100%; }
    .segmented button { flex: 1 1 auto; }
    .crop-handle { width: 26px; height: 26px; }
}
