:root {
    --bg: #0b0e14;
    --surface: #131822;
    --surface-elevated: #1a2130;
    --border: #263043;
    --border-focus: #3b82f6;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 14px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

[hidden] {
    display: none !important;
}

body {
    font-family: "Inter", system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    background-image: radial-gradient(circle at 15% 15%, rgba(59, 130, 246, 0.08), transparent 40%),
        radial-gradient(circle at 85% 85%, rgba(16, 185, 129, 0.06), transparent 40%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

.app-shell {
    max-width: 1120px;
    margin: 0 auto;
    padding: 28px 20px 48px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    display: grid;
    place-items: center;
    color: #fff;
    flex-shrink: 0;
}

.brand h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.quota-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    min-width: 245px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.quota-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.quota-title {
    font-size: 0.74rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    display: inline-flex;
    align-items: center;
    border-radius: 6px;
    transition: color 0.18s ease, transform 0.3s ease;
}

.icon-btn:hover {
    color: var(--text);
}

.icon-btn.spinning svg {
    animation: spin 0.7s linear infinite;
}

.quota-numbers {
    display: flex;
    align-items: baseline;
    gap: 5px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.quota-numbers strong {
    font-size: 0.98rem;
    color: var(--text);
}

.quota-sep {
    opacity: 0.4;
}

.quota-bar {
    width: 100%;
    height: 5px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
}

.quota-fill {
    height: 100%;
    background: var(--success);
    border-radius: 999px;
    transition: width 0.35s ease, background-color 0.25s ease;
}

.quota-fill.warn {
    background: var(--warning);
}

.quota-fill.danger {
    background: var(--danger);
}

.workspace {
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    gap: 24px;
    align-items: start;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--bg);
    padding: 4px;
    border-radius: 10px;
    margin-bottom: 22px;
    border: 1px solid var(--border);
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.86rem;
    font-weight: 500;
    padding: 9px 12px;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.18s ease;
}

.tab-btn.active {
    background: var(--surface-elevated);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-bottom: 18px;
}

.input-group label {
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--text);
}

.input-wrapper {
    display: flex;
    gap: 8px;
}

input[type="url"],
input[type="text"],
input[type="number"],
select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 14px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.18s ease;
}

input:focus,
select:focus {
    border-color: var(--border-focus);
}

.hint {
    font-size: 0.77rem;
    color: var(--text-muted);
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.dropzone {
    border: 1.5px dashed var(--border);
    border-radius: 12px;
    padding: 28px 16px;
    text-align: center;
    background: var(--bg);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    transition: border-color 0.2s ease, background 0.2s ease;
}

.dropzone.dragover {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.06);
}

.dropzone p {
    font-size: 0.88rem;
    color: var(--text);
}

.color-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

input[type="color"] {
    width: 40px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
}

.primary-btn {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 12px 18px;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-decoration: none;
    transition: background 0.18s ease, opacity 0.18s ease;
}

.primary-btn:hover {
    background: var(--accent-hover);
}

.primary-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.ghost-btn {
    background: var(--surface-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0 14px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.18s ease;
}

.ghost-btn:hover {
    border-color: var(--accent);
}

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 0.83rem;
    margin-bottom: 16px;
}

.error-alert {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.empty-state {
    min-height: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 10px;
    color: var(--text-muted);
    padding: 20px;
}

.empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    margin-bottom: 6px;
    color: var(--accent);
}

.empty-state h2 {
    font-size: 1rem;
    color: var(--text);
}

.empty-state p {
    font-size: 0.85rem;
    max-width: 320px;
}

.preview-stage {
    position: relative;
    background: repeating-conic-gradient(#161b26 0% 25%, #0f131c 0% 50%) 50% / 18px 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 240px;
    max-height: 360px;
    margin-bottom: 18px;
}

.preview-stage img {
    max-width: 100%;
    max-height: 360px;
    object-fit: contain;
    display: block;
}

.badge-saving {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(16, 185, 129, 0.92);
    color: #042f2e;
    font-size: 0.76rem;
    font-weight: 700;
    padding: 5px 10px;
    border-radius: 999px;
}

.stats-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 18px;
}

.stat-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-label {
    font-size: 0.74rem;
    color: var(--text-muted);
}

.stat-item strong {
    font-size: 0.86rem;
    color: var(--text);
}

.output-link-box {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-bottom: 16px;
}

.output-link-box label {
    font-size: 0.82rem;
    color: var(--text-muted);
}

@media (max-width: 860px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .quota-card {
        width: 100%;
    }
}

.history-section {
    margin-top: 24px;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.history-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.history-header p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.danger-ghost:hover {
    border-color: var(--danger);
    color: #fca5a5;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 14px;
}

.history-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color 0.18s ease;
}

.history-card:hover {
    border-color: var(--accent);
}

.history-thumb {
    height: 130px;
    background: repeating-conic-gradient(#161b26 0% 25%, #0f131c 0% 50%) 50% / 14px 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}

.history-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(16, 185, 129, 0.9);
    color: #042f2e;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
}

.history-body {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.76rem;
    color: var(--text-muted);
}

.history-meta strong {
    color: var(--text);
}

.history-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.history-btn {
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 7px;
    padding: 6px 8px;
    font-family: inherit;
    font-size: 0.76rem;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.history-btn:hover {
    border-color: var(--accent);
}