/* ============================================
   Invoice Studio - Professional Invoice Generator
   Aesthetic: Editorial Luxury meets Swiss Design
   ============================================ */

:root {
    /* Color System - Black & White Theme */
    --ink: #000000;
    --ink-soft: #333333;
    --ink-muted: #666666;
    --paper: #ffffff;
    --paper-warm: #f8f8f8;
    --cream: #ffffff;
    --accent: #000000;
    --accent-light: #333333;
    --accent-subtle: rgba(0, 0, 0, 0.05);
    --coral: #000000;
    --gold: #000000;
    --border: rgba(0, 0, 0, 0.1);
    --border-strong: rgba(0, 0, 0, 0.2);
    --shadow-soft: 0 2px 20px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 8px 40px rgba(0, 0, 0, 0.12);
    --shadow-strong: 0 20px 60px rgba(0, 0, 0, 0.18);

    /* Typography */
    --font-display: 'Instrument Serif', Georgia, serif;
    --font-body: 'DM Sans', -apple-system, sans-serif;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;

    /* Transitions */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

/* ============================================
   Reset & Base
   ============================================ */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background: linear-gradient(135deg, #f0f0f0 0%, #e5e5e5 100%);
    color: var(--ink);
    min-height: 100vh;
    line-height: 1.5;
}

input, textarea, select, button {
    font-family: inherit;
    font-size: inherit;
}

/* ============================================
   App Layout
   ============================================ */

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

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
    background: var(--ink);
    color: var(--paper);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
}

.sidebar-header {
    padding: var(--space-xl);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.logo {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 400;
    letter-spacing: -0.02em;
    margin-bottom: var(--space-xs);
}

.logo span {
    font-style: italic;
    color: #ffffff;
}

.tagline {
    font-size: 0.8rem;
    color: var(--ink-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}

/* Control Sections */
.control-section {
    margin-bottom: var(--space-xl);
}

.section-title {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--paper);
    margin-bottom: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.section-number {
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-style: italic;
    color: #ffffff;
    font-weight: 400;
}

/* Logo Upload */
.logo-upload-area {
    width: 100%;
    aspect-ratio: 3 / 1;
    border: 1px dashed rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s var(--ease-out);
    margin-bottom: var(--space-md);
    overflow: hidden;
    position: relative;
}

.logo-upload-area:hover {
    border-color: #ffffff;
    background: rgba(255, 255, 255, 0.05);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    color: var(--ink-muted);
    font-size: 0.8rem;
}

.upload-placeholder svg {
    opacity: 0.5;
}

.logo-preview {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Signature Upload */
.signature-upload-area {
    width: 100%;
    aspect-ratio: 3 / 1;
    border: 1px dashed rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s var(--ease-out);
    margin-bottom: var(--space-sm);
    overflow: hidden;
    position: relative;
}

.signature-upload-area:hover {
    border-color: #ffffff;
    background: rgba(255, 255, 255, 0.05);
}

.signature-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 8px;
}

.btn-clear-signature {
    width: 100%;
    padding: 0.5rem;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: var(--ink-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}

.btn-clear-signature:hover {
    border-color: #ff6b6b;
    color: #ff6b6b;
}

/* Input Groups */
.input-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
}

.input-with-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.input-with-label label {
    font-size: 0.7rem;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input, textarea, select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: var(--paper);
    font-size: 0.9rem;
    transition: all 0.2s var(--ease-out);
}

input::placeholder, textarea::placeholder {
    color: var(--ink-muted);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8a8a' stroke-width='2'%3E%3Cpolyline points='6,9 12,15 18,9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

select option {
    background: var(--ink);
    color: var(--paper);
}

textarea {
    resize: vertical;
    min-height: 60px;
}

/* Currency Converter */
.btn-convert {
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    color: var(--paper);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}

.btn-convert:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #ffffff;
}

.convert-result {
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--paper);
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.convert-result.loading {
    color: var(--ink-muted);
}

.convert-result.error {
    color: #ff6b6b;
}

.convert-result .converted-value {
    font-weight: 600;
    font-size: 1.1rem;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: var(--space-lg);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-download {
    width: 100%;
    padding: 1rem;
    background: #ffffff;
    border: none;
    border-radius: 8px;
    color: #000000;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    transition: all 0.3s var(--ease-out);
    position: relative;
    overflow: hidden;
}

.btn-download::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 0%, rgba(255,255,255,0.2) 100%);
    opacity: 0;
    transition: opacity 0.3s;
}

.btn-download:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.btn-download:hover::before {
    opacity: 1;
}

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

/* ============================================
   Preview Area
   ============================================ */

.preview-area {
    padding: var(--space-2xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

.preview-header {
    margin-bottom: var(--space-lg);
}

.preview-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.5rem 1rem;
    background: var(--paper);
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-soft);
    box-shadow: var(--shadow-soft);
}

.preview-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

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

.invoice-wrapper {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    animation: slideUp 0.6s var(--ease-out);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   Invoice Design
   ============================================ */

.invoice {
    background: var(--cream);
    border-radius: 4px;
    box-shadow: var(--shadow-strong);
    padding: var(--space-3xl);
    position: relative;
    overflow: visible;
}

.invoice-decoration {
    position: absolute;
    top: 0;
    right: 0;
    width: 200px;
    height: 200px;
    background: linear-gradient(135deg, var(--accent-subtle) 0%, transparent 70%);
    pointer-events: none;
}

/* Invoice Header */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-xl);
}

.invoice-brand {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.brand-logo {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.logo-placeholder-invoice {
    width: 64px;
    height: 64px;
    background: var(--accent);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--paper);
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-style: italic;
}

.logo-image-invoice {
    max-width: 80px;
    max-height: 64px;
    object-fit: contain;
    border-radius: 4px;
}

.brand-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    max-width: 280px;
}

.brand-name {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--ink);
    line-height: 1;
}

.brand-contact, .brand-address {
    font-size: 0.75rem;
    color: var(--ink-soft);
    line-height: 1.5;
}

.invoice-meta {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.invoice-title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 400;
    letter-spacing: 0.1em;
    color: var(--accent);
    margin-bottom: var(--space-sm);
    line-height: 1;
}

.meta-details {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.meta-row {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-md);
    font-size: 0.85rem;
}

.meta-label {
    color: var(--ink-muted);
}

.meta-value {
    font-weight: 500;
    color: var(--ink);
    min-width: 100px;
}

.meta-row.highlight .meta-value {
    color: var(--coral);
    font-weight: 600;
}

/* Bill To Section */
.bill-to {
    margin-bottom: var(--space-xl);
}

.bill-to-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    color: var(--ink-muted);
    margin-bottom: var(--space-sm);
}

.client-info {
    max-width: 350px;
}

.client-name {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 400;
    color: var(--ink);
    margin-bottom: 4px;
}

.client-contact, .client-address {
    font-size: 0.85rem;
    color: var(--ink-soft);
    line-height: 1.6;
}

/* Services Table */
.services-section {
    margin-bottom: var(--space-xl);
}

.services-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: var(--space-md);
}

.services-table th {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-muted);
    text-align: left;
    padding: var(--space-md) var(--space-md);
    border-bottom: 2px solid var(--border-strong);
    position: relative;
    vertical-align: bottom;
}

.services-table th .header-content {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    min-height: 40px;
}

.services-table th textarea.header-input {
    background: transparent;
    border: none;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-muted);
    padding: 4px 6px;
    width: 100%;
    min-width: 50px;
    min-height: 20px;
    max-height: 80px;
    resize: none;
    overflow: hidden;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.4;
    font-family: inherit;
}

.services-table th textarea.header-input:focus {
    outline: none;
    background: var(--accent-subtle);
    border-radius: 3px;
    color: var(--ink);
}

.services-table th .header-text {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-muted);
    padding: 4px 6px;
}

.services-table th input.header-input.text-right {
    text-align: right;
}

.btn-delete-column {
    width: 16px;
    height: 16px;
    border: none;
    background: transparent;
    color: var(--ink-muted);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s;
    flex-shrink: 0;
}

.services-table th:hover .btn-delete-column {
    opacity: 1;
}

.btn-delete-column:hover {
    color: #ff4444;
}

.services-table th.col-qty,
.services-table th.col-rate,
.services-table th.col-amount,
.services-table th.text-right {
    text-align: right;
}

.services-table th.text-right .header-content {
    justify-content: flex-end;
}

.services-table td {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.services-table td.text-right,
.services-table td input.text-right {
    text-align: right;
}

.services-table .col-amount {
    text-align: right;
    font-weight: 600;
}

.services-table .col-action {
    width: 50px;
    text-align: center;
}

/* Editable cells */
.services-table td input {
    background: transparent;
    border: none;
    padding: 0;
    color: var(--ink);
    font-size: 0.9rem;
    width: 100%;
}

.services-table td input:focus {
    outline: none;
    background: var(--accent-subtle);
    border-radius: 4px;
    padding: 4px 8px;
    margin: -4px -8px;
}

.services-table td input.text-right {
    text-align: right;
}

.service-description {
    font-weight: 500;
    color: var(--ink);
}

.btn-remove-service {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--ink-muted);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-remove-service:hover {
    background: rgba(232, 93, 76, 0.1);
    color: var(--coral);
}

.btn-add-service {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.6rem 1rem;
    background: var(--accent-subtle);
    border: 1px dashed var(--accent);
    border-radius: 6px;
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}

.btn-add-service:hover {
    background: var(--accent);
    color: var(--paper);
    border-style: solid;
}

/* Totals Section */
.totals-section {
    display: flex;
    justify-content: flex-end;
    margin-bottom: var(--space-xl);
}

.totals-box {
    width: 280px;
    background: var(--paper-warm);
    border-radius: 8px;
    padding: var(--space-lg);
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: var(--space-sm) 0;
    font-size: 0.9rem;
    color: var(--ink-soft);
}

.total-row.grand-total {
    border-top: 2px solid var(--border-strong);
    margin-top: var(--space-sm);
    padding-top: var(--space-md);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ink);
}

.total-row.grand-total span:last-child {
    font-family: var(--font-display);
    font-size: 1.35rem;
    color: var(--accent);
}

/* Invoice Footer */
.invoice-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-xl);
    padding-top: var(--space-xl);
    border-top: 1px solid var(--border);
}

.footer-section h4 {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-muted);
    margin-bottom: var(--space-sm);
}

.footer-section p {
    font-size: 0.85rem;
    color: var(--ink-soft);
    line-height: 1.6;
}

.footer-signature {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
}

.signature-image-container {
    min-height: 50px;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    width: 200px;
}

.signature-image {
    max-width: 200px;
    max-height: 70px;
    object-fit: contain;
    width: auto;
    height: auto;
}

.signature-line {
    width: 200px;
    height: 2px;
    background: var(--ink);
}

.footer-signature span {
    font-size: 0.75rem;
    color: var(--ink-muted);
    margin-top: 4px;
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    body {
        background: white !important;
    }

    body * {
        visibility: hidden;
    }

    .invoice,
    .invoice * {
        visibility: visible;
    }

    .invoice {
        position: absolute;
        left: 0;
        top: 0;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 15mm !important;
        box-shadow: none !important;
        transform: none !important;
        border-radius: 0 !important;
    }

    .no-print {
        display: none !important;
    }

    .footer-signature {
        display: flex !important;
    }

    .signature-line {
        background: #000 !important;
        height: 2px !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .signature-image {
        display: block !important;
        max-width: 200px !important;
        max-height: 70px !important;
    }

    .sidebar,
    .preview-header,
    .preview-badge {
        display: none !important;
    }

    .preview-area {
        padding: 0 !important;
    }

    .invoice-wrapper {
        max-width: 100% !important;
        width: 100% !important;
    }
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: relative;
        height: auto;
        max-height: none;
    }

    .sidebar-content {
        max-height: 50vh;
    }

    .preview-area {
        padding: var(--space-lg);
    }

    .invoice {
        padding: var(--space-xl);
    }
}

@media (max-width: 640px) {
    .invoice-header {
        flex-direction: column;
        gap: var(--space-xl);
    }

    .invoice-meta {
        text-align: left;
    }

    .meta-row {
        justify-content: flex-start;
    }

    .invoice-title {
        font-size: 2rem;
    }

    .services-table {
        font-size: 0.85rem;
    }

    .services-table th,
    .services-table td {
        padding: var(--space-sm);
    }

    .totals-box {
        width: 100%;
    }

    .invoice-footer {
        grid-template-columns: 1fr;
    }

    .input-row {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Loading States & Animations
   ============================================ */



/* Focus styles */
*:focus-visible {
    outline: 2px solid #000000;
    outline-offset: 2px;
}

/* Selection styles */
::selection {
    background: var(--accent);
    color: var(--paper);
}

/* ============================================
   App Footer
   ============================================ */

.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 380px;
    padding: var(--space-sm) var(--space-lg);
    background: var(--ink);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    text-align: center;
    z-index: 100;
}

.app-footer p {
    font-size: 0.75rem;
    color: var(--ink-muted);
    margin: 0;
}

.app-footer .heart {
    color: #e25555;
    animation: heartbeat 1.5s ease-in-out infinite;
}

.app-footer a {
    color: var(--paper);
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.2s;
}

.app-footer a:hover {
    opacity: 0.8;
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@media (max-width: 1024px) {
    .app-footer {
        position: relative;
        width: 100%;
    }
}
