:root {
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    color-scheme: dark;
    --color-bg: #0b1326;
    --color-surface: #131b2e;
    --color-surface-high: #1a2338;
    --color-border: #1e293b;
    --color-border-light: #273449;
    --color-primary: #10b981;
    --color-primary-dark: #0b8a62;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #6b7280;
    --badge-url: #38bdf8;
    --badge-upload: #f472b6;
    --radius: 4px;
    --shadow: 0 25px 65px -45px rgba(0, 0, 0, 0.9);
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--text-primary);
    min-height: 100vh;
    font-family: inherit;
}

a {
    color: inherit;
}

.visually-hidden {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
}

.app-shell {
    display: grid;
    grid-template-columns: 360px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 2.25rem 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.sidebar__brand {
    display: flex;
    gap: 0.9rem;
    align-items: center;
}

.logo-dot {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, #0d9488, #10b981);
    display: inline-block;
}

.sidebar__search input {
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    padding: 0.55rem 0.85rem;
    background: #0f182b;
    color: var(--text-primary);
}

.sidebar-label {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
    margin-bottom: 0.35rem;
    color: var(--text-secondary);
}

.sidebar__history-preview {
    flex: 1;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.sidebar-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.ghost-btn {
    flex: 1;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: transparent;
    color: var(--text-secondary);
    padding: 0.55rem 0.75rem;
    font-weight: 600;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.ghost-btn.small {
    flex: 0;
    padding: 0.35rem 0.85rem;
    font-size: 0.8rem;
}

.ghost-btn:hover {
    border-color: var(--color-border-light);
    background: rgba(255, 255, 255, 0.03);
}

.ghost-btn.danger {
    border-color: rgba(248, 113, 113, 0.4);
    color: #fca5a5;
}

.workspace {
    padding: 2.5rem 4vw 3rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.hero {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 2rem;
    background: var(--color-surface);
    box-shadow: var(--shadow);
}

.hero-headline {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    align-items: flex-start;
}

.settings-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 1.1rem;
    border-radius: var(--radius);
    border-color: rgba(16, 185, 129, 0.5);
    color: var(--color-primary);
    background: rgba(16, 185, 129, 0.15);
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0 0 0.35rem;
}

.hero h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3rem);
}

.hero p {
    color: var(--text-secondary);
    max-width: 620px;
}

.hero-form {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

form button,
.primary-btn {
    background: var(--color-primary);
    border: none;
    border-radius: var(--radius);
    padding: 0.85rem 2rem;
    font-weight: 600;
    color: #04251a;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.field-group label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.field-group input[type="text"],
.field-group input[type="url"],
.field-group input[type="number"] {
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: #0f182b;
    color: var(--text-primary);
    padding: 0.7rem 1rem;
    font-size: 1rem;
}

.required label::after {
    content: " *";
    color: #f87171;
}

.source-panel {
    display: none !important;
}

.source-panel.is-visible {
    display: flex !important;
}

#url-panel.source-panel.is-visible {
    flex-direction: column;
    gap: 0.45rem;
}

#file-panel.source-panel.is-visible {
    flex-direction: column;
}

.source-switch {
    display: inline-flex;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.source-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.65rem 1.2rem;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s ease, color 0.2s ease;
}

.source-btn.is-active {
    background: rgba(16, 185, 129, 0.12);
    color: var(--text-primary);
}

.source-panels {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.upload-chip {
    position: relative;
    border: 1px dashed rgba(148, 163, 184, 0.3);
    border-radius: var(--radius);
    padding: 0.9rem 1.1rem;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    color: var(--text-secondary);
}

.upload-chip input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

#file-name {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-container {
    margin: 1rem 0 0.5rem;
}

.status-banner {
    display: inline-flex;
    min-height: 1.5rem;
    align-items: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.status-banner[data-state="success"] { color: #6ee7b7; }
.status-banner[data-state="error"] { color: #fca5a5; }

.panel {
    background: var(--color-surface);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.section-heading-title {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.section-heading-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.icon-btn {
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: transparent;
    color: var(--text-primary);
    padding: 0.55rem 0.9rem;
    cursor: pointer;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
    stroke: var(--color-primary);
    stroke-width: 1.7;
    fill: none;
}

.icon-btn.is-loading svg {
    animation: spin 1s linear infinite;
}

.icon-only {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.icon-btn.icon-only {
    background: #0f182b;
}

.icon-btn.is-accent {
    border-color: rgba(16, 185, 129, 0.6);
    color: var(--color-primary);
    background: rgba(16, 185, 129, 0.1);
}

.icon-btn.danger {
    border-color: rgba(248, 113, 113, 0.4);
    color: #fca5a5;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.custom-size {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: end;
}

.custom-size.collapsed {
    display: none;
}

.settings-custom {
    margin-top: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.ghost-btn.add-size {
    border-color: var(--color-border);
    color: var(--text-primary);
}

.custom-presets-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 2rem;
    color: var(--text-secondary);
}

.custom-chip {
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    padding: 0.3rem 0.9rem;
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
}

.custom-chip button {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.preset-card {
    background: var(--color-surface-high);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.preset-card:hover {
    border-color: var(--color-primary);
    transform: translateY(-2px);
}

.preset-card h3 {
    margin: 0;
    display: flex;
    justify-content: space-between;
    font-size: 1rem;
    color: var(--text-primary);
}

.preset-meta {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.preview-wrapper {
    width: 100%;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--color-border);
    background: #050c18;
}

.preview-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preset-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.preset-actions__icons {
    display: flex;
    gap: 0.55rem;
}

.preset-actions__icons .icon-btn {
    flex: 1;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: #0f182b;
}

.primary-btn.full {
    width: 100%;
    text-align: center;
    justify-content: center;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.history-entry {
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    padding: 0.9rem;
    background: #0f182b;
}

.history-meta {
    display: flex;
    gap: 0.75rem;
    justify-content: space-between;
    align-items: flex-start;
}

.history-date {
    color: var(--text-secondary);
    font-size: 0.8rem;
    white-space: nowrap;
}

.history-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0.5rem 0;
}

.tag {
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    padding: 0.2rem 0.55rem;
    font-size: 0.75rem;
}

.badge {
    border-radius: var(--radius);
    padding: 0.15rem 0.55rem;
    font-size: 0.74rem;
    border: 1px solid var(--color-border);
    background: rgba(255, 255, 255, 0.05);
}

.badge.url { color: var(--badge-url); border-color: rgba(56, 189, 248, 0.4); }
.badge.upload { color: var(--badge-upload); border-color: rgba(244, 114, 182, 0.35); }

.history-source {
    margin: 0.25rem 0 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.history-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    gap: 0.5rem;
}

.icon-trash {
    border: none;
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-radius: var(--radius);
    padding: 0.3rem 0.65rem;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}

.icon-trash:hover {
    background: rgba(239, 68, 68, 0.25);
}

#settings-dialog {
    border: none;
    padding: 0;
    background: transparent;
    width: min(520px, 90vw);
}

#settings-dialog::backdrop { background: rgba(5, 7, 25, 0.85); }

.settings-panel {
    background: #101727;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    color: var(--text-primary);
}

.settings-section h4 { margin: 0 0 0.5rem; }

.preset-toggle-list { display: flex; flex-direction: column; gap: 0.5rem; }

.toggle-line {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

.toggle-line input { accent-color: var(--color-primary); }
.toggle-line span { flex: 1; font-size: 0.95rem; }
.toggle-line small { color: var(--text-secondary); margin-left: 0.35rem; }

.settings-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.storage-usage { color: var(--text-secondary); font-size: 0.9rem; }

#cropper-dialog {
    border: none;
    padding: 0;
    background: transparent;
    width: min(900px, 96vw);
    margin: auto;
}

#cropper-dialog::backdrop { background: rgba(5, 7, 25, 0.85); }

.cropper-panel {
    background: #10172d;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1.5rem;
    color: var(--text-primary);
    max-height: 95vh;
    min-height: clamp(480px, 70vh, 760px);
}

.cropper-header { display: flex; justify-content: space-between; align-items: center; }

.cropper-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.cropper-canvas {
    width: 100%;
    flex: 1;
    min-height: 320px;
    max-height: min(65vh, 560px);
    background: #020715;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    overflow: hidden;
}

.cropper-body img { max-width: 100%; max-height: 100%; display: block; }

.cropper-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
    border-top: 1px solid var(--color-border);
    padding-top: 1rem;
    margin-top: 0.5rem;
}

#rename-dialog {
    border: none;
    padding: 0;
    background: transparent;
    width: min(420px, 90vw);
}

#rename-dialog::backdrop {
    background: rgba(5, 7, 25, 0.85);
}

.rename-panel {
    background: #121a30;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.rename-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.rename-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.rename-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.history-source-text { color: var(--text-secondary); }

.badge.url, .badge.upload { font-weight: 600; }

.note {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

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

@media (max-width: 1024px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: sticky; top: 0; z-index: 2; border-right: none; border-bottom: 1px solid var(--color-border); }
}

@media (max-width: 680px) {
    .workspace { padding: 1.5rem; }
    .panel { padding: 1.5rem; }
}
