/* --- THEME VARIABLES (Light Mode Default) --- */
:root {
    --color-bg: #f4f7fc;
    --color-surface: #ffffff;
    --color-surface-alt: #e9ecef;
    --color-border: #dee2e6;
    --color-text-primary: #212529;
    --color-text-secondary: #495057;
    --color-text-tertiary: #6c757d;
    --color-accent: #007bff;
    --color-accent-hover: #0056b3;
    --color-success: #28a745;
    --color-danger: #dc3545;
    --color-warning: #ffc107;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --card-shadow: 0 4px 15px var(--shadow-color);
    --btn-shadow: 0 2px 5px var(--shadow-color);
    --font-primary: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
      Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    --font-monospace: 'SF Mono', ui-monospace, SFMono-Regular, Menlo, Monaco,
      Consolas, 'Liberation Mono', 'Courier New', monospace;
  }
  body.dark-mode {
    --color-bg: #1e1e2f;
    --color-surface: #27293d;
    --color-surface-alt: #3b3e5e;
    --color-border: #4d4f7c;
    --color-text-primary: #f0f0f0;
    --color-text-secondary: #a0a0c0;
    --color-text-tertiary: #7070a0;
    --color-accent: #82aaff;
    --color-accent-hover: #9acdff;
    --color-success: #50fa7b;
    --color-danger: #ff5555;
    --color-warning: #f1fa8c;
    --shadow-color: rgba(0, 0, 0, 0.25);
  }
  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  body {
    font-family: var(--font-primary);
    background-color: var(--color-bg);
    color: var(--color-text-primary);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-size: 16px;
    transition: background-color 0.3s ease, color 0.3s ease;
  }
  a {
    color: var(--color-accent);
    text-decoration: none;
  }
  a:hover {
    text-decoration: underline;
    color: var(--color-accent-hover);
  }
  
  /* --- Resizing Utility Class --- */
  body.is-resizing * {
    user-select: none; /* Prevents text selection during drag */
    cursor: col-resize !important;
  }
  
  /* --- Shared Styles --- */
  .app-header {
    background-color: var(--color-surface);
    padding: 12px 25px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 20px;
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 2px 5px var(--shadow-color);
    flex-shrink: 0;
    height: 70px;
  }
  .app-header .header-left {
    display: flex;
    justify-content: flex-start;
  }
  .app-header .header-center {
    text-align: center;
  }
  .app-header .header-right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 15px;
  }
  .app-header .logo {
    max-height: 40px;
  }
  .app-header .app-title {
    font-size: 1.25em;
    font-weight: 600;
    margin: 0;
  }
  .card {
    background-color: var(--color-surface);
    padding: 25px;
    border-radius: 10px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--color-border);
  }
  .btn {
    padding: 10px 20px;
    margin: 0; /* Remove default margin */
    cursor: pointer;
    font-size: 0.95em;
    border-radius: 6px;
    border: 1px solid transparent;
    font-weight: 500;
    background-color: var(--color-surface-alt);
    color: var(--color-text-secondary);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .btn:hover:not(:disabled) {
    box-shadow: var(--btn-shadow);
    transform: translateY(-2px);
  }
  .btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
  }
  .btn-primary {
    background-color: var(--color-accent);
    color: white;
  }
  body.dark-mode .btn-primary {
    color: #1e1e2f;
  }
  .btn-primary:hover:not(:disabled) {
    background-color: var(--color-accent-hover);
  }
  .btn-success {
    background-color: var(--color-success);
    color: white;
  }
  body.dark-mode .btn-success {
    color: #1e1e2f;
  }
  .btn-sm {
    padding: 6px 12px;
    font-size: 0.85em;
  }
  .btn i {
    margin-right: 8px;
  }
  .btn.copied {
    background-color: var(--color-success) !important;
    color: white !important;
  }
  body.dark-mode .btn.copied {
    color: #1e1e2f !important;
  }
  .btn-theme-toggle {
    background-color: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    padding: 0;
    box-shadow: none;
  }
  .btn-theme-toggle:hover:not(:disabled) {
    color: var(--color-text-primary);
    transform: translateY(-2px) rotate(15deg);
    box-shadow: var(--btn-shadow);
  }
  .btn-theme-toggle i {
    margin: 0;
  }
  .input-group {
    margin-bottom: 20px;
    text-align: left;
  }
  .input-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9em;
    color: var(--color-text-secondary);
  }
  .input-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background-color: var(--color-bg);
    color: var(--color-text-primary);
    font-size: 1rem;
  }
  .error-message {
    color: var(--color-danger);
    font-size: 0.85em;
    margin-top: 5px;
    min-height: 1.2em;
  }
  
  /* --- Login & Upload Pages --- */
  .login-header {
    text-align: center;
    padding: 30px 20px 10px;
    position: relative;
  }
  .login-header .logo {
    max-height: 80px;
    margin-bottom: 10px;
  }
  .login-header-actions {
    position: absolute;
    top: 15px;
    right: 15px;
  }
  .login-container {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    padding-top: 2vh;
  }
  .form-box {
    max-width: 400px;
    width: 100%;
    text-align: center;
  }
  .password-wrapper {
    position: relative;
  }
  .toggle-password {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-tertiary);
    cursor: pointer;
  }
  #uploadPage,
  #processorPage {
    display: flex;
    flex-direction: column;
    height: 100vh;
  }
  .upload-container {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
  }
  .upload-box {
    text-align: center;
    max-width: 500px;
    width: 100%;
    padding: 40px 30px;
    border: 2px dashed var(--color-border);
    transition: background-color 0.2s ease, border-color 0.2s ease;
  }
  .upload-box.drag-over {
    border-color: var(--color-accent);
    background-color: var(--color-bg);
  }
  .upload-icon {
    font-size: 4em;
    color: var(--color-accent);
    margin-bottom: 20px;
  }
  .upload-input-hidden {
    display: none;
  }
  .file-info {
    margin-top: 15px;
    font-weight: 500;
    color: var(--color-text-secondary);
    min-height: 1.2em;
  }
  #processFileBtn {
    margin-top: 10px;
    width: 100%;
    padding: 12px;
    font-size: 1rem;
  }
  
  /* --- Processor Page & Resizable Panes --- */
  .processor-layout-container {
    display: flex;
    gap: 0;
    flex-grow: 1;
    padding: 20px;
    height: calc(100vh - 70px);
    overflow: hidden;
  }
  .card-pane {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background-color: var(--color-surface);
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: 50%;
  }
  .pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    padding: 0 20px;
    height: 50px;
    border-bottom: 1px solid var(--color-border);
  }
  .pdf-preview-pane .pane-header h3 {
    line-height: 50px;
  }
  .pdf-preview-area {
    flex-grow: 1;
    background-color: var(--color-bg);
    padding: 15px;
  }
  #pdfPreviewFrame {
    width: 100%;
    height: 100%;
    border: none;
  }
  
  #pane-resizer {
    flex-basis: 8px;
    flex-shrink: 0;
    cursor: col-resize;
    background-color: transparent;
    transition: background-color 0.2s ease;
    position: relative;
  }
  #pane-resizer:hover,
  body.is-resizing #pane-resizer {
    background-color: var(--color-accent);
    opacity: 0.5;
  }
  
  /* --- Polished Tab UI --- */
  .tab-navigation {
    display: flex;
    height: 100%;
  }
  .tab-btn {
    position: relative;
    padding: 0 16px;
    cursor: pointer;
    border: none;
    background-color: transparent;
    color: var(--color-text-tertiary);
    font-weight: 500;
    display: flex;
    align-items: center;
    transition: color 0.2s ease, font-weight 0.2s ease;
  }
  .tab-btn:hover {
    color: var(--color-text-primary);
  }
  .tab-btn::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background-color: var(--color-accent);
    transform: scaleX(0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  }
  .tab-btn.active {
    color: var(--color-text-primary);
    font-weight: 600;
  }
  .tab-btn.active::after {
    transform: scaleX(1);
  }
  .pane-actions {
    display: flex;
    gap: 8px;
  }
  
  .output-wrapper {
    flex-grow: 1;
    overflow: hidden;
    position: relative;
    padding: 20px;
    background-color: var(--color-bg);
  }
  .tab-content {
    display: none;
    height: 100%;
    overflow-y: auto;
  }
  .tab-content.active {
    display: block;
  }
  
  /* FIX: CSS Background Bug Fix */
  #jsonView {
    display: none;
    height: 100%; /* Ensure container takes full height */
  }
  #jsonView.active {
    display: flex; /* Use flex to make child fill height */
    flex-direction: column;
  }
  #jsonView pre {
    margin: 0;
    font-family: var(--font-monospace);
    font-size: 0.9em;
    color: var(--color-text-secondary);
    width: 100%;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    background-color: var(--color-surface);
    padding: 15px;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    flex-grow: 1; /* Allow pre to grow and fill space */
    overflow-y: auto; /* Put the scrollbar on the pre tag itself */
  }
  
  .spinner-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
  }
  .spinner {
    display: inline-block;
    border: 5px solid var(--color-surface-alt);
    border-top: 5px solid var(--color-accent);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
  }
  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }
  
  /* --- Table Styles --- */
  .invoice-details-table,
  .invoice-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 25px;
    font-size: 0.9em;
    background-color: var(--color-surface);
  }
  .invoice-details-table th,
  .invoice-details-table td,
  .invoice-items-table th,
  .invoice-items-table td {
    border: 1px solid var(--color-border);
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
  }
  .invoice-details-table th {
    width: 30%;
    font-weight: 600;
    background-color: var(--color-surface-alt);
    color: var(--color-text-secondary);
  }
  .invoice-items-table thead th {
    background-color: var(--color-surface-alt);
    color: var(--color-text-secondary);
    font-weight: 600;
    position: sticky;
    top: -1px; /* Adjust for scroll container padding */
  }
  .invoice-items-table tbody tr:hover {
    background-color: var(--color-surface-alt);
  }
  .notes-section {
    margin-top: 20px;
    padding: 15px;
    background-color: var(--color-surface);
    border-radius: 6px;
    border-left: 4px solid var(--color-warning);
  }
  .notes-section h4 {
    margin-top: 0;
    margin-bottom: 5px;
    color: var(--color-text-primary);
  }
  .table-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border);
  }
  
  /* --- Mobile Navigation & Responsive --- */
  .mobile-nav {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    height: 100%;
    background-color: var(--color-surface);
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
    padding: 20px;
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    z-index: 1001;
    border-left: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .mobile-nav.is-open {
    transform: translateX(0);
  }
  .mobile-nav h3 {
    font-weight: 600;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 10px;
    margin-bottom: 0;
  }
  .mobile-nav .btn {
    width: 100%;
    justify-content: flex-start;
    margin: 0;
    padding: 12px 16px;
    text-align: left;
  }
  .mobile-nav .btn i {
    width: 20px;
    margin-right: 15px;
    text-align: center;
  }
  
  .overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    z-index: 1000;
  }
  .overlay.is-active {
    opacity: 1;
    visibility: visible;
  }
  .btn-mobile-menu {
    display: none;
  } /* Hide mobile menu by default */
  
  @media (max-width: 1024px) {
    .processor-layout-container {
      flex-direction: column;
      height: auto;
      overflow-y: auto;
      gap: 20px;
    }
    .card-pane {
      flex-basis: auto !important;
      min-height: 500px;
    }
    #pane-resizer {
      display: none;
    }
  }
  
  @media (max-width: 768px) {
    .app-header .header-center {
      display: none;
    }
    /* Hide desktop-only buttons */
    .app-header .header-right .btn:not(.btn-mobile-menu) {
      display: none;
    }
    /* Show mobile menu button */
    .app-header .header-right .btn-mobile-menu {
      display: inline-flex;
    }
    .mobile-nav h3 {
      display: block;
    } /* Show "Menu" title in sidebar */
  }
  