/* Web Scraper feature — scoped styles (page-web) */

/* Let Web Creator use the full viewport — the global .creator-area cap of
   1200px wastes ~⅓ of the screen on wide monitors. */
.creator-area:has(#page-web.page-section.active) {
    max-width: none;
}

#page-web .ws-page-header {
    padding: 16px 24px 8px;
}

/* Animated loader for Smart Scraper preview (mirrors Branding tab). */
#page-web .ws-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 60px 10px;
    color: var(--tc-text-muted, #94a3b8);
    font-size: 14px;
    text-align: center;
}
#page-web .ws-loader code {
    font-family: ui-monospace, Menlo, monospace;
    font-size: 12px;
    color: var(--tc-text, #e2e8f0);
}
#page-web .ws-loader-sub {
    font-size: 12px;
    color: var(--tc-text-muted, #94a3b8);
}
#page-web .ws-bars {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 60px;
}
#page-web .ws-bars span {
    width: 6px;
    background: var(--tc-primary, #a855f7);
    border-radius: 3px;
    animation: wsBar 1.1s ease-in-out infinite;
}
#page-web .ws-bars span:nth-child(2) { animation-delay: .1s; }
#page-web .ws-bars span:nth-child(3) { animation-delay: .2s; }
#page-web .ws-bars span:nth-child(4) { animation-delay: .3s; }
#page-web .ws-bars span:nth-child(5) { animation-delay: .4s; }
#page-web .ws-bars span:nth-child(6) { animation-delay: .5s; }
#page-web .ws-bars span:nth-child(7) { animation-delay: .6s; }
@keyframes wsBar {
    0%, 100% { height: 14px; opacity: .5; }
    50% { height: 54px; opacity: 1; }
}

/* Smart Scraper preview prose / link list. */
#page-web .ws-md-pre {
    background: var(--tc-bg, #0f172a);
    border: 1px solid var(--tc-border, #2b3342);
    border-radius: 8px;
    padding: 12px;
    font-family: ui-monospace, Menlo, monospace;
    font-size: 12px;
    line-height: 1.55;
    color: var(--tc-text, #e2e8f0);
    max-height: 420px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}
#page-web .ws-link-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 320px;
    overflow: auto;
}
#page-web .ws-link-list li {
    padding: 6px 8px;
    border-radius: 6px;
    margin-bottom: 2px;
}
#page-web .ws-link-list li:hover {
    background: var(--tc-card-hover, rgba(255,255,255,0.04));
}
#page-web .ws-link-list a {
    color: var(--tc-primary, #a855f7);
    text-decoration: none;
}

#page-web .ws-legal-banner {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-top: 12px;
    padding: 10px 14px;
    border: 1px solid var(--border-subtle, #2b3342);
    border-radius: 8px;
    background: var(--bg-secondary, rgba(255,255,255,0.03));
    font-size: 13px;
    color: var(--text-secondary, #b4bdca);
}

#page-web .ws-legal-banner code {
    background: rgba(255,255,255,0.06);
    padding: 1px 5px;
    border-radius: 3px;
}

#page-web .ws-legal-icon {
    font-size: 18px;
    line-height: 1;
}

#page-web .ws-tabs {
    display: flex;
    gap: 6px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-subtle, #2b3342);
    margin-bottom: 16px;
}

#page-web .ws-tab {
    background: transparent;
    color: var(--text-secondary, #b4bdca);
    border: 0;
    border-bottom: 2px solid transparent;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

#page-web .ws-tab:hover {
    color: var(--text-primary, #e6ecf3);
}

#page-web .ws-tab.active {
    color: var(--accent-color, #4f9cf9);
    border-bottom-color: var(--accent-color, #4f9cf9);
}

#page-web .ws-panel {
    display: none;
    padding: 0 24px 32px;
}

#page-web .ws-panel.active {
    display: block;
}

#page-web .ws-grid {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 18px;
}

@media (max-width: 1180px) {
    #page-web .ws-grid {
        grid-template-columns: 1fr;
    }
}

#page-web .ws-card {
    background: var(--bg-card, rgba(255,255,255,0.02));
    border: 1px solid var(--border-subtle, #2b3342);
    border-radius: 10px;
    padding: 16px 18px;
    min-height: 0;
}

#page-web .ws-card-header {
    margin-bottom: 12px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

#page-web .ws-card-header h2 {
    font-size: 17px;
    margin: 0;
}

#page-web .ws-card-header p {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--text-secondary, #8a93a1);
}

#page-web .ws-subsection {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed var(--border-subtle, #2b3342);
}

#page-web .ws-subsection h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary, #8a93a1);
    margin: 0 0 8px;
}

#page-web .ws-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary, #8a93a1);
    margin-bottom: 10px;
    flex: 1;
}

#page-web .ws-input {
    background: var(--bg-input, rgba(0,0,0,0.25));
    color: var(--text-primary, #e6ecf3);
    border: 1px solid var(--border-subtle, #2b3342);
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 13px;
    width: 100%;
}

#page-web textarea.ws-input {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    resize: vertical;
}

#page-web .ws-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin: 8px 0;
}

#page-web .ws-row label {
    font-size: 13px;
    color: var(--text-primary, #e6ecf3);
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

#page-web .ws-fieldset {
    border: 1px solid var(--border-subtle, #2b3342);
    border-radius: 8px;
    padding: 10px 12px;
    margin: 10px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
}

#page-web .ws-fieldset legend {
    padding: 0 6px;
    font-size: 12px;
    color: var(--text-secondary, #8a93a1);
}

#page-web .ws-btn {
    background: var(--bg-input, rgba(255,255,255,0.06));
    color: var(--text-primary, #e6ecf3);
    border: 1px solid var(--border-subtle, #2b3342);
    border-radius: 6px;
    padding: 7px 14px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s, border-color 0.15s;
    text-decoration: none;
    display: inline-block;
}

#page-web .ws-btn:hover:not(:disabled) {
    border-color: var(--accent-color, #4f9cf9);
}

#page-web .ws-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#page-web .ws-btn-primary {
    background: var(--accent-color, #4f9cf9);
    border-color: var(--accent-color, #4f9cf9);
    color: #0b1220;
    font-weight: 600;
}

#page-web .ws-btn-secondary {
    background: transparent;
}

#page-web .ws-btn-danger {
    color: #ff8a8a;
    border-color: rgba(255, 107, 107, 0.4);
}

#page-web .ws-btn-danger:hover:not(:disabled) {
    background: rgba(255, 107, 107, 0.08);
}

#page-web .ws-btn-small {
    padding: 3px 8px;
    font-size: 12px;
}

#page-web .ws-status {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-secondary, #8a93a1);
    min-height: 18px;
}

#page-web .ws-status-ok {
    color: #6ed993;
}

#page-web .ws-status-error {
    color: #ff8a8a;
}

#page-web .ws-counts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

#page-web .ws-count-pill {
    background: rgba(79, 156, 249, 0.12);
    border: 1px solid rgba(79, 156, 249, 0.35);
    color: var(--accent-color, #4f9cf9);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 12px;
    font-family: ui-monospace, monospace;
}

#page-web .ws-preview {
    max-height: 680px;
    overflow: auto;
    font-size: 13px;
    line-height: 1.5;
}

#page-web .ws-preview h3 {
    font-size: 13px;
    margin: 14px 0 6px;
    color: var(--accent-color, #4f9cf9);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#page-web .ws-preview ul {
    margin: 4px 0;
    padding-left: 20px;
}

#page-web .ws-empty {
    color: var(--text-secondary, #8a93a1);
    font-style: italic;
    padding: 22px;
    text-align: center;
}

#page-web .ws-thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
}

#page-web .ws-thumb {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-subtle, #2b3342);
    border-radius: 6px;
    padding: 6px;
    overflow: hidden;
}

#page-web .ws-thumb img {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    background: #0b1220;
    border-radius: 4px;
}

#page-web .ws-thumb small {
    font-size: 10px;
    color: var(--text-secondary, #8a93a1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#page-web .ws-progress-block {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px 18px;
    margin-bottom: 12px;
}

#page-web .ws-progress-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 10px;
    border-radius: 6px;
    background: rgba(255,255,255,0.03);
    font-size: 13px;
}

#page-web .ws-progress-row strong {
    font-family: ui-monospace, monospace;
    color: var(--accent-color, #4f9cf9);
}

#page-web .ws-log {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    background: rgba(0,0,0,0.35);
    border: 1px solid var(--border-subtle, #2b3342);
    border-radius: 6px;
    padding: 8px 10px;
    max-height: 340px;
    overflow: auto;
    color: var(--text-secondary, #b4bdca);
}

#page-web .ws-log-line {
    white-space: pre-wrap;
    word-break: break-word;
    padding: 1px 0;
}

#page-web .ws-log-warn { color: #ffd479; }
#page-web .ws-log-error { color: #ff8a8a; }

#page-web .ws-table-wrap {
    overflow: auto;
    max-width: 100%;
}

#page-web .ws-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

#page-web .ws-table th,
#page-web .ws-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-subtle, #2b3342);
    text-align: left;
    vertical-align: top;
}

#page-web .ws-table th {
    background: rgba(255,255,255,0.03);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary, #8a93a1);
}

#page-web .ws-td-url {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#page-web .ws-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

#page-web .ws-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: rgba(255,255,255,0.06);
    color: var(--text-primary, #e6ecf3);
}

#page-web .ws-badge-draft { background: rgba(180, 180, 180, 0.18); }
#page-web .ws-badge-running { background: rgba(79, 156, 249, 0.2); color: #4f9cf9; }
#page-web .ws-badge-completed { background: rgba(110, 217, 147, 0.18); color: #6ed993; }
#page-web .ws-badge-completed_with_errors { background: rgba(255, 212, 121, 0.18); color: #ffd479; }
#page-web .ws-badge-failed { background: rgba(255, 138, 138, 0.18); color: #ff8a8a; }
#page-web .ws-badge-cancelled { background: rgba(180, 180, 180, 0.18); color: #b4bdca; }

#page-web .ws-jobs-empty td {
    text-align: center;
    color: var(--text-secondary, #8a93a1);
    font-style: italic;
    padding: 24px;
}

#page-web .ws-instagram-note {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 10px 12px;
    background: rgba(79, 156, 249, 0.08);
    border: 1px solid rgba(79, 156, 249, 0.3);
    border-radius: 8px;
    font-size: 12.5px;
    margin: 10px 0;
    color: var(--text-secondary, #b4bdca);
}

/* Modal used for logs / manifest preview */
.ws-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: none;
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.ws-modal.active {
    display: flex;
}

.ws-modal-body {
    background: var(--bg-card, #151b25);
    border: 1px solid var(--border-subtle, #2b3342);
    border-radius: 10px;
    padding: 16px;
    width: min(880px, 92vw);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
}

.ws-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.ws-modal-body pre {
    background: rgba(0,0,0,0.35);
    border-radius: 6px;
    padding: 10px;
    overflow: auto;
    font-size: 12px;
    flex: 1;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ──────────────────────────────────────────────────────────────
   Mobile responsive — Web Creator (smart scraper, branding,
   media downloader, full site downloader, jobs, settings).
   Two tiers: tablet (≤900px) and phone (≤640px).
   ────────────────────────────────────────────────────────────── */

/* Tablet (≤ 900px) — shrink chrome, keep two-column where it fits. */
@media (max-width: 900px) {
    #page-web .ws-page-header {
        padding: 12px 16px 0;
    }
    #page-web .ws-page-header h1.page-title {
        font-size: 1.4em;
    }
    #page-web .ws-legal-banner {
        font-size: 12px;
        padding: 8px 10px;
    }
    #page-web .ws-tabs {
        padding: 0 12px;
        /* Scroll horizontally instead of wrapping — preserves the bottom
           border treatment so the active-tab underline stays correct. */
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    #page-web .ws-tabs::-webkit-scrollbar {
        height: 4px;
    }
    #page-web .ws-tab {
        padding: 10px 12px;
        font-size: 13px;
        flex-shrink: 0;
        white-space: nowrap;
        /* Touch target: 44px tap height */
        min-height: 44px;
    }
    #page-web .ws-panel {
        padding: 0 12px 24px;
    }
    #page-web .ws-card {
        padding: 14px 12px;
    }
    /* Already at 1-col below 1180px via the existing rule; redundant but
       explicit so layout intent is obvious at this breakpoint too. */
    #page-web .ws-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    #page-web .ws-progress-block {
        grid-template-columns: 1fr;
    }
    /* Jobs table: ensure it scrolls instead of clipping content; clamp url
       column width so the row doesn't blow up. */
    #page-web .ws-table {
        font-size: 12.5px;
    }
    #page-web .ws-td-url {
        max-width: 200px;
    }
}

/* Phone (≤ 640px) — single-column everywhere; touch-first; allow url +
   long log lines to wrap rather than clip; stack action buttons. */
@media (max-width: 640px) {
    #page-web .ws-page-header {
        padding: 10px 12px 0;
    }
    #page-web .ws-page-header h1.page-title {
        font-size: 1.2em;
    }
    #page-web .ws-page-header .section-description {
        font-size: 13px;
    }
    #page-web .ws-tabs {
        padding: 0 8px;
        gap: 4px;
    }
    #page-web .ws-tab {
        padding: 10px 10px;
        font-size: 12.5px;
        min-height: 44px;
    }
    #page-web .ws-panel {
        padding: 0 8px 20px;
    }
    #page-web .ws-card {
        padding: 12px 10px;
    }
    #page-web .ws-card-header h2 {
        font-size: 1.05em;
    }
    #page-web .ws-card-header p {
        font-size: 12.5px;
    }
    /* Inputs + buttons: ≥44px tap targets, full-width by default. */
    #page-web .ws-input,
    #page-web textarea.ws-input {
        font-size: 16px;          /* prevents iOS Safari auto-zoom */
        padding: 12px 12px;
        min-height: 44px;
        width: 100%;
        box-sizing: border-box;
    }
    #page-web .ws-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    #page-web .ws-row .ws-btn {
        width: 100%;
    }
    #page-web .ws-btn {
        min-height: 44px;
        padding: 12px 14px;
        font-size: 14px;
    }
    #page-web .ws-btn-small {
        min-height: 36px;
        padding: 8px 10px;
        font-size: 12.5px;
    }
    #page-web .ws-fieldset {
        padding: 10px 8px;
    }
    /* Counts pill grid: stack to a 2-up layout so labels don't truncate. */
    #page-web .ws-counts {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }
    /* Thumbnail / media-grid: shrink min column width so 1-2 fit per row. */
    #page-web .ws-card .ws-grid,
    #page-web [class*="thumb"] .ws-grid,
    #page-web [class*="media-grid"] {
        grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    }
    /* Jobs table: collapse the URL column ellipsis and let cells wrap.
       The table-wrap already scrolls horizontally as a fallback. */
    #page-web .ws-td-url {
        max-width: none;
        white-space: normal;
        word-break: break-all;
    }
    #page-web .ws-table th,
    #page-web .ws-table td {
        padding: 6px 6px;
        font-size: 12px;
    }
    /* Action buttons in a job row: stack vertically when space is tight. */
    #page-web .ws-actions {
        flex-direction: column;
        align-items: stretch;
    }
    #page-web .ws-actions .ws-btn,
    #page-web .ws-actions .ws-btn-small {
        width: 100%;
        justify-content: center;
    }
    /* Log viewer: cap height shorter on phone so it doesn't dominate. */
    #page-web .ws-log {
        max-height: 220px;
        font-size: 11.5px;
    }
    /* Status banners full-width with comfortable text size. */
    #page-web .ws-status {
        font-size: 13px;
    }
    /* Modal: use full viewport with padding instead of fixed width. */
    .ws-modal-body {
        width: 96vw;
        max-height: 90vh;
        padding: 12px;
    }
    .ws-modal-body pre {
        font-size: 11.5px;
    }
    /* Branding host (mounted by branding.js) — let it use full width and
       wrap any flex/grid the module creates inside. */
    #page-web [data-branding-host] {
        width: 100%;
    }
    #page-web [data-branding-host] > * {
        max-width: 100%;
    }
}

/* Very small phones (≤ 380px): one tab visible at a time without
   horizontal squeeze. The horizontal-scroll tab strip from 900px still
   applies; just nudge sizes a touch smaller. */
@media (max-width: 380px) {
    #page-web .ws-tab {
        font-size: 12px;
        padding: 10px 8px;
    }
    #page-web .ws-page-header h1.page-title {
        font-size: 1.1em;
    }
}

/* ──────────────────────────────────────────────────────────────
   Branding panel overrides (the .tc-br-* classes injected by
   web/static/js/modules/branding.js). Match the same tablet/phone
   tiers as the Web Creator wrapper. The branding module sets a
   320px min-width on its input row + a 140px fixed first column on
   its meta grid; both break on phones, so we relax them here.
   ────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    #page-web .tc-br-input,
    #page-web input.tc-br-input {
        flex: 1 1 100%;
        min-width: 0;
        font-size: 16px;     /* iOS no-zoom */
        padding: 12px 12px;
        min-height: 44px;
    }
    /* The input toolbar (input + Analyze button) should stack. */
    #page-web .tc-br-toolbar,
    #page-web [data-branding-host] form,
    #page-web [data-branding-host] .row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    /* Action buttons in branding header full-width on phone. */
    #page-web .tc-br-actions,
    #page-web [data-branding-host] .actions {
        flex-direction: column;
        gap: 8px;
    }
    #page-web .tc-br-actions > *,
    #page-web [data-branding-host] button {
        width: 100%;
        min-height: 44px;
    }
    /* Meta grid: drop the fixed 140px label column to label-over-value. */
    #page-web .tc-br-meta-grid {
        grid-template-columns: 1fr;
        gap: 4px 0;
    }
    /* Color swatches: keep small + scrollable; auto-fill already adapts. */
    #page-web .tc-br-grid {
        grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    }
    /* Token list: stack each row to one column on phone so the value
       (which is often a color hex or font name) gets full width. */
    #page-web .tc-br-token-list .row {
        grid-template-columns: 1fr;
    }
    /* Logo/image card grid: shrink min size so 2-3 per row. */
    #page-web .tc-br-images {
        grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    }
    #page-web .tc-br-imgcard img {
        height: 80px;
    }
    /* Links list: cap shorter on phone so it doesn't dominate the view. */
    #page-web .tc-br-links {
        max-height: 320px;
    }
    /* Screenshot preview should never blow horizontal layout. */
    #page-web .tc-br-shot {
        max-width: 100%;
        height: auto;
    }
}
