/* --- 全域設定 --- */
      body,
      input,
      textarea,
      button,
      select {
        font-family:
          "Inter",
          ui-sans-serif,
          system-ui,
          -apple-system,
          BlinkMacSystemFont,
          "Segoe UI",
          Roboto,
          "Helvetica Neue",
          Arial,
          sans-serif !important;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
      }

      body {
        margin: 0;
        background-color: #f0f4f8;
        color: #1e293b;
      }
      .app-container {
        min-height: 100vh;
        padding: 2rem 1rem;
      }
      .controls-bar {
        max-width: 800px;
        margin: 0 auto 1.5rem auto;
        display: flex;
        flex-wrap: wrap;
        gap: 1rem;
        justify-content: space-between;
        align-items: center;
      }

      .invoice-card {
        max-width: 800px;
        margin: 0 auto;
        background-color: white;
        border-radius: 1.5rem;
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
        overflow: hidden;
        position: relative;
      }
      .decorative-bar {
        height: 0.5rem;
        background: linear-gradient(to right, #3b82f6, #60a5fa, #bfdbfe);
      }
      .card-content {
        padding: 2rem;
      }
      @media (min-width: 768px) {
        .card-content {
          padding: 3rem;
        }
      }

      /* --- Header Meta Grid (Invoice No & Date 對齊專用) --- */
      .header-meta-container {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
      }

      .invoice-meta-grid {
        display: grid;
        /* Label (靠左) | Value (靠右，固定寬度以保持整齊) */
        grid-template-columns: max-content 180px;
        column-gap: 2rem;
        row-gap: 0.5rem;
        align-items: center;
      }

      .meta-label {
        text-align: left;
        font-size: 0.875rem;
        font-weight: 700;
        color: #94a3b8;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        padding-top: 1px;
      }

      .meta-value-container {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        width: 100%;
        height: 32px;
      }

      .meta-input {
        text-align: right;
        font-weight: 500;
        color: #334155;
        background: transparent;
        border: none;
        border-bottom: 1px solid transparent;
        width: 100%;
        height: 100%;
        font-size: 1rem;
        transition: 0.2s;
        padding: 0;
      }
      .meta-input:hover {
        border-bottom-color: #cbd5e1;
      }
      .meta-input:focus {
        border-bottom-color: #3b82f6;
        outline: none;
      }

      /* --- 統一的 12 格 Grid 系統 --- */
      .grid-12 {
        display: grid;
        grid-template-columns: repeat(12, 1fr);
        gap: 1rem;
        align-items: center;
      }

      .items-header {
        border-bottom: 2px solid #f1f5f9;
        padding-bottom: 0.75rem;
        margin-bottom: 1rem;
      }

      .item-row {
        position: relative;
        margin-bottom: 0.5rem;
        min-height: 40px;
      }

      .footer-row {
        display: grid;
        grid-template-columns: repeat(12, 1fr);
        gap: 1rem;
        align-items: center;
        margin-bottom: 0.5rem;
        position: relative;
      }

      /* 欄位跨度 */
      .col-desc {
        grid-column: span 7;
        padding-left: 0;
      }
      .col-qty {
        grid-column: span 1;
        text-align: center;
      }
      .col-price {
        grid-column: span 2;
        text-align: right;
      }
      .col-amount {
        grid-column: span 2;
        text-align: right;
      }

      /* Footer Alignment */
      .col-footer-label {
        grid-column: span 8;
        text-align: right;
        color: #64748b;
        font-size: 0.875rem;
        font-weight: 500;
        padding-right: 0.5rem;
      }

      .col-footer-input {
        grid-column: span 2;
        display: flex;
        justify-content: flex-end;
      }

      .col-footer-value {
        grid-column: span 2;
        text-align: right;
        color: #334155;
        font-size: 0.875rem;
        font-weight: 600;
        white-space: nowrap;
      }

      .header-text {
        font-size: 0.75rem;
        font-weight: 700;
        color: #94a3b8;
        text-transform: uppercase;
        letter-spacing: 0.05em;
      }

      /* --- 底部文字區域 (Notes & Terms) --- */
      .bottom-section {
        margin-top: 3rem;
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
      }

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

      .text-block-title {
        font-size: 0.75rem;
        font-weight: 700;
        color: #94a3b8;
        text-transform: uppercase;
        letter-spacing: 0.05em;
      }

      .text-block-content {
        width: 100%;
        font-size: 0.75rem;
        line-height: 1.5;
        color: #64748b;
        background-color: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 0.5rem;
        padding: 0.75rem;
        resize: none;
        min-height: 80px;
        transition: border-color 0.2s;
      }
      .text-block-content:focus {
        border-color: #3b82f6;
        outline: none;
        color: #334155;
      }

      .print-text-block {
        display: none;
        font-size: 0.75rem;
        line-height: 1.5;
        color: #64748b;
        white-space: pre-wrap;
        width: 100%;
      }

      /* --- Input Styling --- */
      .input-box {
        display: flex;
        align-items: center;
        border: 1px solid #e2e8f0;
        border-radius: 0.375rem;
        background-color: white;
        height: 32px;
        width: 100%;
        padding: 0 0.25rem;
        transition: border-color 0.2s;
      }
      .input-box.has-btn {
        border-radius: 0.375rem 0 0 0.375rem;
        border-right: none;
      }
      .input-box:focus-within {
        border-color: #3b82f6;
        z-index: 1;
      }

      .input-field-in-box {
        flex: 1;
        border: none;
        outline: none;
        text-align: right;
        padding: 0 0.25rem;
        font-size: 0.875rem;
        width: 100%;
        color: #334155;
        background: transparent;
        min-width: 0;
      }

      .input-symbol-left {
        font-size: 0.75rem;
        color: #94a3b8;
        margin-left: 4px;
        margin-right: 0;
        user-select: none;
        font-weight: 500;
      }

      .input-symbol-right {
        font-size: 0.75rem;
        color: #94a3b8;
        margin-left: 0;
        margin-right: 4px;
        user-select: none;
        font-weight: 500;
      }

      .swap-btn {
        height: 32px;
        padding: 0 0.5rem;
        border: 1px solid #e2e8f0;
        border-radius: 0 0.375rem 0.375rem 0;
        background-color: white;
        color: #64748b;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background-color 0.2s;
      }
      .swap-btn:hover {
        background-color: #f8fafc;
        color: #334155;
      }

      /* Add Options */
      .add-options-row {
        display: flex;
        justify-content: flex-end;
        gap: 1rem;
        margin-top: 0.5rem;
        margin-bottom: 1rem;
        grid-column: 1 / -1;
      }
      .add-opt-btn {
        font-size: 0.75rem;
        color: #3b82f6;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 4px;
        border: none;
        background: none;
        font-weight: 500;
      }
      .add-opt-btn:hover {
        color: #1d4ed8;
        text-decoration: underline;
      }

      /* Delete Button */
      .delete-option-btn {
        position: absolute;
        right: -20px;
        top: 50%;
        transform: translateY(-50%);
        color: #cbd5e1;
        cursor: pointer;
        border: none;
        background: transparent;
        padding: 4px;
      }
      .delete-option-btn:hover {
        color: #f87171;
      }

      /* Other Inputs */
      .input-transparent {
        background: transparent;
        border: none;
        border-bottom: 1px solid transparent;
        width: 100%;
        padding: 4px 0;
        outline: none;
        transition: 0.2s;
        font-size: 0.875rem;
        color: #334155;
      }
      .input-transparent:hover {
        border-bottom-color: #cbd5e1;
      }
      .input-transparent:focus {
        border-bottom-color: #3b82f6;
      }
      .text-center {
        text-align: center;
      }
      .text-right {
        text-align: right;
      }
      .text-left {
        text-align: left;
      }
      .input-bare {
        background: transparent;
        border: none;
        width: 100%;
        outline: none;
      }
      .textarea-resize {
        resize: none;
        overflow: hidden;
        display: block;
      }

      /* Buttons */
      .btn-primary {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.5rem 1.5rem;
        background: #2563eb;
        color: white;
        border-radius: 999px;
        font-weight: 500;
        font-size: 0.875rem;
        border: none;
        cursor: pointer;
      }
      .btn-secondary {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.5rem 1rem;
        background: white;
        border: 1px solid #e5e7eb;
        border-radius: 999px;
        color: #475569;
        font-size: 0.875rem;
        font-weight: 500;
        cursor: pointer;
      }

      .btn-add {
        margin: 1.5rem auto;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        color: #2563eb;
        background: #eff6ff;
        border: 1px solid #bfdbfe;
        border-radius: 999px;
        cursor: pointer;
        padding: 0.5rem 1.5rem;
        font-size: 0.875rem;
        font-weight: 500;
        transition: all 0.2s;
        width: fit-content;
      }
      .btn-add:hover {
        background: #dbeafe;
      }

      .delete-btn-wrapper {
        position: absolute;
        left: -30px;
        top: 50%;
        transform: translateY(-50%);
      }
      .btn-icon {
        color: #cbd5e1;
        cursor: pointer;
        border: none;
        background: none;
        padding: 4px;
      }
      .btn-icon:hover {
        color: #f87171;
      }

      /* Total Final */
      .total-final-label {
        font-size: 1.125rem;
        font-weight: 700;
        color: #1e293b;
      }
      .total-final-value {
        font-size: 1.25rem;
        font-weight: 700;
        color: #2563eb;
      }

      /* 列印樣式 */
      @media print {
        body {
          background: white;
        }
        .app-container {
          padding: 0;
        }

        /* 隱藏元素 */
        .no-print,
        .controls-bar,
        .delete-option-btn,
        .swap-btn,
        .delete-btn-wrapper,
        .decorative-bar {
          display: none !important;
        }

        .print-padding {
          padding: 0 !important;
        }
        .invoice-card {
          box-shadow: none;
          border-radius: 0;
        }

        /* 輸入框調整 */
        .input-box {
          border: none;
          padding: 0;
          justify-content: flex-end;
          width: auto;
        }
        .input-field-in-box {
          text-align: right;
          padding: 0;
          width: auto;
        }

        /* 文字區塊調整：隱藏 Textarea，顯示 Div */
        .text-block-content {
          display: none !important;
        }
        .print-text-block {
          display: block !important;
        }

        /* 強制同一行顯示 Header */
        .print-flex-row {
          display: flex !important;
          flex-direction: row !important;
        }

        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
      }
