:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --card-border: #334155;
    --accent-primary: #6366f1;
    --accent-hover: #4f46e5;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --crop-line-color: #ef4444;
    --radius-lg: 16px;
    --radius-md: 10px;
    --shadow-glow: 0 10px 30px -10px rgba(99, 102, 241, 0.35);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.85), rgba(15, 23, 42, 0.95));
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--card-border);
    padding: 1.25rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.logo-group {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    width: 46px;
    height: 46px;
    background: linear-gradient(135deg, var(--accent-primary), #a855f7);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    box-shadow: var(--shadow-glow);
    color: white;
}

.title-group h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #ffffff, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.title-group p {
    font-size: 0.825rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

.header-btn,
.header-btn:link,
.header-btn:visited {
    text-decoration: none !important;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.header-btn-home,
.header-btn-home:link,
.header-btn-home:visited {
    color: var(--text-main) !important;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--card-border);
}

.header-btn-home:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff !important;
}

.header-btn-calc,
.header-btn-calc:link,
.header-btn-calc:visited {
    color: var(--accent-warning) !important;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.header-btn-calc:hover {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24 !important;
}

.badge {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-success);
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.775rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.badge-dot {
    width: 8px;
    height: 8px;
    background-color: var(--accent-success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.2); }
    100% { opacity: 1; transform: scale(1); }
}

@media (max-width: 768px) {
    header {
        padding: 0.85rem 1rem;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .logo-group {
        width: 100%;
        gap: 10px;
    }

    .title-group h1 {
        font-size: 1.15rem;
    }

    .title-group p {
        font-size: 0.75rem;
    }

    .header-actions {
        width: 100%;
        gap: 8px;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .header-btn {
        font-size: 0.775rem;
        padding: 5px 10px;
    }

    .badge {
        font-size: 0.725rem;
        padding: 4px 10px;
    }
}

@media (max-width: 480px) {
    .logo-group img {
        height: 34px !important;
    }

    .title-group h1 {
        font-size: 1.05rem;
    }

    .title-group p {
        font-size: 0.7rem;
    }

    .header-actions {
        gap: 6px;
        flex-wrap: wrap;
    }

    .header-btn {
        font-size: 0.75rem;
        padding: 5px 9px;
    }

    .badge {
        font-size: 0.7rem;
        padding: 4px 8px;
    }
}

/* Main Layout */
main {
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 1.5rem;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.sidebar-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.app-grid {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 1024px) {
    main {
        margin: 1rem auto;
        padding: 0 1rem;
    }

    .app-grid {
        display: flex;
        flex-direction: column;
        gap: 1.25rem;
    }

    .sidebar-panel {
        display: contents;
    }

    .upload-card {
        order: 1;
    }

    .preview-card {
        order: 2;
    }

    .settings-card {
        order: 3;
    }
}

/* Cards */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.card-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Dropzone */
.dropzone {
    border: 2px dashed #475569;
    border-radius: var(--radius-md);
    padding: 2.2rem 1rem;
    text-align: center;
    background: rgba(15, 23, 42, 0.4);
    cursor: pointer;
    transition: all 0.25s ease;
    position: relative;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.08);
}

.dropzone-icon {
    font-size: 2.4rem;
    color: var(--accent-primary);
    margin-bottom: 0.75rem;
}

.dropzone-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.dropzone.has-files {
    padding: 0.85rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border-style: solid;
    background: rgba(99, 102, 241, 0.08);
}

.dropzone.has-files .dropzone-icon {
    font-size: 1.25rem;
    margin-bottom: 0;
}

.dropzone.has-files .dropzone-title {
    font-size: 0.85rem;
    margin-bottom: 0;
}

.dropzone.has-files .dropzone-desc {
    display: none;
}

.file-input {
    display: none;
}

/* File List */
.file-list {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 180px;
    overflow-y: auto;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.825rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.file-item:hover,
.file-item.active-file {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.12);
}

.active-badge {
    background: rgba(99, 102, 241, 0.25);
    color: #a5b4fc;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 6px;
    border: 1px solid rgba(99, 102, 241, 0.4);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.file-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crop-toolbar {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.remove-file {
    color: #ef4444;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: background 0.2s;
}

.remove-file:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* Controls */
.control-group {
    margin-bottom: 1.25rem;
}

.control-label {
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preset-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 1rem;
}

.preset-btn {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
}

.preset-btn i {
    font-size: 1.1rem;
    color: var(--accent-primary);
}

.preset-btn:hover {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
}

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

.preset-btn.active i {
    color: #fff;
}

/* Slider Controls */
.slider-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--card-border);
    padding: 12px;
    border-radius: 8px;
}

.range-slider {
    width: 100%;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

.slider-values {
    display: flex;
    justify-content: space-between;
    font-size: 0.775rem;
    color: var(--text-muted);
}

.highlight-val {
    color: var(--accent-success);
    font-weight: 700;
}

/* Action Buttons */
.action-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 1.5rem;
}

.btn {
    padding: 12px 18px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-hover));
    color: white;
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 12px 35px -8px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid var(--card-border);
    color: var(--text-main);
}

.btn-secondary:hover:not(:disabled) {
    background: #334155;
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.btn-success:hover:not(:disabled) {
    box-shadow: 0 10px 25px -5px rgba(16, 185, 129, 0.4);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Preview Panel */
.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
}

.nav-btn {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.nav-btn:hover:not(:disabled) {
    background: var(--accent-primary);
}

.canvas-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    min-height: 480px;
}

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

.canvas-box {
    background: #090d16;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    overflow: hidden;
}

.canvas-title {
    position: absolute;
    top: 10px;
    left: 12px;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid var(--card-border);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    z-index: 10;
}

.canvas-container {
    position: relative;
    max-width: 100%;
    max-height: 420px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border-radius: 4px;
    overflow: hidden;
}

canvas {
    max-width: 100%;
    max-height: 420px;
    object-fit: contain;
    display: block;
}

.crop-overlay-line {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--crop-line-color);
    box-shadow: 0 0 8px var(--crop-line-color);
    z-index: 20;
    pointer-events: none;
}

.crop-overlay-line::after {
    content: "CROP LINE (ABOVE TAX INVOICE)";
    position: absolute;
    right: 8px;
    top: -20px;
    background: var(--crop-line-color);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
}

.crop-shade {
    position: absolute;
    left: 0;
    width: 100%;
    bottom: 0;
    background: rgba(239, 68, 68, 0.25);
    pointer-events: none;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

/* Footer */
footer {
    border-top: 1px solid var(--card-border);
    padding: 1.25rem 2rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: rgba(15, 23, 42, 0.5);
}
