/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    min-height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    line-height: 1.6;
    padding-top: 84px !important;
}

/* Container Layout */
.container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 84px);
}

/* Header */
/* ── Language Dropdown ── */

.lang-dropdown {
    position: relative;
}

.lang-dropdown-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: #f0f4f8;
    border: 1px solid #dde3ea;
    border-radius: 6px;
    color: #2c3e50;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
    user-select: none;
}

.lang-dropdown-btn:hover,
.lang-dropdown.open .lang-dropdown-btn {
    background: #e4eaf1;
    border-color: #b0bec9;
}

.lang-dropdown-btn .lang-flag {
    font-size: 1.1rem;
    line-height: 1;
}

.lang-code {
    flex: 1;
    letter-spacing: 0.3px;
}

.lang-caret {
    opacity: 0.5;
    transition: transform 0.2s ease;
    flex-shrink: 0;
    color: #5a6a7a;
}

.lang-dropdown.open .lang-caret {
    transform: rotate(180deg);
}

.lang-dropdown-menu {
    position: absolute;
    top: calc(100% + 0.4rem);
    left: 0;
    background: white;
    border: 1px solid #dde3ea;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    min-width: 100%;
    z-index: 2000;
    animation: dropdown-in 0.15s ease;
}

@keyframes dropdown-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.lang-dropdown-menu[hidden] {
    display: none;
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.6rem 1rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: #2c3e50;
    text-align: left;
    transition: background 0.12s;
}

.lang-option:hover {
    background: #f0f5fa;
}

.lang-option.active {
    background: #ebf5fb;
    color: #2980b9;
    font-weight: 600;
}

.lang-option .lang-flag {
    font-size: 1.15rem;
    line-height: 1;
}

.lang-name {
    flex: 1;
}

/* Main Layout */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Sidebar */
.sidebar-app-title {
    padding: 0.8rem 1rem 0;
    font-size: 1rem;
    font-weight: 700;
    color: #2c3e50;
    letter-spacing: 0.2px;
}

.sidebar {
    width: 250px;
    background-color: #fff;
    border-right: 1px solid #e0e6ed;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.sidebar-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e0e6ed;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.sidebar-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.file-count {
    background-color: #3498db;
    color: white;
    border-radius: 20px;
    padding: 0.25rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.file-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.file-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background-color: #f8f9fa;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.file-item:hover {
    background-color: #e8ecf1;
    border-color: #bdc3c7;
}

.file-item.active {
    background-color: #3498db;
    color: white;
    border-color: #2980b9;
}

.file-item-name {
    flex: 1;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-item-remove {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.file-item-remove:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.file-item.active .file-item-remove:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Content Area */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Drop Zone */
.drop-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    margin: 2rem;
    border: 2px dashed #bdc3c7;
    border-radius: 12px;
    background-color: #f8f9fa;
    transition: all 0.3s ease;
    cursor: pointer;
}

.drop-zone.drag-over {
    border-color: #3498db;
    background-color: #ecf0f1;
    box-shadow: 0 0 20px rgba(52, 152, 219, 0.2);
}

.drop-zone-content {
    text-align: center;
}

.drop-icon {
    width: 64px;
    height: 64px;
    color: #95a5a6;
    margin-bottom: 1rem;
    transition: color 0.3s ease;
}

.drop-zone.drag-over .drop-icon {
    color: #3498db;
}

.drop-zone h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.drop-zone p {
    color: #7f8c8d;
    margin-bottom: 1rem;
}

.file-input-label {
    display: inline-block;
    padding: 0.75rem 2rem;
    background-color: #3498db;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s ease;
}

.file-input-label:hover {
    background-color: #2980b9;
}

/* Viewer Container */
.viewer-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    background-color: white;
    margin: 0 2rem 2rem 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* Tabs Container */
.tabs-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #e0e6ed;
    background-color: #f8f9fa;
    padding: 0 1rem;
    gap: 1rem;
}

/* Tabs */
.tabs {
    display: flex;
    flex: 1;
}

.tab-button {
    padding: 1rem 2rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: #7f8c8d;
    transition: all 0.2s ease;
    border-bottom: 3px solid transparent;
    position: relative;
    bottom: -1px;
}

.tab-button:hover {
    color: #2c3e50;
    background-color: white;
}

.tab-button.active {
    color: #3498db;
    border-bottom-color: #3498db;
    background-color: white;
}

/* Tab Actions */
.tabs-actions {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 0;
}

.action-button {
    padding: 0.6rem 1.2rem;
    background-color: white;
    border: 1px solid #e0e6ed;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.action-button:hover {
    background-color: #f8f9fa;
    border-color: #bdc3c7;
}

.pdf-button:active {
    transform: scale(0.98);
}

.print-button:active {
    transform: scale(0.98);
}

/* Generating state */
.action-button.generating {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* Tab Content */
.tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: none;
}

.tab-content.active {
    display: block;
}

/* Parsed View Styling */
#parsedTab {
    padding: 0;
}

#parsedContent {
    height: 100%;
}

.invoice-section {
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #e0e6ed;
}

.invoice-section:last-child {
    border-bottom: none;
}

.section-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #3498db;
    display: inline-block;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.info-item {
    padding: 1rem;
    background-color: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #3498db;
}

.info-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.info-value {
    font-size: 1rem;
    color: #2c3e50;
    word-break: break-word;
}

.address-block {
    padding: 1rem;
    background-color: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #3498db;
    margin-bottom: 1rem;
}

.address-block h3 {
    font-size: 1rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 0.75rem;
}

.address-line {
    font-size: 0.95rem;
    color: #555;
    margin-bottom: 0.25rem;
}

/* Table Styling */
.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.95rem;
}

.invoice-table thead {
    background-color: #34495e;
    color: white;
}

.invoice-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
}

.invoice-table td {
    padding: 1rem;
    border-bottom: 1px solid #e0e6ed;
}

.invoice-table tbody tr:hover {
    background-color: #f8f9fa;
}

.number-cell {
    text-align: right;
    font-family: 'Courier New', monospace;
}

.center-cell {
    text-align: center;
}

/* Tax Summary */
.tax-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin: 1.5rem 0;
}

.tax-item {
    padding: 1.5rem;
    background: linear-gradient(135deg, #ecf0f1 0%, #bdc3c7 100%);
    border-radius: 8px;
    text-align: center;
}

.tax-rate {
    font-size: 0.9rem;
    color: #7f8c8d;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.tax-amount {
    font-size: 1.5rem;
    color: #2c3e50;
    font-weight: 700;
}

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

.total-item {
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
    border: 2px solid #e0e6ed;
}

.total-item.highlight {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
    border-color: #2980b9;
}

.total-label {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    opacity: 0.9;
    margin-bottom: 0.5rem;
}

.total-amount {
    font-size: 1.8rem;
    font-weight: 700;
}

/* ── XML Table (Parsed View) ── */

.xml-tree {
    font-size: 0.88rem;
}

.xml-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

/* Sticky column header */
.xml-table-head th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #2c3e50;
    color: white;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 2px solid #1a252f;
}

.xml-table-head th:nth-child(1) { width: 18%; }
.xml-table-head th:nth-child(2) { width: 18%; }
.xml-table-head th:nth-child(3) { width: 42%; }
.xml-table-head th:nth-child(4) { width: 22%; }

/* Section header rows (container elements) */
.xml-section-row td {
    padding: 0.45rem 0.75rem;
    font-weight: 700;
    border-bottom: 1px solid transparent;
}

.xml-section-root td {
    background: #2c3e50;
    color: white;
    font-size: 0.85rem;
}

.xml-section-level1 td {
    background: #34495e;
    color: white;
    font-size: 0.83rem;
}

.xml-section-nested td {
    background: #ecf0f1;
    color: #2c3e50;
    font-size: 0.82rem;
    border-bottom: 1px solid #dde3ea;
}

.xml-section-tag {
    font-family: 'Courier New', monospace;
}

.xml-section-root .xml-section-tag,
.xml-section-level1 .xml-section-tag {
    color: #7ecbff;
}

.xml-section-nested .xml-section-tag {
    color: #2980b9;
}

.xml-section-label {
    font-style: normal;
}

.xml-section-desc {
    font-style: italic;
    opacity: 0.8;
    font-weight: 400;
    font-size: 0.8rem;
}

.xml-group-attrs {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    opacity: 0.7;
    margin-left: 0.4rem;
}

/* Data rows (leaf elements) */
.xml-row:hover td {
    background: #f0f7ff;
}

.xml-row td {
    padding: 0.38rem 0.75rem;
    border-bottom: 1px solid #f0f2f5;
    vertical-align: middle;
}

.xml-cell-tag {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: #2980b9;
    font-weight: 600;
    word-break: break-all;
}

.xml-cell-label {
    font-weight: 600;
    color: #2c3e50;
}

.xml-cell-desc {
    color: #7f8c8d;
    font-style: italic;
    font-size: 0.83rem;
}

.xml-cell-value {
    font-weight: 500;
    color: #1a1a1a;
    text-align: right;
    word-break: break-word;
}

/* ── Invoice View Tab ── */

.invoice-tab-content {
    padding: 0 !important;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.invoice-tab-content.active {
    display: flex !important;
}

.invoice-pdf-frame {
    flex: 1 1 0;   /* 0 base overrides iframe intrinsic size so flex fills correctly */
    width: 100%;
    border: none;
    min-height: 0;
}

.invoice-pdf-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 200px;
    color: #7f8c8d;
    font-size: 1rem;
}

.invoice-pdf-spinner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}

.invoice-pdf-error {
    margin: 2rem;
    padding: 1.5rem;
    background-color: #fadbd8;
    border-left: 4px solid #e74c3c;
    border-radius: 6px;
    color: #c0392b;
    font-weight: 500;
}


/* Raw XML View */
#xmlContent {
    background-color: #282c34;
    color: #abb2bf;
    padding: 1.5rem;
    border-radius: 6px;
    overflow-x: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Syntax Highlighting */
.xml-tag {
    color: #61afef;
}

.xml-attribute {
    color: #56b6c2;
}

.xml-value {
    color: #98c379;
}

.xml-text {
    color: #e06c75;
}

.xml-comment {
    color: #5c6370;
}

/* Messages */
.error-message {
    padding: 1.5rem;
    margin: 2rem;
    background-color: #fadbd8;
    border-left: 4px solid #e74c3c;
    border-radius: 6px;
    color: #c0392b;
    font-weight: 500;
}

.success-message {
    padding: 1.5rem;
    margin: 2rem;
    background-color: #d5f4e6;
    border-left: 4px solid #27ae60;
    border-radius: 6px;
    color: #1e8449;
    font-weight: 500;
}

/* Footer */
.footer {
    background-color: #f8f9fa;
    border-top: 1px solid #e0e6ed;
    padding: 1.5rem;
    text-align: center;
    color: #7f8c8d;
    font-size: 0.9rem;
}

/* Print Styles */
@media print {
    body {
        padding-top: 0 !important;
    }

    .navbar,
    .header,
    .sidebar,
    .tabs,
    .tabs-container,
    .tabs-actions,
    .footer,
    .drop-zone,
    .file-input-label,
    .error-message,
    .success-message {
        display: none;
    }

    .main-layout {
        flex-direction: column;
    }

    .content {
        margin: 0;
    }

    .viewer-container {
        margin: 0;
        box-shadow: none;
        border-radius: 0;
    }

    .tab-content {
        padding: 0;
        display: block !important;
    }

    #parsedContent {
        max-width: 100%;
    }

    body {
        background-color: white;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e0e6ed;
        max-height: 200px;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .drop-zone {
        margin: 1rem;
        padding: 2rem 1rem;
    }

    .viewer-container {
        margin: 1rem;
    }

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

    .tab-button {
        padding: 0.75rem 1.5rem;
        font-size: 0.9rem;
    }

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

    .tax-summary {
        grid-template-columns: 1fr;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #bdc3c7;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}
