:root {
    --bg: #f4f6f3;
    --surface: #ffffff;
    --surface-soft: #f9faf7;
    --text: #17201c;
    --muted: #65716b;
    --border: #dfe5df;
    --border-strong: #c9d2cb;
    --primary: #146b63;
    --primary-dark: #0d4e49;
    --primary-soft: #e2f2ee;
    --accent: #c87918;
    --accent-soft: #fff0d6;
    --ok: #1c7c45;
    --ok-soft: #e4f4e9;
    --warn: #b66812;
    --warn-soft: #fff2dc;
    --bad: #b94135;
    --bad-soft: #fde8e5;
    --info: #366aa5;
    --info-soft: #e5eef9;
    --shadow: 0 12px 30px rgba(29, 42, 36, 0.08);
    --radius: 8px;
    --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: var(--font);
    font-size: 14px;
    letter-spacing: 0;
}

button,
input,
select,
textarea {
    font: inherit;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

label {
    display: block;
    margin: 0 0 7px;
    color: #36433d;
    font-size: 12px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    outline: none;
}

input,
select {
    min-height: 40px;
    padding: 0 11px;
}

textarea {
    resize: vertical;
    padding: 11px;
    line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(20, 107, 99, 0.14);
}

input:disabled {
    background: #edf1ee;
    color: var(--muted);
}

.login-screen {
    min-height: 100vh;
    padding: 28px;
    display: grid;
    place-items: center;
}

.login-shell {
    width: min(920px, 100%);
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    gap: 18px;
    align-items: stretch;
}

.login-copy,
.login-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.login-copy {
    padding: 38px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.product-mark {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    margin-bottom: 24px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
}

.login-copy h1 {
    margin: 0 0 12px;
    font-size: 34px;
    line-height: 1.12;
}

.login-copy p {
    margin: 0;
    max-width: 460px;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.55;
}

.login-panel {
    padding: 30px;
}

.login-panel label + input {
    margin-bottom: 16px;
}

.form-error {
    margin-top: 14px;
    padding: 10px 12px;
    border-radius: 6px;
    background: var(--bad-soft);
    color: var(--bad);
    font-weight: 700;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 18px;
    background: #ffffff;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 11px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.brand-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: #fff;
    background: var(--primary);
    font-weight: 800;
}

.brand-block strong {
    display: block;
    font-size: 14px;
}

.brand-block span {
    color: var(--muted);
    font-size: 12px;
}

.nav-stack {
    display: grid;
    gap: 6px;
}

.nav-link {
    min-height: 40px;
    padding: 0 11px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #33423b;
    font-weight: 700;
}

.nav-link:hover {
    text-decoration: none;
    background: var(--surface-soft);
}

.nav-link.active {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.nav-link i {
    font-size: 19px;
}

.sidebar-account {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.sidebar-account span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-weight: 700;
}

.workspace {
    min-width: 0;
    padding: 22px;
}

.topbar {
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar h2 {
    margin: 3px 0 0;
    font-size: 24px;
    line-height: 1.2;
}

.eyebrow {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.topbar-actions,
.inline-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.api-chip {
    max-width: 300px;
    min-height: 38px;
    padding: 0 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.api-chip code {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page {
    display: block;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.metric {
    min-height: 92px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 8px 20px rgba(29, 42, 36, 0.04);
}

.metric span {
    display: block;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 10px;
}

.metric strong {
    font-size: 30px;
    line-height: 1;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(430px, 1.1fr) minmax(320px, 0.9fr);
    gap: 14px;
    align-items: start;
}

.detail-grid,
.api-grid,
.settings-layout {
    display: grid;
    gap: 14px;
}

.detail-grid {
    grid-template-columns: minmax(0, 1fr) 320px;
}

.api-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-layout .panel:first-child,
.settings-layout .panel:nth-child(3) {
    grid-column: 1 / -1;
}

.panel {
    margin-bottom: 14px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 8px 20px rgba(29, 42, 36, 0.04);
}

.panel-heading {
    min-height: 42px;
    margin-bottom: 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.panel-heading h3 {
    margin: 0 0 4px;
    font-size: 17px;
    line-height: 1.25;
}

.panel-heading span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.btn,
.icon-btn {
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.btn {
    min-height: 40px;
    padding: 0 13px;
}

.btn-full {
    width: 100%;
}

.btn + .btn {
    margin-top: 8px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    text-decoration: none;
}

.btn-secondary {
    background: var(--surface-soft);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-warning {
    background: var(--accent-soft);
    color: #7a440b;
    border-color: #f2c879;
}

.btn-ghost {
    background: transparent;
    color: var(--primary);
}

.btn:disabled {
    opacity: 0.65;
    cursor: wait;
}

.icon-btn {
    width: 36px;
    height: 36px;
    background: var(--surface-soft);
    color: var(--text);
    border-color: var(--border);
}

.icon-btn:hover {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.form-grid {
    display: grid;
    gap: 12px;
    margin-bottom: 12px;
}

.form-grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid.four {
    grid-template-columns: 1fr 1fr auto auto;
    align-items: end;
}

.toggle-row {
    min-height: 40px;
    margin: 0;
    padding: 0 11px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 9px;
    background: #fff;
    color: var(--text);
}

.toggle-row input,
.switch-grid input {
    width: auto;
    min-height: auto;
}

.switch-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.switch-grid label {
    min-height: 42px;
    margin: 0;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-soft);
    color: var(--text);
}

.button-stack {
    display: flex;
    align-items: end;
    gap: 8px;
}

.preview-list {
    margin-top: 12px;
    display: grid;
    gap: 8px;
}

.preview-item,
.cookie-row,
.action-item {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-soft);
}

.preview-item {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 6px 10px;
}

.preview-item span {
    color: var(--primary);
    font-weight: 800;
}

.preview-item small {
    grid-column: 2;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
}

.batch-list {
    display: grid;
    gap: 10px;
}

.batch-card {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-soft);
}

.batch-card-head,
.batch-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.batch-card-head strong {
    display: block;
    margin-bottom: 4px;
}

.batch-card-head span,
.batch-card-foot span {
    color: var(--muted);
    font-size: 12px;
}

.batch-card-foot {
    margin-top: 8px;
}

.progress-shell {
    margin-bottom: 14px;
}

.progress-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.progress-track {
    height: 10px;
    border-radius: 999px;
    background: #e8eee9;
    overflow: hidden;
}

.progress-track.small {
    height: 7px;
    margin-top: 12px;
}

.progress-track span,
#batch-progress-bar {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), #6a9e3f);
    transition: width 180ms ease;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.data-table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
    background: #fff;
}

.data-table th,
.data-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    background: var(--surface-soft);
    color: #46544e;
    font-size: 12px;
    font-weight: 900;
}

.data-table tr:last-child td {
    border-bottom: 0;
}

.data-table td small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}

.row-actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.empty-cell,
.empty-state,
.loading-row {
    padding: 18px;
    color: var(--muted);
    text-align: center;
}

.url-cell {
    max-width: 360px;
}

.url-cell a {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.platform-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    margin: 2px 4px 2px 0;
    padding: 0 8px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 800;
}

.status-badge,
.log-level {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
}

.status-queued,
.status-pending {
    background: #eef0ea;
    color: #526058;
}

.status-running {
    background: var(--info-soft);
    color: var(--info);
}

.status-completed {
    background: var(--ok-soft);
    color: var(--ok);
}

.status-partial,
.status-action_required,
.status-blocked,
.status-captcha_required,
.status-rate_limited,
.status-paused {
    background: var(--warn-soft);
    color: var(--warn);
}

.status-failed {
    background: var(--bad-soft);
    color: var(--bad);
}

.action-list {
    display: grid;
    gap: 10px;
}

.action-item strong {
    display: block;
    margin-bottom: 6px;
}

.action-item p,
.action-item small {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
}

.action-item small {
    display: block;
    margin-top: 8px;
    color: var(--warn);
    font-weight: 700;
}

.code-block {
    margin: 0;
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #16201c;
    color: #eaf3ee;
    overflow-x: auto;
    line-height: 1.55;
    font-size: 12px;
}

.toolbar-input {
    max-width: 260px;
}

.cookie-list {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.cookie-row {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    gap: 8px;
}

.cookie-row span,
.muted {
    color: var(--muted);
}

.inline-result {
    min-height: 22px;
    margin-top: 10px;
    color: var(--muted);
    font-weight: 700;
}

.inline-result.ok {
    color: var(--ok);
}

.inline-result.bad {
    color: var(--bad);
}

.toast-host {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 50;
    display: grid;
    gap: 8px;
}

.toast {
    max-width: min(420px, calc(100vw - 36px));
    padding: 12px 14px;
    border-radius: 6px;
    background: var(--text);
    color: #fff;
    box-shadow: var(--shadow);
    font-weight: 800;
}

.toast-error {
    background: var(--bad);
}

.toast-warning {
    background: var(--warn);
}

.log-level {
    background: #eef0ea;
    color: #526058;
}

.level-ERROR {
    background: var(--bad-soft);
    color: var(--bad);
}

.level-WARNING {
    background: var(--warn-soft);
    color: var(--warn);
}

.level-INFO {
    background: var(--info-soft);
    color: var(--info);
}

.spin {
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 1180px) {
    .metrics-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid,
    .detail-grid,
    .api-grid,
    .settings-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 820px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .nav-stack {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .workspace {
        padding: 14px;
    }

    .topbar,
    .panel-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .form-grid.two,
    .form-grid.three,
    .form-grid.four,
    .switch-grid {
        grid-template-columns: 1fr;
    }

    .button-stack {
        align-items: stretch;
        flex-direction: column;
    }

    .login-shell {
        grid-template-columns: 1fr;
    }

    .login-copy {
        padding: 24px;
    }
}

@media (max-width: 560px) {
    .login-screen {
        padding: 12px;
    }

    .login-copy h1 {
        font-size: 28px;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .nav-stack {
        grid-template-columns: 1fr;
    }

    .topbar-actions,
    .inline-actions {
        width: 100%;
    }

    .topbar-actions .btn,
    .inline-actions .btn {
        width: 100%;
    }

    .api-chip {
        width: 100%;
        max-width: none;
    }
}
