:root {
      /* Light Theme (Default) */
      --color-bg-primary: #f8fafc;
      --color-bg-secondary: #ffffff;
      --color-bg-tertiary: #f1f5f9;
      --color-bg-card: #ffffff;
      --color-bg-elevated: #ffffff;
      --color-border: rgba(0, 0, 0, 0.08);
      --color-border-focus: rgba(14, 165, 233, 0.5);
      --color-text-primary: #0f172a;
      --color-text-secondary: #475569;
      --color-text-muted: #94a3b8;
      --color-accent: #0ea5e9;
      --color-accent-hover: #38bdf8;
      --color-accent-glow: rgba(14, 165, 233, 0.15);
      --color-accent-secondary: #1e40af;
      --color-error: #ef4444;
      --color-error-bg: rgba(239, 68, 68, 0.1);
      --color-success: #10b981;
      --color-success-bg: rgba(16, 185, 129, 0.1);
      --color-warning: #f59e0b;
      --color-warning-bg: rgba(245, 158, 11, 0.1);
      --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
      --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
      --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
      --header-bg: rgba(255, 255, 255, 0.9);
      --orb-opacity: 0.15;
    }

    [data-theme="dark"] {
      --color-bg-primary: #0a0f1a;
      --color-bg-secondary: #111827;
      --color-bg-tertiary: #1a2332;
      --color-bg-card: #161f2e;
      --color-bg-elevated: #1e2a3d;
      --color-border: rgba(255, 255, 255, 0.08);
      --color-border-focus: rgba(14, 165, 233, 0.5);
      --color-text-primary: #f8fafc;
      --color-text-secondary: #94a3b8;
      --color-text-muted: #64748b;
      --color-accent: #0ea5e9;
      --color-accent-hover: #38bdf8;
      --color-accent-glow: rgba(14, 165, 233, 0.2);
      --color-accent-secondary: #3b82f6;
      --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
      --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
      --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
      --header-bg: rgba(10, 15, 26, 0.9);
      --orb-opacity: 0.3;
    }

    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    body {
      font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
      background: var(--color-bg-primary);
      color: var(--color-text-primary);
      line-height: 1.5;
      min-height: 100vh;
      -webkit-font-smoothing: antialiased;
      transition: background-color 0.3s ease, color 0.3s ease;
    }

    .invoice-portal { position: relative; overflow-x: hidden; }

    .ambient-bg {
      position: fixed;
      inset: 0;
      pointer-events: none;
      z-index: 0;
      overflow: hidden;
    }

    .gradient-orb {
      position: absolute;
      border-radius: 50%;
      filter: blur(100px);
      opacity: var(--orb-opacity);
      transition: opacity 0.3s ease;
    }

    .orb-1 {
      width: 600px;
      height: 600px;
      background: radial-gradient(circle, #0ea5e9 0%, transparent 70%);
      top: -200px;
      right: -100px;
      animation: float 20s ease-in-out infinite;
    }

    .orb-2 {
      width: 400px;
      height: 400px;
      background: radial-gradient(circle, #1e40af 0%, transparent 70%);
      bottom: -100px;
      left: -100px;
      animation: float 25s ease-in-out infinite reverse;
    }

    .orb-3 {
      width: 300px;
      height: 300px;
      background: radial-gradient(circle, #7c3aed 0%, transparent 70%);
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      animation: pulse 15s ease-in-out infinite;
    }

    @keyframes float {
      0%, 100% { transform: translate(0, 0); }
      33% { transform: translate(30px, -30px); }
      66% { transform: translate(-20px, 20px); }
    }

    @keyframes pulse {
      0%, 100% { opacity: calc(var(--orb-opacity) * 0.8); transform: translate(-50%, -50%) scale(1); }
      50% { opacity: var(--orb-opacity); transform: translate(-50%, -50%) scale(1.1); }
    }

    .portal-header {
      position: sticky;
      top: 0;
      z-index: 100;
      background: var(--header-bg);
      backdrop-filter: blur(20px);
      border-bottom: 1px solid var(--color-border);
      transition: background-color 0.3s ease;
    }

    .header-content {
      max-width: 1400px;
      margin: 0 auto;
      padding: 0.75rem 2rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .logo-section {
      display: flex;
      align-items: center;
      gap: 1rem;
    }

    .company-logo {
      height: 40px;
      width: auto;
      object-fit: contain;
    }

    .logo-divider {
      width: 1px;
      height: 32px;
      background: var(--color-border);
      margin: 0 0.5rem;
    }

    .portal-title {
      display: flex;
      flex-direction: column;
    }

    .portal-title h1 {
      font-size: 1rem;
      font-weight: 600;
      letter-spacing: -0.01em;
      color: var(--color-text-primary);
    }

    .portal-title .subtitle {
      font-size: 0.7rem;
      color: var(--color-text-muted);
      text-transform: uppercase;
      letter-spacing: 0.08em;
    }

    .header-actions {
      display: flex;
      align-items: center;
      gap: 1rem;
    }

    /* Theme Toggle */
    .theme-toggle {
      position: relative;
      width: 56px;
      height: 28px;
      background: var(--color-bg-tertiary);
      border: 1px solid var(--color-border);
      border-radius: 100px;
      cursor: pointer;
      transition: all 0.3s ease;
      display: flex;
      align-items: center;
      padding: 2px;
    }

    .theme-toggle:hover {
      border-color: var(--color-accent);
    }

    .theme-toggle-thumb {
      position: absolute;
      width: 22px;
      height: 22px;
      background: var(--color-accent);
      border-radius: 50%;
      transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
      left: 2px;
    }

    [data-theme="dark"] .theme-toggle-thumb {
      transform: translateX(28px);
    }

    .theme-toggle-thumb svg {
      width: 14px;
      height: 14px;
    }

    .theme-toggle-icons {
      display: flex;
      justify-content: space-between;
      width: 100%;
      padding: 0 6px;
      color: var(--color-text-muted);
    }

    .theme-toggle-icons svg {
      width: 14px;
      height: 14px;
    }

    .status-pill {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.5rem 1rem;
      background: var(--color-success-bg);
      border: 1px solid rgba(16, 185, 129, 0.3);
      border-radius: 100px;
      font-size: 0.75rem;
      font-weight: 500;
      color: var(--color-success);
    }

    .status-dot {
      width: 6px;
      height: 6px;
      background: var(--color-success);
      border-radius: 50%;
      animation: blink 2s ease-in-out infinite;
    }

    @keyframes blink {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.4; }
    }

    .portal-main {
      position: relative;
      z-index: 1;
      max-width: 1200px;
      margin: 0 auto;
      padding: 2rem;
    }

    .section-nav {
      display: flex;
      gap: 0.5rem;
      margin-bottom: 2rem;
      padding: 0.25rem;
      background: var(--color-bg-secondary);
      border-radius: 16px;
      border: 1px solid var(--color-border);
      box-shadow: var(--shadow-sm);
      transition: all 0.3s ease;
    }

    .nav-tab {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 0.5rem;
      padding: 1rem 1.5rem;
      background: transparent;
      border: none;
      border-radius: 12px;
      color: var(--color-text-muted);
      font-family: inherit;
      font-size: 0.875rem;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .nav-tab:hover {
      color: var(--color-text-secondary);
    }

    .nav-tab.active {
      background: var(--color-bg-elevated);
      color: var(--color-text-primary);
      box-shadow: var(--shadow-md);
    }

    .nav-tab.active svg {
      color: var(--color-accent);
    }

    .item-count {
      padding: 2px 8px;
      background: var(--color-accent);
      color: white;
      border-radius: 100px;
      font-size: 0.75rem;
      font-weight: 600;
    }

    .form-section {
      display: none;
      animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .form-section.active { display: block; }

    @keyframes fadeInUp {
      from { opacity: 0; transform: translateY(20px); }
      to { opacity: 1; transform: translateY(0); }
    }

    .section-header {
      margin-bottom: 2rem;
    }

    .section-header h2 {
      font-size: 1.5rem;
      font-weight: 600;
      letter-spacing: -0.02em;
      margin-bottom: 0.25rem;
    }

    .section-header p {
      color: var(--color-text-muted);
      font-size: 0.9375rem;
    }

    .header-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .form-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 1.5rem;
    }

    .form-group {
      display: flex;
      flex-direction: column;
      gap: 0.5rem;
    }

    .form-group.full-width {
      grid-column: 1 / -1;
    }

    .form-group label {
      font-size: 0.8125rem;
      font-weight: 500;
      color: var(--color-text-secondary);
      display: flex;
      align-items: center;
      gap: 0.25rem;
    }

    .required { color: var(--color-error); }

    .input-wrapper {
      position: relative;
    }

    input, textarea, select {
      width: 100%;
      padding: 0.875rem 1rem;
      background: var(--color-bg-secondary);
      border: 1px solid var(--color-border);
      border-radius: 10px;
      color: var(--color-text-primary);
      font-family: inherit;
      font-size: 0.9375rem;
      transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    }

    input::placeholder, textarea::placeholder {
      color: var(--color-text-muted);
    }

    input:hover, textarea:hover, select:hover {
      border-color: rgba(14, 165, 233, 0.3);
    }

    input:focus, textarea:focus, select:focus {
      outline: none;
      border-color: var(--color-border-focus);
      box-shadow: 0 0 0 3px var(--color-accent-glow);
    }

    input.error, textarea.error, select.error {
      border-color: var(--color-error);
    }

    input.valid, select.valid {
      border-color: var(--color-success);
    }

    textarea {
      resize: vertical;
      min-height: 80px;
    }

    select {
      appearance: none;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 1rem center;
      padding-right: 2.5rem;
      cursor: pointer;
    }

    select option {
      background: var(--color-bg-secondary);
      color: var(--color-text-primary);
    }

    .input-wrapper.currency {
      position: relative;
    }

    .input-wrapper.currency input {
      padding-left: 4.5rem;
    }

    .currency-selector {
      position: absolute;
      left: 1px;
      top: 1px;
      bottom: 1px;
      display: flex;
      align-items: center;
    }

    .currency-selector select {
      border: none;
      background: var(--color-bg-tertiary);
      border-radius: 9px 0 0 9px;
      padding: 0 0.5rem 0 0.75rem;
      font-size: 0.75rem;
      font-weight: 600;
      color: var(--color-text-secondary);
      height: 100%;
      min-width: 60px;
      cursor: pointer;
    }

    .currency-selector select:focus {
      outline: none;
      box-shadow: none;
    }

    .hint {
      font-size: 0.75rem;
      color: var(--color-text-muted);
    }

    .error-text {
      font-size: 0.75rem;
      color: var(--color-error);
    }

    .section-actions {
      display: flex;
      justify-content: flex-end;
      gap: 1rem;
      margin-top: 3rem;
      padding-top: 2rem;
      border-top: 1px solid var(--color-border);
    }

    .btn-primary, .btn-ghost, .btn-add, .btn-submit, .btn-validate {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 0.5rem;
      font-family: inherit;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
      border: none;
    }

    .btn-primary {
      padding: 1rem 1.5rem;
      background: linear-gradient(135deg, var(--color-accent), #0284c7);
      color: white;
      border-radius: 10px;
      font-size: 0.9375rem;
    }

    .btn-primary:hover {
      transform: translateY(-1px);
      box-shadow: 0 4px 20px var(--color-accent-glow);
    }

    .btn-ghost {
      padding: 1rem 1.5rem;
      background: transparent;
      color: var(--color-text-secondary);
      border-radius: 10px;
      font-size: 0.9375rem;
      border: 1px solid var(--color-border);
    }

    .btn-ghost:hover {
      background: var(--color-bg-secondary);
      color: var(--color-text-primary);
      border-color: var(--color-accent);
    }

    .btn-add {
      padding: 0.5rem 1rem;
      background: var(--color-accent-glow);
      color: var(--color-accent);
      border-radius: 10px;
      font-size: 0.875rem;
      border: 1px solid rgba(14, 165, 233, 0.3);
    }

    .btn-add:hover {
      background: var(--color-accent);
      color: white;
    }

    .btn-validate {
      padding: 1rem 2rem;
      background: var(--color-warning-bg);
      color: var(--color-warning);
      border: 1px solid rgba(245, 158, 11, 0.3);
      border-radius: 10px;
      font-size: 1rem;
      font-weight: 600;
      min-width: 180px;
    }

    .btn-validate:hover:not(:disabled) {
      background: var(--color-warning);
      color: white;
      transform: translateY(-1px);
      box-shadow: 0 4px 20px rgba(245, 158, 11, 0.3);
    }

    .btn-submit {
      padding: 1rem 2rem;
      background: linear-gradient(135deg, var(--color-accent), #0284c7);
      color: white;
      border-radius: 10px;
      font-size: 1rem;
      font-weight: 600;
      min-width: 180px;
    }

    .btn-submit:hover:not(:disabled) {
      transform: translateY(-2px);
      box-shadow: 0 8px 30px var(--color-accent-glow);
    }

    .btn-submit:disabled, .btn-validate:disabled {
      opacity: 0.7;
      cursor: not-allowed;
    }

    .btn-icon {
      width: 32px;
      height: 32px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      background: var(--color-bg-tertiary);
      color: var(--color-text-muted);
      border-radius: 6px;
      border: none;
      cursor: pointer;
      transition: all 0.25s;
    }

    .btn-icon:hover {
      background: var(--color-bg-elevated);
      color: var(--color-text-primary);
    }

    .btn-icon.danger:hover {
      background: var(--color-error-bg);
      color: var(--color-error);
    }

    .items-container {
      display: flex;
      flex-direction: column;
      gap: 1rem;
    }

    .item-card {
      background: var(--color-bg-card);
      border: 1px solid var(--color-border);
      border-radius: 16px;
      overflow: visible;
      transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
      box-shadow: var(--shadow-sm);
    }

    .item-card:hover {
      border-color: rgba(14, 165, 233, 0.2);
    }

    .item-card.expanded {
      border-color: var(--color-border-focus);
      box-shadow: var(--shadow-lg);
    }

    .item-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 1rem 1.5rem;
      cursor: pointer;
      transition: background 0.15s;
    }

    .item-header:hover {
      background: var(--color-bg-tertiary);
    }

    .item-summary {
      display: flex;
      align-items: center;
      gap: 1rem;
    }

    .item-number {
      width: 32px;
      height: 32px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: var(--color-accent-glow);
      color: var(--color-accent);
      border-radius: 6px;
      font-size: 0.8125rem;
      font-weight: 600;
      font-family: 'JetBrains Mono', monospace;
    }

    .item-info {
      display: flex;
      flex-direction: column;
      gap: 2px;
    }

    .item-desc {
      font-weight: 500;
      color: var(--color-text-primary);
    }

    .item-meta {
      font-size: 0.8125rem;
      color: var(--color-text-muted);
      font-family: 'JetBrains Mono', monospace;
    }

    .item-actions {
      display: flex;
      align-items: center;
      gap: 0.5rem;
    }

    .expand-icon {
      display: flex;
      color: var(--color-text-muted);
      transition: transform 0.25s;
    }

    .item-card.expanded .expand-icon {
      transform: rotate(180deg);
    }

    .item-body {
      padding: 1.5rem;
      background: var(--color-bg-secondary);
      border-top: 1px solid var(--color-border);
    }
    @keyframes slideIn {
      from { opacity: 0; transform: scale(0.95); }
      to { opacity: 1; transform: scale(1); }
    }

    .item-grid {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 1.5rem;
    }

    .item-grid .form-group.span-2 {
      grid-column: span 2;
    }

    .item-grid input,
    .item-grid select {
      padding: 0.625rem 1rem;
      background: var(--color-bg-tertiary);
      font-size: 0.875rem;
    }

    .item-grid .input-wrapper.currency input {
      padding-left: 4.5rem;
    }

    .summary-card {
      margin-top: 2rem;
      padding: 1.5rem;
      background: var(--color-bg-card);
      border: 1px solid var(--color-border);
      border-radius: 16px;
      box-shadow: var(--shadow-sm);
    }

    .summary-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0.5rem 0;
    }

    .summary-row:not(:last-child) {
      border-bottom: 1px solid var(--color-border);
    }

    .summary-row.total {
      padding-top: 1rem;
      margin-top: 0.5rem;
      border-bottom: none;
    }

    .summary-row.total .summary-label {
      font-size: 1rem;
      font-weight: 600;
      color: var(--color-text-primary);
    }

    .summary-row.total .summary-value {
      font-size: 1.25rem;
      font-weight: 700;
      color: var(--color-accent);
    }

    .summary-label {
      color: var(--color-text-secondary);
      font-size: 0.875rem;
    }

    .summary-value {
      font-family: 'JetBrains Mono', monospace;
      font-weight: 600;
      color: var(--color-text-primary);
    }

    .summary-value.tax {
      color: var(--color-warning);
    }

    /* Final Actions */
    .final-actions {
      display: flex;
      gap: 1rem;
      margin-top: 2rem;
      padding-top: 2rem;
      border-top: 1px solid var(--color-border);
    }

    .final-actions .btn-validate {
      flex: 1;
    }

    .final-actions .btn-submit {
      flex: 1;
    }

    /* Validation Results */
    .validation-results {
      margin-top: 1.5rem;
      padding: 1rem;
      border-radius: 10px;
      display: none;
    }

    .validation-results.show {
      display: block;
      animation: slideIn 0.2s ease-out;
    }

    .validation-results.success {
      background: var(--color-success-bg);
      border: 1px solid rgba(16, 185, 129, 0.3);
    }

    .validation-results.error {
      background: var(--color-error-bg);
      border: 1px solid rgba(239, 68, 68, 0.3);
    }

    .validation-header {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      font-weight: 600;
      margin-bottom: 0.5rem;
    }

    .validation-results.success .validation-header {
      color: var(--color-success);
    }

    .validation-results.error .validation-header {
      color: var(--color-error);
    }

    .validation-list {
      list-style: none;
      font-size: 0.875rem;
    }

    .validation-list li {
      padding: 0.25rem 0;
      padding-left: 1.25rem;
      position: relative;
    }

    .validation-list li::before {
      content: '•';
      position: absolute;
      left: 0;
    }

    .validation-results.success .validation-list {
      color: var(--color-success);
    }

    .validation-results.error .validation-list {
      color: var(--color-error);
    }

    /* Modal */
    .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.5);
      backdrop-filter: blur(8px);
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 2rem;
      z-index: 1000;
      display: none;
    }

    .modal-overlay.active {
      display: flex;
    }

    .modal {
      width: 100%;
      max-width: 480px;
      background: var(--color-bg-card);
      border: 1px solid var(--color-border);
      border-radius: 24px;
      padding: 3rem;
      text-align: center;
      animation: slideIn 0.2s ease-out;
      box-shadow: var(--shadow-lg);
    }

    .modal-icon {
      width: 80px;
      height: 80px;
      margin: 0 auto 1.5rem;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .modal-icon.success {
      background: var(--color-success-bg);
      color: var(--color-success);
    }

    .modal-icon.error {
      background: var(--color-error-bg);
      color: var(--color-error);
    }

    .modal h3 {
      font-size: 1.25rem;
      font-weight: 600;
      margin-bottom: 0.5rem;
    }

    .modal p {
      color: var(--color-text-secondary);
      margin-bottom: 1.5rem;
    }

    .response-data {
      margin: 1.5rem 0;
      padding: 1rem;
      background: var(--color-bg-secondary);
      border-radius: 10px;
      text-align: left;
      max-height: 200px;
      overflow: auto;
    }

    .response-data pre {
      font-family: 'JetBrains Mono', monospace;
      font-size: 0.75rem;
      color: var(--color-text-muted);
      white-space: pre-wrap;
      word-break: break-all;
    }

    .modal-actions {
      display: flex;
      gap: 1rem;
      justify-content: center;
    }

    .spinner {
      width: 18px;
      height: 18px;
      border: 2px solid rgba(255, 255, 255, 0.3);
      border-top-color: white;
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
    }

    @keyframes spin {
      to { transform: rotate(360deg); }
    }

    @media (max-width: 768px) {
      .header-content { padding: 0.75rem 1rem; }
      .company-logo { height: 32px; }
      .portal-title h1 { font-size: 0.875rem; }
      .logo-divider { display: none; }
      .status-pill { display: none; }
      .portal-main { padding: 1rem; }
      .section-nav { flex-wrap: wrap; }
      .nav-tab {
        flex: 1 1 45%;
        padding: 0.75rem 1rem;
      }
      .form-grid { grid-template-columns: 1fr; }
      .item-grid { grid-template-columns: repeat(2, 1fr); }
      .item-grid .form-group.span-2 { grid-column: 1 / -1; }
      .section-actions { flex-direction: column; }
      .section-actions button { width: 100%; }
      .final-actions { flex-direction: column; }
    }

    ::-webkit-scrollbar { width: 8px; height: 8px; }
    ::-webkit-scrollbar-track { background: var(--color-bg-secondary); }
    ::-webkit-scrollbar-thumb { background: var(--color-bg-elevated); border-radius: 4px; }
    ::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }
    ::selection { background: var(--color-accent); color: white; }

    input[type='number']::-webkit-inner-spin-button,
    input[type='number']::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
    input[type='number'] { -moz-appearance: textfield; }
    input[type='date']::-webkit-calendar-picker-indicator { filter: invert(0.5); cursor: pointer; }
    [data-theme="dark"] input[type='date']::-webkit-calendar-picker-indicator { filter: invert(0.6); }
