:root {
    --bg: #f6f2ec;
    --card: #ffffff;
    --text: #1d1b1a;
    --muted: #6f6a66;
    --accent: #2d6a4f;
    --accent-dark: #1f4e3a;
    --border: #ddd2c7;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Georgia", "Times New Roman", serif;
    background: radial-gradient(circle at top, #fff5e6 0%, #f6f2ec 45%, #efe6dc 100%);
    color: var(--text);
}

.container {
    max-width: 960px;
    margin: 40px auto;
    padding: 0 20px 40px;
}

.header {
    text-align: center;
    margin-bottom: 24px;
}

.header h1 {
    margin: 0 0 8px;
    font-size: 32px;
}

.subtitle {
    color: var(--muted);
    margin: 0;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 8px 20px rgba(36, 23, 14, 0.08);
}

form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-weight: 600;
}

.file-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.file-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: #f9f5ef;
    cursor: pointer;
    font-weight: 700;
    color: var(--text);
    min-height: 44px;
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.file-toggle .icon {
    width: 18px;
    height: 18px;
    display: inline-flex;
}

.file-toggle svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.file-toggle.active {
    border-color: var(--accent);
    color: #ffffff;
    background: var(--accent);
    box-shadow: 0 6px 14px rgba(45, 106, 79, 0.25);
}

.file-toggle:hover,
.file-toggle:active {
    border-color: var(--accent-dark);
    box-shadow: 0 6px 14px rgba(45, 106, 79, 0.18);
}

.file-toggle:focus-visible {
    outline: 3px solid rgba(45, 106, 79, 0.4);
    outline-offset: 2px;
}

.file-input {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 6px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: #fbf7f1;
    cursor: pointer;
    font-weight: 600;
    margin-top: 10px;
    min-height: 56px;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.file-input input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.file-input:hover,
.file-input:focus-within {
    border-color: var(--accent);
    box-shadow: 0 6px 14px rgba(45, 106, 79, 0.15);
}

.file-name {
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (hover: hover) and (pointer: fine) {
    .file-row {
        display: none;
    }
}

input[type="file"],
select {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fffdfb;
    font-size: 14px;
}

button {
    background: var(--accent);
    color: #fff;
    padding: 12px 18px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s ease;
}

button:disabled {
    background: #9fb4a8;
    cursor: not-allowed;
}

button:hover:not(:disabled) {
    background: var(--accent-dark);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.status-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.status-row {
    display: flex;
    justify-content: space-between;
    font-weight: 600;
}

.result {
    margin-top: 12px;
}

.result-card {
    display: flex;
    align-items: center;
    gap: 16px;
}

.result-card img {
    max-width: 160px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.status-overlay {
    position: fixed;
    inset: 0;
    background: rgba(24, 20, 16, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 900;
}

.status-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -46%) scale(0.98);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 18px 40px rgba(36, 23, 14, 0.2);
    width: min(92vw, 520px);
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 1001;
}

.status-modal:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.status-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

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

.status-modal-header h3 {
    margin: 0;
    font-size: 20px;
}

.status-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: #fffaf5;
    font-size: 20px;
    cursor: pointer;
}

.status-modal-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 6px;
}

.spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid #e2d7cd;
    border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
}

.status-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    border: 2px solid var(--accent);
    color: var(--accent);
    font-size: 18px;
    font-weight: 700;
}

.status-icon.success::after {
    content: "✓";
}

.status-icon.error {
    border-color: #b64b4b;
    color: #b64b4b;
}

.status-icon.error::after {
    content: "!";
}

.status-modal-footer {
    margin-top: 14px;
    display: flex;
    justify-content: flex-end;
}

.status-ok {
    padding: 10px 16px;
    border-radius: 10px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #ffffff;
    font-weight: 700;
    cursor: pointer;
}

.modal-open {
    overflow: hidden;
}

.result-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 16, 12, 0.7);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1002;
}

.result-modal {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: scale(0.98);
    z-index: 1003;
}

.result-modal:not(.hidden),
.result-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

.result-title {
    margin: 0;
    font-size: 20px;
    color: #f7f1ea;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.result-modal img {
    max-width: min(92vw, 980px);
    max-height: 78vh;
    border-radius: 16px;
    border: 1px solid #1b1b1b;
    background: #ffffff;
    cursor: pointer;
}

.result-download {
    padding: 10px 18px;
    border-radius: 12px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #ffffff;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

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

.history {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.history-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    padding: 12px;
    border: 1px dashed var(--border);
    border-radius: 12px;
    background: #fffaf5;
}

.history-item img {
    max-width: 120px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.hidden {
    display: none;
}

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(20, 16, 12, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 1000;
}

.lightbox.hidden {
    display: none;
}

.lightbox img {
    max-width: min(90vw, 900px);
    max-height: 90vh;
    border-radius: 12px;
    border: 1px solid #1b1b1b;
    background: #fff;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #ffffff;
    color: #2b2b2b;
    font-size: 24px;
    cursor: pointer;
}

@media (max-width: 720px) {
    .grid-3 {
        grid-template-columns: 1fr;
    }

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

    .result-card {
        flex-direction: column;
        align-items: flex-start;
    }
}
