:root {
    /* Blue Serenity (Reverted Dark Mode) */
    --bg-main: #0f172a;
    --bg-soft: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;

    --accent-primary: #2563eb;
    /* Royal Blue */
    --accent-secondary: #60a5fa;
    /* Blue 400 */
    --accent-tertiary: #1e40af;
    /* Blue 800 */

    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-blur: 12px;

    --input-bg: rgba(15, 23, 42, 0.6);
    --input-border: rgba(255, 255, 255, 0.1);

    --success: #10B981;
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    /* Reverted to Inter for clarity */

    --shadow-card: 0 4px 30px rgba(0, 0, 0, 0.3);

    color-scheme: dark;
}

[data-theme="light"] {
    /* Soft Morning (Light Mode) */
    color-scheme: light;
    --bg-main: #f0f4f8;
    --bg-soft: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;

    --accent-primary: #0d9488;
    /* Teal 600 */
    --accent-secondary: #f59e0b;
    /* Amber 500 */
    --accent-tertiary: #6366f1;
    /* Indigo 500 */

    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: rgba(203, 213, 225, 0.6);

    --input-bg: rgba(255, 255, 255, 0.9);
    --input-border: rgba(203, 213, 225, 0.8);

    --shadow-card: 0 4px 30px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    overflow-x: hidden;
    position: relative;
    transition: background-color 0.5s ease, color 0.5s ease;
}

/* Background Effects */
.background-globes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.globe {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    transition: background 0.5s ease;
}

.globe-1 {
    width: 500px;
    height: 500px;
    background: var(--accent-primary);
    top: -100px;
    left: -100px;
    animation: breathe 15s infinite ease-in-out;
}

.globe-2 {
    width: 400px;
    height: 400px;
    background: var(--accent-tertiary);
    bottom: -50px;
    right: -50px;
    animation: breathe 12s infinite ease-in-out reverse;
}

.globe-3 {
    width: 300px;
    height: 300px;
    background: var(--accent-secondary);
    top: 40%;
    left: 30%;
    animation: pulse 10s infinite ease-in-out;
    opacity: 0.2;
}

@keyframes breathe {

    0%,
    100% {
        transform: scale(1) translate(0, 0);
        opacity: 0.3;
    }

    50% {
        transform: scale(1.1) translate(20px, 30px);
        opacity: 0.5;
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.2;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.4;
    }
}

/* Layout */
.container {
    width: 100%;
    max-width: 1200px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 1rem;
}

.header-top {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    margin-bottom: 0.5rem;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    font-size: 2.5rem;
}

h1 {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    background: linear-gradient(to right, var(--text-primary), var(--accent-primary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.theme-toggle {
    position: absolute;
    right: 0;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    backdrop-filter: blur(var(--glass-blur));
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    transform: scale(1.1);
    background: var(--accent-primary);
    color: var(--bg-main);
    border-color: var(--accent-primary);
}

.app-description {
    color: var(--text-secondary);
    font-size: 1.1rem;
    max-width: 600px;
    margin: 0 auto;
}

.coffee-link {
    display: inline-block;
    margin-top: 1rem;
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s;
    background: rgba(45, 212, 191, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    border: 1px solid rgba(45, 212, 191, 0.2);
}

.coffee-link:hover {
    background: rgba(45, 212, 191, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(45, 212, 191, 0.2);
}

/* Workspace Grid */
.workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

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

    .theme-toggle {
        position: static;
        margin-left: 1rem;
    }
}

/* Cards */
.card {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: 1.5rem;
    padding: 2rem;
    box-shadow: var(--shadow-card);
    transition: transform 0.3s ease, background 0.5s ease, border-color 0.5s ease;
}

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

h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    color: var(--accent-primary);
    margin-bottom: 1rem;
    font-weight: 500;
}

/* Form Elements */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
}

input,
textarea,
select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 0.75rem;
    padding: 0.8rem 1rem;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 1.05rem;
    /* Slightly larger */
    font-weight: 500;
    /* Punchier */
    transition: all 0.2s;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
    /* Larger label */
    font-weight: 600;
    /* Bolder label */
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.2);
}

textarea {
    resize: vertical;
}

/* Select options styling */
select option {
    background-color: var(--bg-soft);
    color: var(--text-primary);
}

.hint {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.4rem;
    opacity: 0.8;
}

/* Input Group for Prefix */
.input-group {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.input-prefix {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-right: none;
    border-radius: 0.75rem 0 0 0.75rem;
    padding: 0.8rem 1rem;
    color: var(--text-secondary);
    font-size: 1rem;
    display: flex;
    align-items: center;
    white-space: nowrap;
    flex-shrink: 0;
}

.input-group input {
    flex: 1;
    min-width: 0;
    /* Prevent overflow */
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* Date Picker */
input[type="date"] {
    color-scheme: light dark;
}

/* Buttons */
.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-tertiary));
    border: none;
    border-radius: 0.75rem;
    padding: 1rem;
    color: #fff;
    /* Ensure text is readable on gradient */
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(45, 212, 191, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(45, 212, 191, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-primary);
    padding: 0.8rem 1.2rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: var(--font-heading);
    transition: all 0.2s;
    flex: 1;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-primary);
}

.full-width {
    width: 100%;
}

/* Items List */
.items-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.item-row {
    background: rgba(0, 0, 0, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: 0.75rem;
    padding: 1.25rem;
    position: relative;
    transition: all 0.2s;
}

[data-theme="light"] .item-row {
    background: rgba(255, 255, 255, 0.5);
    border-color: var(--glass-border);
}

.item-row:hover {
    border-color: var(--accent-primary);
    background: rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .item-row:hover {
    background: rgba(255, 255, 255, 0.7);
}

.item-row-header {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: flex-start;
}

.item-desc {
    flex: 1;
    font-weight: 500;
}

.remove-btn {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.remove-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
}

.item-row-details {
    display: grid;
    grid-template-columns: minmax(70px, 0.8fr) minmax(100px, 1.2fr) minmax(110px, 1fr) minmax(100px, 1.2fr) minmax(100px, 1.2fr);
    gap: 0.8rem;
    align-items: end;
}

.field-mini {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.field-mini label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.3rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Totals Grid */
.totals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

@media (max-width: 600px) {
    .item-row-details {
        grid-template-columns: 1fr 1fr;
    }

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


/* Results Panel States */
.results-panel {
    min-height: 400px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: sticky;
    top: 2rem;
}

.hidden {
    display: none !important;
}

/* Placeholder State */
.state-placeholder {
    text-align: center;
    color: var(--text-secondary);
}

.illustration {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.7;
    animation: float 6s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* Processing State */
.state-processing {
    text-align: center;
}

.loader {
    width: 60px;
    height: 60px;
    margin: 0 auto 1.5rem;
    position: relative;
}

.spinner {
    width: 100%;
    height: 100%;
    border: 4px solid var(--glass-border);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Success State */
.state-success {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
}

.success-header {
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-badge {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    padding: 0.4rem 0.8rem;
    border-radius: 2rem;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 10px var(--success);
}

.invoice-preview {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 1rem;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--glass-border);
}

[data-theme="light"] .invoice-preview {
    background: rgba(255, 255, 255, 0.6);
}

.preview-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
}

.preview-divider {
    height: 1px;
    background: var(--glass-border);
    margin: 0.5rem 0;
}

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

.value {
    color: var(--text-primary);
    font-weight: 500;
    text-align: right;
}

.value.strong {
    font-weight: 700;
    color: var(--accent-primary);
}

.value.large {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--success);
}

.sub-info {
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}