      :root {
        --ink: #0e1c2c;
        --ink-soft: #2c3e50;
        --muted: #64748b;
        --muted-light: #94a3b8;
        --line: #e2e8f0;
        --line-soft: #f1f5f9;
        --panel: #ffffff;
        --wash: #f0f4f8;
        --wash-deep: #e8edf3;
        --brand: #0f766e;
        --brand-dark: #0a5a54;
        --brand-mid: #0d9488;
        --brand-bright: var(--brand-bright);
        --brand-accent: var(--brand-accent);
        --brand-deep: var(--brand-deep);
        --brand-light: #e8f7f5;
        --brand-pale: #f0faf9;
        --brand-border: var(--brand-border);
        --brand-subtle-text: var(--brand-subtle-text);
        --brand-active-text: var(--brand-active-text);
        --brand-dark-text: var(--brand-dark-text);
        --brand-rgb: 15, 118, 110;
        --accent: #b45309;
        --danger: #c0392b;
        --danger-light: #fff1f0;
        --success: #15803d;
        --success-light: #f0fdf4;
        --warning: #b45309;
        --warning-light: #fffbeb;
        --radius: 10px;
        --radius-sm: 7px;
        --radius-lg: 14px;
        --shadow-xs: 0 1px 2px rgba(14,28,44,0.06);
        --shadow-sm: 0 1px 4px rgba(14,28,44,0.07), 0 1px 2px rgba(14,28,44,0.05);
        --shadow-md: 0 4px 16px rgba(14,28,44,0.08), 0 1px 4px rgba(14,28,44,0.05);
        --shadow-lg: 0 16px 48px rgba(14,28,44,0.14), 0 4px 12px rgba(14,28,44,0.07);
        --shadow-xl: 0 24px 64px rgba(14,28,44,0.18), 0 8px 24px rgba(14,28,44,0.08);
        --nav-w: 272px;
      }

      * { box-sizing: border-box; }

      html { scroll-behavior: smooth; }

      body {
        margin: 0;
        font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
        color: var(--ink);
        background: var(--wash);
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
      }

      button, input, select, textarea { font: inherit; }

      .app {
        min-height: 100vh;
        display: grid;
        grid-template-columns: var(--nav-w) minmax(0, 1fr);
      }

      /* ═══════════════════════════════════════════════════════
         SIDEBAR
      ═══════════════════════════════════════════════════════ */

      .sidebar {
        position: sticky;
        top: 0;
        align-self: start;
        height: 100vh;
        overflow-y: auto;
        background: linear-gradient(175deg, #0c1829 0%, #0e2038 55%, #0a1e34 100%);
        color: #f0f4f8;
        padding: 0 12px 28px;
        display: flex;
        flex-direction: column;
        border-right: 1px solid rgba(255,255,255,0.04);
        scrollbar-width: thin;
        scrollbar-color: rgba(255,255,255,0.1) transparent;
      }

      .sidebar::after {
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        width: 1px;
        height: 100%;
        background: linear-gradient(180deg, rgba(var(--brand-rgb),0.5) 0%, rgba(255,255,255,0.04) 40%, transparent 100%);
        pointer-events: none;
      }

      .brand {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 22px 8px 20px;
        margin-bottom: 4px;
        border-bottom: 1px solid rgba(255,255,255,0.06);
      }

      .brand-mark {
        width: 40px;
        height: 40px;
        flex: 0 0 40px;
        display: grid;
        place-items: center;
        border-radius: 10px;
        background: linear-gradient(135deg, var(--brand-bright) 0%, var(--brand) 60%, var(--brand-dark) 100%);
        color: #ffffff;
        font-size: 15px;
        font-weight: 900;
        letter-spacing: -0.5px;
        box-shadow: 0 3px 12px rgba(var(--brand-rgb),0.5), inset 0 1px 0 rgba(255,255,255,0.2);
      }

      .brand-title {
        font-size: 16.5px;
        font-weight: 800;
        letter-spacing: -0.02em;
        color: #f8fafc;
        line-height: 1.1;
      }

      .brand-subtitle {
        color: #4d6a82;
        font-size: 10.5px;
        font-weight: 600;
        margin-top: 3px;
        letter-spacing: 0.06em;
        text-transform: uppercase;
      }

      .nav {
        display: grid;
        gap: 1px;
        padding-top: 10px;
      }

      .nav button {
        width: 100%;
        border: 0;
        border-left: 2px solid transparent;
        border-radius: 0 8px 8px 0;
        padding: 9px 12px 9px 10px;
        color: #7a96ae;
        background: transparent;
        text-align: left;
        cursor: pointer;
        font-size: 13.5px;
        font-weight: 500;
        line-height: 1.3;
        transition: background 0.14s, color 0.14s, border-color 0.14s;
        position: relative;
      }

      .nav button:hover {
        background: rgba(255,255,255,0.055);
        color: #c8dae8;
        border-left-color: rgba(20,184,166,0.3);
      }

      .nav-section {
        margin-top: 16px;
        padding-top: 14px;
        border-top: 1px solid rgba(255,255,255,0.06);
        display: grid;
        gap: 1px;
      }

      .nav-parent {
        width: 100%;
        border: 0;
        border-radius: 6px;
        padding: 4px 12px 4px;
        color: #3d5a70;
        background: transparent;
        text-align: left;
        font-weight: 700;
        font-size: 10px;
        letter-spacing: 0.1em;
        text-transform: uppercase;
        cursor: default;
        margin-top: 4px;
      }

      .nav-child {
        margin-left: 10px;
        width: calc(100% - 10px);
        font-size: 13px;
      }

      .settings-subnav { display: none; }
      body.settings-view .settings-subnav { display: grid; }
      .settings-subnav .nav-child { font-size: 12.5px; padding: 7px 12px 7px 10px; }

      .nav button.active {
        color: #e0f2fe;
        background: linear-gradient(90deg, rgba(var(--brand-rgb),0.22) 0%, rgba(var(--brand-rgb),0.08) 100%);
        border-left-color: var(--brand-bright);
        font-weight: 600;
      }

      .nav button.active::after {
        content: "";
        position: absolute;
        right: 10px;
        top: 50%;
        transform: translateY(-50%);
        width: 5px;
        height: 5px;
        border-radius: 50%;
        background: var(--brand-bright);
        opacity: 0.7;
      }

      /* ═══════════════════════════════════════════════════════
         MAIN LAYOUT
      ═══════════════════════════════════════════════════════ */

      .main {
        min-width: 0;
        display: flex;
        flex-direction: column;
      }

      .topbar {
        min-height: 64px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 20px;
        padding: 12px 28px;
        background: #ffffff;
        border-bottom: 1px solid var(--line);
        box-shadow: 0 1px 0 rgba(14,28,44,0.04), var(--shadow-xs);
        position: sticky;
        top: 0;
        z-index: 10;
      }

      .topbar h1 {
        margin: 0;
        font-size: 19px;
        font-weight: 700;
        letter-spacing: -0.025em;
        color: var(--ink);
      }

      .top-actions {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-wrap: wrap;
      }

      .content {
        padding: 24px 28px;
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 18px;
        align-items: start;
      }

      /* ═══════════════════════════════════════════════════════
         BUTTONS
      ═══════════════════════════════════════════════════════ */

      .toolbar-button {
        min-height: 36px;
        border-radius: var(--radius-sm);
        border: 1px solid #d0dae6;
        background: linear-gradient(180deg, #ffffff 0%, #f7fafc 100%);
        color: var(--ink-soft);
        padding: 0 14px;
        cursor: pointer;
        font-size: 13px;
        font-weight: 600;
        transition: background 0.12s, border-color 0.12s, box-shadow 0.12s, transform 0.08s;
        box-shadow: var(--shadow-xs);
      }

      .toolbar-button:hover {
        background: linear-gradient(180deg, #f8fbff 0%, #eef4fa 100%);
        border-color: #b8c8d8;
        box-shadow: var(--shadow-sm);
      }

      .toolbar-button:active { transform: translateY(1px); box-shadow: none; }

      .primary-button {
        min-height: 36px;
        border-radius: var(--radius-sm);
        border: 1px solid #0a6460;
        background: linear-gradient(180deg, var(--brand-bright) 0%, var(--brand) 60%, var(--brand-deep) 100%);
        color: #ffffff;
        padding: 0 16px;
        cursor: pointer;
        font-size: 13px;
        font-weight: 700;
        letter-spacing: 0.01em;
        transition: filter 0.12s, box-shadow 0.12s, transform 0.08s;
        box-shadow: 0 1px 4px rgba(var(--brand-rgb),0.35), inset 0 1px 0 rgba(255,255,255,0.15);
      }

      .primary-button:hover {
        filter: brightness(1.06);
        box-shadow: 0 4px 14px rgba(var(--brand-rgb),0.42), inset 0 1px 0 rgba(255,255,255,0.15);
      }

      .primary-button:active { transform: translateY(1px); filter: brightness(0.96); box-shadow: none; }

      .soft-button {
        min-height: 34px;
        border: 1px solid #d0dae6;
        border-radius: var(--radius-sm);
        background: linear-gradient(180deg, #f8fafc 0%, #f0f5fa 100%);
        color: var(--ink-soft);
        padding: 0 12px;
        cursor: pointer;
        font-size: 13px;
        font-weight: 600;
        transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
        box-shadow: var(--shadow-xs);
      }

      .soft-button:hover {
        background: linear-gradient(180deg, #eef4fb 0%, #e6eef8 100%);
        border-color: #b8c8d8;
        box-shadow: var(--shadow-sm);
      }

      .danger-button {
        min-height: 34px;
        border: 1px solid #f5c2bd;
        border-radius: var(--radius-sm);
        background: linear-gradient(180deg, #fff7f7 0%, #fef0ef 100%);
        color: var(--danger);
        padding: 0 12px;
        cursor: pointer;
        font-weight: 600;
        font-size: 13px;
        transition: background 0.12s, box-shadow 0.12s;
        box-shadow: var(--shadow-xs);
      }

      .danger-button:hover {
        background: linear-gradient(180deg, #fee8e6 0%, #fdd9d6 100%);
        box-shadow: var(--shadow-sm);
      }

      /* ═══════════════════════════════════════════════════════
         PANELS
      ═══════════════════════════════════════════════════════ */

      .panel {
        background: var(--panel);
        border: 1px solid var(--line);
        border-radius: var(--radius);
        box-shadow: var(--shadow-sm);
        overflow: hidden;
      }

      .hidden { display: none !important; }

      .panel-header {
        padding: 14px 20px;
        border-bottom: 1px solid var(--line);
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        background: linear-gradient(180deg, #fafcff 0%, #f5f8fb 100%);
        position: relative;
      }

      .panel-header::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 2px;
        background: linear-gradient(90deg, var(--brand) 0%, var(--brand-mid) 50%, transparent 100%);
        opacity: 0.6;
        border-radius: var(--radius) var(--radius) 0 0;
      }

      .panel-header h2 {
        margin: 0;
        font-size: 14.5px;
        font-weight: 700;
        letter-spacing: -0.01em;
        color: var(--ink);
      }

      .badge {
        display: inline-flex;
        align-items: center;
        min-height: 22px;
        border-radius: 999px;
        padding: 0 9px;
        background: var(--brand-light);
        color: var(--brand-dark);
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.02em;
        border: 1px solid rgba(var(--brand-rgb),0.15);
      }

      /* ═══════════════════════════════════════════════════════
         FORM ELEMENTS
      ═══════════════════════════════════════════════════════ */

      .form {
        padding: 20px;
        display: grid;
        gap: 16px;
      }

      .grid-2 {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 14px;
      }

      label {
        display: grid;
        gap: 5px;
        color: var(--muted);
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.06em;
        text-transform: uppercase;
      }

      input,
      select,
      textarea {
        width: 100%;
        border: 1px solid #cbd5e1;
        border-radius: var(--radius-sm);
        min-height: 38px;
        padding: 8px 11px;
        color: var(--ink);
        background: #ffffff;
        font-size: 14px;
        transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
        text-transform: none;
        letter-spacing: 0;
        font-weight: 400;
      }

      input::placeholder,
      textarea::placeholder { color: #a0afc0; }

      input:hover:not(:disabled),
      select:hover:not(:disabled),
      textarea:hover:not(:disabled) {
        border-color: #99b0c8;
      }

      input:focus,
      select:focus,
      textarea:focus {
        outline: none;
        border-color: var(--brand);
        background: var(--brand-pale);
        box-shadow: 0 0 0 3px rgba(var(--brand-rgb),0.1), 0 1px 3px rgba(var(--brand-rgb),0.08);
      }

      input:disabled {
        background: #f4f7fa;
        color: #7a8fa0;
        border-color: #dde4ec;
        cursor: not-allowed;
      }

      textarea {
        min-height: 86px;
        resize: vertical;
        line-height: 1.55;
      }

      select {
        cursor: pointer;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 10px center;
        padding-right: 30px;
      }

      .main-fields { display: grid; gap: 16px; }
      .main-fields .grid-2 { gap: 14px; }
      .main-fields label { gap: 5px; }
      .main-fields input,
      .main-fields select,
      .main-fields textarea { min-height: 40px; font-size: 14px; }

      .order-address-fields {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 14px;
        align-items: stretch;
      }

      .order-address-fields textarea {
        min-height: 150px;
        height: 150px;
        line-height: 1.45;
      }

      /* ═══════════════════════════════════════════════════════
         AUTOCOMPLETE DROPDOWNS
      ═══════════════════════════════════════════════════════ */

      .customer-autocomplete { position: relative; }

      .customer-dropdown {
        position: absolute;
        z-index: 50;
        top: calc(100% + 5px);
        left: 0;
        right: 0;
        max-height: 360px;
        overflow: auto;
        border: 1px solid #bccad6;
        border-radius: 10px;
        background: #ffffff;
        box-shadow: var(--shadow-lg);
        scrollbar-width: thin;
      }

      .customer-dropdown-option {
        width: 100%;
        min-height: 38px;
        display: flex;
        align-items: center;
        border: 0;
        border-bottom: 1px solid #f1f5f9;
        background: #ffffff;
        color: var(--ink);
        padding: 8px 14px;
        text-align: left;
        font-size: 14px;
        line-height: 1.2;
        cursor: pointer;
        transition: background 0.1s, color 0.1s;
      }

      .customer-dropdown-option:hover,
      .customer-dropdown-option:focus {
        background: var(--brand-light);
        color: var(--brand-dark);
        outline: none;
      }

      .customer-dropdown-option:last-child { border-bottom: 0; }

      .item-catalog-dropdown {
        position: fixed;
        z-index: 90;
        max-height: 340px;
        overflow: auto;
        border: 1px solid #bccad6;
        border-radius: 10px;
        background: #ffffff;
        box-shadow: var(--shadow-lg);
        scrollbar-width: thin;
      }

      .item-catalog-option {
        width: 100%;
        min-height: 48px;
        display: grid;
        gap: 2px;
        border: 0;
        border-bottom: 1px solid #f1f5f9;
        background: #ffffff;
        color: var(--ink);
        padding: 8px 14px;
        text-align: left;
        cursor: pointer;
        transition: background 0.1s;
      }

      .item-catalog-option:hover,
      .item-catalog-option:focus {
        background: var(--brand-light);
        outline: none;
      }

      .item-catalog-name {
        white-space: normal;
        overflow-wrap: anywhere;
        font-size: 13.5px;
        font-weight: 700;
        line-height: 1.2;
        color: var(--ink);
      }

      .item-catalog-meta {
        color: var(--muted);
        font-size: 12px;
        font-weight: 600;
      }

      #orderPanel .main-fields label,
      #invoicesPanel .main-fields label { gap: 5px; font-size: 10.5px; }
      #orderPanel .main-fields input,
      #orderPanel .main-fields select,
      #invoicesPanel .main-fields input,
      #invoicesPanel .main-fields select {
        min-height: 36px;
        height: 36px;
        padding: 6px 10px;
        font-size: 13.5px;
      }
      #orderPanel .main-fields textarea,
      #invoicesPanel .main-fields textarea { padding: 8px 10px; font-size: 13.5px; line-height: 1.35; }
      .main-fields textarea { overflow: visible; }

      /* ═══════════════════════════════════════════════════════
         LINE ITEMS TABLE
      ═══════════════════════════════════════════════════════ */

      .line-items {
        border: 1px solid var(--line);
        border-radius: var(--radius-sm);
        overflow: hidden;
        box-shadow: var(--shadow-xs);
      }

      .entry-table {
        width: 100%;
        border-collapse: collapse;
      }

      .entry-table th {
        padding: 9px 10px;
        background: linear-gradient(180deg, #f4f8fb 0%, #edf2f8 100%);
        border-right: 1px solid var(--line);
        border-bottom: 1px solid #c8d8e8;
        color: #546880;
        font-size: 10.5px;
        text-align: left;
        text-transform: uppercase;
        letter-spacing: 0.07em;
        font-weight: 700;
      }

      .entry-table td {
        padding: 7px 7px;
        border-right: 1px solid var(--line);
        border-bottom: 1px solid var(--line);
        vertical-align: top;
        background: #ffffff;
        transition: background 0.1s;
      }

      .entry-table tbody tr:nth-child(even) td { background: #fafbfd; }
      .entry-table tbody tr:hover td { background: var(--brand-pale); }

      .entry-table th:last-child,
      .entry-table td:last-child { border-right: 0; }
      .entry-table tr:last-child td { border-bottom: 0; }
      .entry-table input,
      .entry-table select { min-height: 34px; }

      .entry-table th:first-child,
      .entry-table td:first-child { width: 52%; }
      .entry-table .item-name,
      .entry-table .sr-item-name,
      .entry-table .invn-item-name { width: 100%; min-width: 360px; }
      .entry-table textarea.item-name,
      .entry-table textarea.sr-item-name,
      .entry-table textarea.invn-item-name { display: block; resize: none; overflow: hidden; min-height: 30px; font: inherit; font-size: 14px; line-height: 1.4; padding: 3px 4px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); box-sizing: border-box; }
      .entry-table .item-qty,
      .entry-table .sr-item-qty,
      .entry-table .invn-item-qty { width: 76px; min-width: 76px; text-align: center; }
      .entry-table .item-price,
      .entry-table .sr-item-price,
      .entry-table .invn-item-price { width: 132px; min-width: 132px; }
      .entry-table .item-discount,
      .entry-table .sr-item-discount,
      .entry-table .invn-item-discount { width: 86px; min-width: 86px; }
      .entry-table .item-tax,
      .entry-table .sr-item-tax,
      .entry-table .invn-item-tax { width: 132px; min-width: 132px; }
      .entry-table .amount-cell {
        padding-top: 14px;
        text-align: right;
        font-weight: 700;
        white-space: nowrap;
        color: var(--ink-soft);
      }
      .entry-table .line-delete-cell { width: 54px; text-align: center; vertical-align: middle; }

      .item-delete {
        width: 32px;
        min-height: 32px;
        border: 1px solid #f5c2bd;
        border-radius: 6px;
        background: #fff7f7;
        color: var(--danger);
        font-size: 17px;
        font-weight: 900;
        line-height: 1;
        cursor: pointer;
        transition: background 0.12s, box-shadow 0.12s;
        box-shadow: var(--shadow-xs);
      }

      .item-delete:hover { background: #fee8e6; box-shadow: var(--shadow-sm); }

      .entry-actions {
        display: flex;
        gap: 8px;
        padding: 10px 14px;
        border-top: 1px solid var(--line);
        background: linear-gradient(180deg, #fafcff 0%, #f4f8fb 100%);
      }

      /* ═══════════════════════════════════════════════════════
         CUSTOMERS
      ═══════════════════════════════════════════════════════ */

      .customer-type-picker {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
      }

      .customer-type-button {
        min-height: 58px;
        border: 1.5px solid var(--brand-border);
        border-radius: 9px;
        background: linear-gradient(145deg, var(--brand-pale) 0%, var(--brand-light) 100%);
        color: var(--brand-dark);
        padding: 10px 14px;
        text-align: left;
        cursor: pointer;
        transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.1s;
        box-shadow: var(--shadow-xs);
      }

      .customer-type-button strong,
      .customer-type-button span { display: block; }
      .customer-type-button strong { font-size: 15px; line-height: 1.2; }
      .customer-type-button span { margin-top: 3px; color: var(--brand-subtle-text); font-size: 12px; font-weight: 600; }

      .customer-type-button:hover {
        border-color: var(--brand-mid);
        transform: translateY(-1px);
        box-shadow: var(--shadow-md);
      }

      .customer-type-button.active {
        border-color: var(--brand);
        background: linear-gradient(145deg, var(--brand) 0%, var(--brand-dark) 100%);
        color: #ffffff;
        box-shadow: 0 4px 14px rgba(var(--brand-rgb),0.35), inset 0 1px 0 rgba(255,255,255,0.1);
      }

      .customer-type-button.active span { color: var(--brand-active-text); }

      .customer-vat-currency-row { align-items: end; }
      .customer-vat-currency-row input,
      .customer-vat-currency-row select { height: 50px; min-height: 50px; font-size: 16px; }
      .customer-currency-field { grid-column: 2; }

      .customer-csv-actions {
        display: flex;
        align-items: center;
        gap: 12px;
        flex-wrap: wrap;
      }

      .customer-row-actions {
        display: flex;
        gap: 7px;
        align-items: center;
        justify-content: flex-end;
        flex-wrap: wrap;
      }

      .customer-row-actions .soft-button,
      .customer-row-actions .danger-button {
        min-height: 30px;
        padding: 0 9px;
        font-size: 12px;
        white-space: nowrap;
      }

      .order-actions {
        justify-content: flex-start;
        flex-wrap: nowrap;
        gap: 8px;
      }

      .order-actions .soft-button,
      .order-actions .danger-button {
        min-width: 80px;
        min-height: 40px;
        padding: 0 14px;
        font-size: 13.5px;
      }

      .order-list-table th,
      .order-list-table td { padding-top: 12px; padding-bottom: 12px; vertical-align: middle; }
      .order-list-table td:last-child,
      .order-list-table th:last-child { width: 210px; }

      .csv-status {
        color: var(--muted);
        font-size: 13px;
        font-weight: 600;
        display: inline-flex;
        align-items: center;
        gap: 8px;
      }

      .csv-status.is-loading::before {
        content: "";
        width: 13px;
        height: 13px;
        border: 2px solid var(--line);
        border-top-color: var(--brand);
        border-radius: 50%;
        animation: csv-spin 0.65s linear infinite;
        flex: 0 0 auto;
      }

      @keyframes csv-spin { to { transform: rotate(360deg); } }

      .customer-total-count {
        margin: 10px 0 0;
        font-size: 13px;
        font-weight: 700;
        color: var(--ink);
      }

      .customer-total-count strong { color: var(--brand); font-size: 16px; }

      /* ═══════════════════════════════════════════════════════
         EDITOR BOTTOM
      ═══════════════════════════════════════════════════════ */

      .editor-bottom {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
        gap: 24px;
        align-items: start;
      }

      #orderPanel > .form > .main-fields { order: 1; }
      #orderPanel > .form > .line-items { order: 2; }
      #orderPanel > .form > .editor-bottom { order: 3; }
      #orderPanel > .form > .order-save-actions { order: 4; }
      #orderPanel > .form > .settings-box { order: 5; }

      .order-save-actions { justify-content: flex-end; padding: 0; border-top: 0; background: transparent; }

      .editor-totals {
        display: grid;
        gap: 8px;
        padding: 18px;
        border-radius: 10px;
        background: linear-gradient(145deg, #f0f7f6 0%, #e8f5f3 100%);
        border: 1px solid #c8e8e4;
        box-shadow: var(--shadow-sm);
      }

      .editor-total-row {
        display: grid;
        grid-template-columns: 1fr 150px;
        gap: 12px;
        align-items: center;
        font-size: 13.5px;
        color: var(--ink-soft);
      }

      .editor-total-row strong { text-align: right; font-weight: 700; }

      .editor-grand-total {
        padding-top: 12px;
        border-top: 1px solid #a8d8d2;
        font-size: 17px;
        font-weight: 800;
        color: var(--ink);
      }

      /* ═══════════════════════════════════════════════════════
         PREVIEW / MODAL
      ═══════════════════════════════════════════════════════ */

      .preview-wrap {
        overflow: auto;
        padding: 8px 0 28px;
      }

      body.order-view:not(.preview-open) #previewPanel { display: none; }

      body.preview-open #previewPanel {
        position: fixed;
        inset: 0;
        z-index: 80;
        display: grid;
        place-items: start center;
        padding: 32px 24px;
        background: rgba(8,16,30,0.8);
        overflow: auto;
        backdrop-filter: blur(4px);
      }

      #customerStatementPreviewPanel:not(.hidden) {
        position: fixed;
        inset: 0;
        z-index: 85;
        display: grid;
        place-items: start center;
        padding: 32px 24px;
        background: rgba(8,16,30,0.8);
        overflow: auto;
        backdrop-filter: blur(4px);
      }

      /* Base toolbar layout — shared by all panels */
      .preview-modal-toolbar {
        position: sticky;
        top: 0;
        z-index: 2;
        width: 860px;
        max-width: calc(100vw - 72px);
        display: flex;
        align-items: center;
        gap: 8px;
        flex-wrap: wrap;
        margin: 0 0 12px;
      }

      /* Frosted-glass container — Order Confirmation, Invoices, Sales Receipts */
      #previewPanel .preview-modal-toolbar,
      #invoiceDetailPanel .preview-modal-toolbar,
      #salesReceiptDetailPanel .preview-modal-toolbar,
      #creditNoteDetailPanel .preview-modal-toolbar {
        padding: 10px 14px;
        background: rgba(255,255,255,0.85);
        backdrop-filter: blur(16px);
        border-radius: 14px;
        border: 1px solid rgba(14,28,44,0.08);
        box-shadow: 0 4px 20px rgba(14,28,44,0.10), 0 1px 4px rgba(14,28,44,0.06);
        gap: 6px;
        margin: 0 0 14px;
      }

      /* Backward-compatible base styles for old-class buttons in other toolbars */
      .preview-modal-toolbar button:not(.ptb-btn):not(.ptb-close) {
        min-height: 40px;
        border: 1px solid rgba(255,255,255,0.25);
        border-radius: 9px;
        background: rgba(255,255,255,0.96);
        color: var(--ink);
        padding: 0 16px;
        font-weight: 700;
        font-size: 13px;
        cursor: pointer;
        box-shadow: var(--shadow-md);
        transition: background 0.13s, transform 0.08s;
        backdrop-filter: blur(8px);
      }
      .preview-modal-toolbar button:not(.ptb-btn):not(.ptb-close):hover { background: #ffffff; }
      .preview-modal-toolbar button:not(.ptb-btn):not(.ptb-close):active { transform: translateY(1px); }
      .preview-modal-toolbar .primary-button {
        border-color: #0a6460;
        background: linear-gradient(180deg, var(--brand-bright) 0%, var(--brand) 100%);
        color: #fff;
        box-shadow: 0 2px 10px rgba(var(--brand-rgb),0.45), inset 0 1px 0 rgba(255,255,255,0.15);
      }
      .preview-modal-toolbar .primary-button:hover { filter: brightness(1.07); }
      .preview-modal-toolbar .danger-button {
        border-color: #f5c2bd;
        background: rgba(255,247,247,0.97);
        color: var(--danger);
      }

      .ptb-spacer { flex: 1; }

      /* Base button */
      .ptb-btn {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        height: 36px;
        padding: 0 14px;
        border-radius: 9px;
        border: 1px solid transparent;
        font-family: inherit;
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
        white-space: nowrap;
        transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
      }
      .ptb-btn:active { transform: translateY(1px); }
      .ptb-btn svg { flex-shrink: 0; }

      /* Soft (Edit, Send email) */
      .ptb-soft {
        background: rgba(255,255,255,0.9);
        border-color: var(--line);
        color: var(--ink-soft);
        box-shadow: 0 1px 3px rgba(14,28,44,0.07);
      }
      .ptb-soft:hover {
        background: #fff;
        border-color: var(--brand-mid);
        color: var(--brand);
        box-shadow: 0 2px 8px rgba(var(--brand-rgb),0.15);
      }

      /* Mark as sent (green tint) */
      .ptb-sent {
        background: #f0fdf4;
        border-color: #86efac;
        color: #16a34a;
        box-shadow: 0 1px 3px rgba(14,28,44,0.06);
      }
      .ptb-sent:hover {
        background: #dcfce7;
        border-color: #4ade80;
        box-shadow: 0 2px 8px rgba(22,163,74,0.18);
      }
      .ptb-sent:disabled { opacity: 1; cursor: default; filter: none; }

      /* Convert to invoice (brand teal tint) */
      .ptb-convert {
        background: var(--brand-light);
        border-color: var(--brand-mid);
        color: var(--brand-dark);
        box-shadow: 0 1px 3px rgba(14,28,44,0.06);
      }
      .ptb-convert:hover {
        background: #d0f0ec;
        box-shadow: 0 2px 8px rgba(var(--brand-rgb),0.20);
      }

      /* Primary (PDF/Print) */
      .ptb-primary {
        background: linear-gradient(135deg, var(--brand-mid) 0%, var(--brand-dark) 100%);
        border-color: var(--brand-dark);
        color: #fff;
        box-shadow: 0 2px 10px rgba(var(--brand-rgb),0.40), inset 0 1px 0 rgba(255,255,255,0.15);
        padding: 0 18px;
      }
      .ptb-primary:hover {
        filter: brightness(1.08);
        box-shadow: 0 4px 14px rgba(var(--brand-rgb),0.50), inset 0 1px 0 rgba(255,255,255,0.15);
      }

      /* Danger (Delete) */
      .ptb-danger {
        background: #fff5f5;
        border-color: #fecaca;
        color: #dc2626;
        box-shadow: 0 1px 3px rgba(14,28,44,0.06);
      }
      .ptb-danger:hover {
        background: #fee2e2;
        border-color: #f87171;
        box-shadow: 0 2px 8px rgba(220,38,38,0.18);
      }

      /* Close button (icon only) */
      .ptb-close {
        width: 34px;
        height: 34px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        border: 1px solid var(--line);
        background: rgba(255,255,255,0.9);
        color: var(--muted);
        cursor: pointer;
        flex-shrink: 0;
        box-shadow: 0 1px 3px rgba(14,28,44,0.07);
        transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
        margin-left: 4px;
      }
      .ptb-close:hover {
        background: #fee2e2;
        border-color: #f87171;
        color: #dc2626;
        transform: scale(1.08);
      }
      .ptb-close:active { transform: scale(0.94); }

      /* "Already sent" state on mark-sent button */
      .preview-modal-toolbar .sent-state-button {
        background: var(--brand-light);
        border-color: var(--brand-mid);
        color: var(--brand-dark);
        cursor: default;
      }
      .preview-modal-toolbar .sent-state-button:hover {
        background: var(--brand-light);
        box-shadow: none;
        transform: none;
      }
      .preview-modal-toolbar .sent-state-button:disabled { opacity: 1; cursor: default; }

      /* ═══════════════════════════════════════════════════════
         DOCUMENT (printed invoice) — layout intact
      ═══════════════════════════════════════════════════════ */

      .document {
        width: 860px;
        max-width: calc(100vw - 72px);
        min-height: 1120px;
        margin: 0 auto;
        background: #ffffff;
        border: 1px solid #9b9b9b;
        border-radius: 0;
        box-shadow: 0 20px 60px rgba(14,28,44,0.1);
        overflow: hidden;
      }

      .customer-statement-document .doc-body { padding: 30px 34px 36px; }

      .statement-brand-row {
        display: grid;
        grid-template-columns: 1fr 260px;
        gap: 32px;
        align-items: start;
        margin-bottom: 40px;
        min-height: 112px;
      }

      .statement-brand-row .doc-logo { width: 340px; height: 92px; margin-top: 14px; }
      .statement-brand-row .doc-logo img { width: 340px; }
      .statement-company-info { text-align: right; font-size: 16px; line-height: 1.35; }
      .statement-company-info strong { display: block; font-size: 18px; }

      .statement-header {
        display: grid;
        grid-template-columns: 1fr 0.78fr;
        gap: 42px;
        align-items: start;
        border-bottom: 0;
        padding-bottom: 34px;
      }

      .statement-customer { white-space: pre-line; font-size: 16px; line-height: 1.45; }
      .statement-title-block { text-align: right; }
      .statement-title-block h2 { margin: 0; padding-bottom: 6px; border-bottom: 2px solid #111111; color: #000000; font-size: 34px; line-height: 1.05; }
      .statement-title-block p { margin: 8px 0 0; padding-bottom: 8px; border-bottom: 1px solid #111111; font-size: 16px; }
      .statement-summary { width: 42%; margin: 0 0 68px auto; }
      .statement-summary-title { background: #e4e4e4; padding: 9px 10px; font-size: 17px; font-weight: 900; }
      .statement-summary-row { display: grid; grid-template-columns: 1fr auto; gap: 18px; padding: 7px 0; font-size: 16px; }
      .statement-summary-row.statement-total { border-top: 1px solid #111111; margin-top: 4px; padding-top: 10px; }

      .statement-table { width: 100%; border-collapse: collapse; font-size: 15px; }
      .statement-table th { background: #3d3f3b; color: #ffffff; padding: 9px 8px; text-align: left; font-size: 15px; font-weight: 900; }
      .statement-table td { border-bottom: 1px solid #d8d8d8; padding: 12px 8px; text-align: left; vertical-align: top; }
      .statement-table td:nth-child(4),
      .statement-table td:nth-child(5),
      .statement-table td:nth-child(6),
      .statement-table th:nth-child(4),
      .statement-table th:nth-child(5),
      .statement-table th:nth-child(6) { text-align: right; }
      .statement-balance-due { display: grid; grid-template-columns: 1fr auto; gap: 18px; margin-top: 20px; padding-top: 14px; font-size: 17px; }
      .statement-balance-due strong:first-child { text-align: right; }

      .doc-stripe { display: none; }
      .doc-body { padding: 0; }

      .doc-header {
        display: grid;
        grid-template-columns: 1.1fr 0.78fr 0.9fr;
        gap: 22px;
        align-items: start;
        min-height: 148px;
        padding: 28px 22px 12px;
        border-bottom: 1px solid #9b9b9b;
      }

      .doc-logo {
        width: 310px;
        max-width: 100%;
        height: 82px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        background: transparent;
        color: #000000;
        font-weight: 900;
        font-size: 42px;
        letter-spacing: 10px;
        line-height: 0.95;
      }

      .doc-logo span { margin-top: 14px; font-size: 9px; letter-spacing: 1.8px; font-weight: 700; text-align: right; }
      .doc-logo.has-image { align-items: flex-start; letter-spacing: 0; }
      .doc-logo.has-image .logo-text { display: none; }
      .doc-logo img { display: none; width: 310px; max-width: 100%; max-height: 96px; object-fit: contain; }
      .doc-logo.has-image img { display: block; }
      .document.no-discount .order-discount-column { display: none; }

      .draft-edit-input {
        font-size: inherit;
        font-weight: 700;
        font-family: inherit;
        color: inherit;
        background: transparent;
        border: none;
        border-bottom: 1.5px solid var(--brand);
        border-radius: 0;
        padding: 0 2px;
        width: 130px;
        outline: none;
        line-height: inherit;
      }
      .draft-edit-input:focus { border-bottom-color: var(--brand-mid); background: rgba(var(--brand-rgb),0.06); }
      @media (prefers-color-scheme: dark) {
        .draft-edit-input { border-bottom-color: var(--brand-accent); }
        .draft-edit-input:focus { background: rgba(45,212,191,0.08); }
      }
      @media print {
        .draft-edit-input { display: none; }
        .draft-date-field { display: none; }
        .draft-static.hidden { display: inline !important; }
      }

      /* Il campo data nativo è invisibile e sovrapposto allo span formattato:
         riceve i click/tastiera per il calendario nativo del browser, ma il
         testo mostrato (giorno/mese/anno) resta sempre quello formattato,
         indipendentemente dalla lingua/regione del browser dell'utente. */
      .draft-date-field {
        position: relative;
        display: inline-block;
        width: 130px;
      }
      .draft-date-field .draft-edit-input {
        display: inline-block;
        width: 100%;
        cursor: pointer;
        white-space: nowrap;
        overflow: hidden;
      }
      .draft-date-field input[type="date"] {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        border: none;
        opacity: 0;
        cursor: pointer;
      }

      /* ═══════════════════════════════════════════════════════
         SETTINGS BOX
      ═══════════════════════════════════════════════════════ */

      .settings-box {
        display: grid;
        gap: 16px;
        padding: 20px;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: linear-gradient(145deg, #fafcff 0%, #f5f8fd 100%);
        box-shadow: var(--shadow-sm);
      }

      .settings-box h3 {
        margin: 0;
        font-size: 14.5px;
        font-weight: 700;
        letter-spacing: -0.01em;
        color: var(--ink);
        padding-bottom: 12px;
        border-bottom: 1px solid var(--line);
      }

      #salesReceiptEditorPanel { order: -1; }

      /* ═══════════════════════════════════════════════════════
         LOGO UPLOAD
      ═══════════════════════════════════════════════════════ */

      .logo-upload-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 12px;
        align-items: end;
      }

      .logo-preview {
        min-height: 82px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1.5px dashed #b8ccd8;
        border-radius: 9px;
        background: linear-gradient(145deg, #f8fbff 0%, #f2f7fb 100%);
        overflow: hidden;
        transition: border-color 0.15s, background 0.15s;
        color: var(--muted-light);
        font-size: 13px;
        font-weight: 600;
      }

      .logo-preview:hover { border-color: var(--brand); background: var(--brand-pale); }
      .logo-preview img { display: none; max-width: 280px; max-height: 76px; object-fit: contain; }
      .logo-preview.has-image img { display: block; }
      .logo-preview.has-image span { display: none; }

      /* ═══════════════════════════════════════════════════════
         CUSTOMER LIST TABLE
      ═══════════════════════════════════════════════════════ */

      .customer-list {
        width: 100%;
        border-collapse: collapse;
        border: 1px solid var(--line);
        border-radius: var(--radius-sm);
        overflow: hidden;
        box-shadow: var(--shadow-xs);
      }

      .customer-list th,
      .customer-list td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; }

      .customer-list th {
        background: linear-gradient(180deg, #f4f8fb 0%, #edf3f9 100%);
        color: #546880;
        font-size: 10.5px;
        text-transform: uppercase;
        letter-spacing: 0.07em;
        font-weight: 700;
        border-bottom-color: #c8d8e8;
      }

      .customer-list tr:last-child td { border-bottom: 0; }
      .customer-list tbody tr { cursor: pointer; transition: background 0.1s; }
      .customer-list tbody tr:nth-child(even) td { background: #fafcfe; }
      .customer-list tbody tr:hover td { background: var(--brand-light); }

      .saved-customers-list th,
      .saved-customers-list td { padding: 14px 18px; font-size: 15px; line-height: 1.35; }
      .saved-customers-list th { font-size: 11px; }
      .saved-customers-list tbody tr { min-height: 58px; }
      .saved-customers-list .customer-row-actions { flex-wrap: nowrap; }
      .saved-customers-list .customer-row-actions .soft-button,
      .saved-customers-list .customer-row-actions .danger-button { min-height: 34px; font-size: 12.5px; padding: 0 10px; white-space: nowrap; }

      /* ═══════════════════════════════════════════════════════
         CUSTOMER KPIs
      ═══════════════════════════════════════════════════════ */

      .customer-kpis {
        display: grid;
        grid-template-columns: repeat(4, minmax(140px, 1fr));
        gap: 12px;
      }

      .customer-kpi {
        padding: 18px 16px;
        border: 1px solid var(--line);
        border-radius: 11px;
        background: linear-gradient(145deg, #ffffff 0%, #f8fafb 100%);
        box-shadow: var(--shadow-sm);
        transition: box-shadow 0.15s, transform 0.15s;
        position: relative;
        overflow: hidden;
      }

      .customer-kpi::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 3px;
        background: linear-gradient(90deg, var(--brand) 0%, var(--brand-mid) 100%);
        opacity: 0.7;
      }

      .customer-kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

      .customer-kpi span {
        display: block;
        color: var(--muted);
        font-size: 10.5px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.07em;
      }

      .customer-kpi strong {
        display: block;
        margin-top: 8px;
        font-size: 22px;
        font-weight: 800;
        letter-spacing: -0.025em;
        color: var(--ink);
      }

      /* ═══════════════════════════════════════════════════════
         DASHBOARD
      ═══════════════════════════════════════════════════════ */

      .dashboard-receivable-total {
        display: block;
        margin: 4px 0 14px;
        font-size: 32px;
        font-weight: 800;
        color: var(--ink);
        letter-spacing: -0.03em;
      }

      .dashboard-receivable-split { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
      .dashboard-currency-label { margin: 0 0 2px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
      .dashboard-kpi-eur { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-top: 2px; }
      .dashboard-kpi-eur.hidden { display: none; }

      .dashboard-kpi-overdue {
        border-color: #f5c2bd;
        background: linear-gradient(145deg, #fff9f8 0%, #fff0ef 100%);
      }

      .dashboard-kpi-overdue::before { background: linear-gradient(90deg, var(--danger) 0%, #e05a50 100%); }
      .dashboard-kpi-overdue strong { color: var(--danger); }

      .dashboard-monthly-chart {
        display: grid;
        grid-template-columns: repeat(12, 1fr);
        align-items: end;
        gap: 8px;
        height: 220px;
        padding: 12px 8px 0;
        border-bottom: 1px solid var(--line);
      }

      .dashboard-month-bar-wrap {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-end;
        height: 100%;
        gap: 6px;
      }

      .dashboard-month-bar-value {
        font-size: 10.5px;
        font-weight: 700;
        color: var(--muted);
        white-space: nowrap;
      }

      .dashboard-month-bar {
        width: 100%;
        max-width: 24px;
        min-height: 2px;
        border-radius: 4px 4px 0 0;
        background: linear-gradient(180deg, #38d9cc 0%, var(--brand-mid) 50%, var(--brand) 100%);
        box-shadow: 0 2px 8px rgba(var(--brand-rgb),0.25);
      }

      .dashboard-month-bar-label {
        margin-top: 7px;
        font-size: 9.5px;
        font-weight: 700;
        color: var(--muted-light);
        text-transform: uppercase;
        letter-spacing: 0.04em;
      }

      .dashboard-operator-greeting h3 { font-size: 32px; margin: 0 0 4px; font-weight: 800; letter-spacing: -0.02em; }
      .dashboard-operator-greeting p { margin: 0; color: var(--muted); font-size: 14px; }

      .dashboard-operator-counters {
        display: grid;
        grid-template-columns: repeat(2, minmax(140px, 1fr));
        gap: 12px;
      }

      .dashboard-operator-clock-card {
        margin-top: 12px;
        padding: 1px;
        border-radius: 26px;
        background: linear-gradient(135deg, #f6f0e4 0%, #ede1c9 100%);
        box-shadow: 0 16px 40px -20px rgba(41, 37, 36, 0.35);
        animation: dashboardClockFadeIn 0.6s ease;
        transition: background 1.5s ease;
      }
      .dashboard-operator-clock-card.time-night {
        background: linear-gradient(135deg, #3f3a34 0%, #1c1917 100%);
      }

      .dashboard-clock-glass {
        background: rgba(255, 255, 255, 0.6);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-radius: 25px;
        padding: 28px 28px 24px;
        border-top: 1px solid rgba(179, 136, 79, 0.35);
      }
      .dashboard-operator-clock-card.time-night .dashboard-clock-glass {
        background: rgba(28, 25, 23, 0.5);
        border-top-color: rgba(212, 175, 116, 0.3);
      }

      .dashboard-clock-main {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 18px;
        flex-wrap: wrap;
      }
      .dashboard-clock-left { text-align: left; }
      .dashboard-clock-time {
        font-size: 56px;
        font-weight: 700;
        letter-spacing: -0.02em;
        color: #292524;
        font-variant-numeric: tabular-nums;
        line-height: 1;
      }
      .dashboard-operator-clock-card.time-night .dashboard-clock-time { color: #f5f0e8; }
      .dashboard-clock-date {
        margin-top: 8px;
        font-size: 13px;
        font-weight: 600;
        color: #92764f;
        text-transform: uppercase;
        letter-spacing: 0.08em;
      }
      .dashboard-operator-clock-card.time-night .dashboard-clock-date { color: #d4af74; }

      .dashboard-clock-right {
        display: flex;
        align-items: center;
        gap: 16px;
        background: #ffffff;
        padding: 16px 28px;
        border-radius: 18px;
        border: 1px solid rgba(179, 136, 79, 0.25);
      }
      .dashboard-operator-clock-card.time-night .dashboard-clock-right {
        background: rgba(255, 255, 255, 0.06);
        border-color: rgba(212, 175, 116, 0.25);
      }
      .dashboard-clock-right .weather-emoji { font-size: 50px; line-height: 1; filter: saturate(0.75); }
      .dashboard-clock-right .weather-info { display: flex; flex-direction: column; text-align: left; }
      .dashboard-clock-right .weather-temp { font-size: 27px; font-weight: 700; color: #292524; line-height: 1.2; }
      .dashboard-operator-clock-card.time-night .weather-temp { color: #f5f0e8; }
      .dashboard-clock-right .weather-label { font-size: 13px; color: #78716c; }
      .dashboard-operator-clock-card.time-night .weather-label { color: #a8a29e; }

      .dashboard-clock-wish {
        margin-top: 22px;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 11px 22px;
        border-radius: 999px;
        background: transparent;
        border: 1px solid #B3884F;
        color: #92764f;
        font-size: 16px;
        font-weight: 600;
        letter-spacing: 0.02em;
      }
      .dashboard-operator-clock-card.time-night .dashboard-clock-wish {
        border-color: #d4af74;
        color: #d4af74;
      }

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

      .dashboard-counter {
        padding: 16px;
        text-align: center;
        background: linear-gradient(145deg, #f4f8fb 0%, #edf2f8 100%);
        border-radius: 10px;
        border: 1px solid var(--line);
        box-shadow: var(--shadow-xs);
      }

      .dashboard-counter strong {
        display: block;
        font-size: 26px;
        font-weight: 800;
        letter-spacing: -0.025em;
        color: var(--brand-dark);
      }

      .dashboard-counter span {
        display: block;
        margin-top: 4px;
        font-size: 10.5px;
        color: var(--muted);
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
      }

      .dashboard-row-list {
        border: 1px solid var(--line);
        border-radius: var(--radius);
        overflow: hidden;
        box-shadow: var(--shadow-sm);
      }

      .dashboard-row {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        cursor: pointer;
        border-left: 3px solid transparent;
        background: #ffffff;
        transition: background 0.1s, border-left-color 0.1s;
      }

      .dashboard-row + .dashboard-row { border-top: 1px solid var(--line-soft); }
      .dashboard-row:hover { background: #f8fbff; }

      .dashboard-row-icon {
        flex: 0 0 auto;
        width: 34px;
        height: 34px;
        border-radius: 50%;
        display: grid;
        place-items: center;
        font-size: 11px;
        font-weight: 800;
        background: var(--wash);
        color: var(--muted);
        border: 1px solid var(--line);
      }

      .dashboard-row-body { flex: 1; min-width: 0; }
      .dashboard-row-title { font-weight: 600; font-size: 13.5px; }
      .dashboard-row-subtitle { margin-top: 2px; color: var(--muted); font-size: 12px; }
      .dashboard-row-meta { flex: 0 0 auto; font-size: 12px; color: var(--muted); font-weight: 700; }
      .dashboard-row-chevron { flex: 0 0 auto; color: #bccad6; font-size: 14px; }

      .dashboard-row.urgent { border-left-color: var(--danger); }
      .dashboard-row.urgent .dashboard-row-icon { background: #fee8e6; color: var(--danger); border-color: #f5c2bd; }
      .dashboard-row.pending { border-left-color: var(--accent); }
      .dashboard-row.pending .dashboard-row-icon { background: #fef3e0; color: var(--accent); border-color: #f6d9a4; }
      .dashboard-row.neutral .dashboard-row-icon { background: var(--wash); color: var(--muted); }

      .dashboard-row-empty { padding: 14px 16px; color: var(--muted); font-size: 13px; background: #ffffff; }
      .dashboard-section-hint { margin: -8px 0 12px; color: var(--muted); font-size: 13px; }

      /* ═══════════════════════════════════════════════════════
         CUSTOMER DETAIL
      ═══════════════════════════════════════════════════════ */

      .customer-detail-grid {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 16px;
      }

      .customer-detail-block {
        padding: 16px;
        border: 1px solid var(--line);
        border-radius: 10px;
        background: #ffffff;
        box-shadow: var(--shadow-sm);
      }

      .customer-info-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
      }

      .customer-info-card {
        min-height: 110px;
        padding: 14px;
        border: 1px solid var(--line);
        border-radius: 9px;
        background: linear-gradient(145deg, #fafcff 0%, #f5f8fd 100%);
      }

      .customer-info-card.full { grid-column: 1 / -1; }

      .customer-info-card span {
        display: block;
        margin-bottom: 8px;
        color: var(--muted);
        font-size: 10.5px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.07em;
      }

      .customer-info-card strong,
      .customer-info-card p { margin: 0; line-height: 1.45; white-space: pre-line; }

      .mini-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
      .mini-table th,
      .mini-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; }
      .mini-table th { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
      .mini-table tbody tr:nth-child(even) td { background: var(--line-soft); }

      .customer-related-section { display: grid; gap: 8px; }
      .customer-related-section h3 { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }

      .customer-related-table th:nth-child(1),
      .customer-related-table td:nth-child(1) { width: 32%; }
      .customer-related-table th:nth-child(2),
      .customer-related-table td:nth-child(2) { width: 18%; }
      .customer-related-table th:nth-child(3),
      .customer-related-table td:nth-child(3) { width: 22%; }
      .customer-related-table th:nth-child(4),
      .customer-related-table td:nth-child(4) { width: 28%; }

      /* ═══════════════════════════════════════════════════════
         INVOICE DETAIL
      ═══════════════════════════════════════════════════════ */

      .invoice-detail-actions {
        display: flex;
        gap: 8px;
        flex-wrap: nowrap;
        align-items: center;
        overflow-x: auto;
      }

      .invoice-detail-actions button { flex: 0 0 auto; white-space: nowrap; }

      #invoiceDetailPanel,
      #salesReceiptDetailPanel,
      #creditNoteDetailPanel {
        position: fixed;
        inset: 0;
        z-index: 75;
        display: grid;
        place-items: start center;
        gap: 14px;
        padding: 32px 24px;
        background: rgba(8,16,30,0.8);
        border: 0;
        border-radius: 0;
        overflow: auto;
        backdrop-filter: blur(4px);
      }

      #invoiceDetailPanel.hidden,
      #salesReceiptDetailPanel.hidden,
      #creditNoteDetailPanel.hidden { display: none !important; }

      #invoiceDetailPanel > .panel-header,
      #salesReceiptDetailPanel > .panel-header,
      #creditNoteDetailPanel > .panel-header { width: 1040px; max-width: calc(100vw - 72px); padding: 0; border: 0; background: transparent; }

      #invoiceDetailPanel .preview-modal-toolbar,
      #salesReceiptDetailPanel .preview-modal-toolbar,
      #creditNoteDetailPanel .preview-modal-toolbar { width: 1040px; max-width: 100%; justify-content: center; flex-wrap: nowrap; margin: 0; }

      #salesReceiptDetailPanel .preview-modal-toolbar { justify-content: center; flex-wrap: wrap; gap: 8px; overflow: visible; }
      #salesReceiptDetailPanel .preview-modal-toolbar button { min-height: 40px; padding: 0 12px; font-size: 14px; }

      .invoice-copy { position: relative; margin: 0 auto; box-shadow: var(--shadow-xl); }
      .invoice-copy .doc-header { grid-template-columns: 1.1fr 0.78fr 0.9fr; }
      .invoice-copy .address-grid { grid-template-columns: 1fr 1fr; }

      .invoice-bottom-row {
        display: flex;
        align-items: flex-end;
        gap: 16px;
        margin-top: 12px;
      }

      .invoice-footer-side {
        flex: 1;
        min-width: 0;
      }

      .invoice-footer-text {
        white-space: pre-line;
        color: #1f2933;
        font-size: 10px;
        line-height: 1.42;
      }

      .invoice-footer-picker {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-bottom: 6px;
      }

      .invoice-footer-picker span { color: #4b5563; font-size: 12px; font-weight: 700; }

      .invoice-footer-picker select {
        min-height: 30px;
        border: 1px solid #c8d0d9;
        border-radius: 7px;
        background: #ffffff;
        color: var(--ink);
        font-size: 12px;
        font-weight: 700;
        padding: 0 26px 0 8px;
      }

      .invoice-bottom-row .totals { margin-left: 0; }

      @keyframes mypos-blink {
        0%, 100% { opacity: 1; }
        50%       { opacity: 0.15; }
      }
      .mypos-blink {
        display: inline-block;
        color: var(--brand);
        font-weight: 700;
        animation: mypos-blink 1s ease-in-out infinite;
      }

      .status-overdue {
        color: #c0392b;
        font-weight: 600;
      }

      /* ═══════════════════════════════════════════════════════
         HAMBURGER / MOBILE SIDEBAR
      ═══════════════════════════════════════════════════════ */

      .sidebar-toggle-btn {
        display: none;
        min-height: 38px;
        width: 38px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: linear-gradient(180deg, #ffffff 0%, #f7fafc 100%);
        color: var(--ink);
        font-size: 18px;
        line-height: 1;
        cursor: pointer;
        flex: 0 0 auto;
        align-items: center;
        justify-content: center;
        box-shadow: var(--shadow-xs);
        transition: background 0.12s, box-shadow 0.12s;
      }

      .sidebar-toggle-btn:hover { background: #f0f5fa; box-shadow: var(--shadow-sm); }

      .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 199;
        background: rgba(8,16,30,0.58);
        backdrop-filter: blur(2px);
      }

      /* ═══════════════════════════════════════════════════════
         AUTH / LOGIN
      ═══════════════════════════════════════════════════════ */

      body.auth-locked .app { display: none; }
      body:not(.auth-locked) .login-screen { display: none; }
      body.auth-locked .chat-widget { display: none; }

      /* ── Login screen ── */
      .login-screen {
        position: relative;
        min-height: 100vh;
        display: grid;
        place-items: center;
        padding: 24px;
        overflow: hidden;
        background:
          radial-gradient(ellipse at 18% 28%, rgba(var(--brand-rgb),0.22) 0%, transparent 52%),
          radial-gradient(ellipse at 82% 72%, rgba(20,184,166,0.12) 0%, transparent 48%),
          linear-gradient(155deg, #07101c 0%, #0c1d35 55%, #091728 100%);
      }

      /* Decorative background circles */
      .login-bg-circle {
        position: absolute;
        border-radius: 50%;
        pointer-events: none;
      }
      .login-bg-c1 {
        width: 520px; height: 520px;
        top: -160px; left: -140px;
        background: radial-gradient(circle, rgba(var(--brand-rgb),0.12) 0%, transparent 70%);
        border: 1px solid rgba(var(--brand-rgb),0.08);
      }
      .login-bg-c2 {
        width: 380px; height: 380px;
        bottom: -100px; right: -80px;
        background: radial-gradient(circle, rgba(20,184,166,0.10) 0%, transparent 70%);
        border: 1px solid rgba(20,184,166,0.07);
      }
      .login-bg-c3 {
        width: 200px; height: 200px;
        top: 40%; right: 12%;
        background: radial-gradient(circle, rgba(var(--brand-rgb),0.07) 0%, transparent 70%);
      }

      /* Card */
      .login-card {
        position: relative;
        z-index: 1;
        width: min(420px, 100%);
        display: grid;
        gap: 18px;
        padding: 0 0 32px;
        border-radius: 20px;
        background: rgba(255,255,255,0.98);
        border: 1px solid rgba(255,255,255,0.15);
        box-shadow:
          0 4px 32px rgba(0,0,0,0.32),
          0 24px 80px rgba(0,0,0,0.28),
          inset 0 1px 0 rgba(255,255,255,0.9);
        backdrop-filter: blur(20px);
        overflow: hidden;
        animation: loginCardIn 0.4s cubic-bezier(0.34,1.3,0.64,1) both;
      }
      @keyframes loginCardIn {
        from { opacity: 0; transform: translateY(28px) scale(0.96); }
        to   { opacity: 1; transform: translateY(0) scale(1); }
      }

      /* Accent top bar */
      .login-card::before {
        content: '';
        display: block;
        height: 4px;
        background: linear-gradient(90deg, var(--brand-dark) 0%, var(--brand-mid) 60%, var(--brand-accent) 100%);
      }

      /* Inner padding wrapper (everything below the top bar) */
      .login-card > *:not(:first-child) { padding-left: 36px; padding-right: 36px; }
      .login-card > .login-logo { padding-top: 28px; }

      /* Logo */
      .login-logo { display: flex; justify-content: center; }
      .login-logo-mark { display: flex; align-items: baseline; gap: 10px; }
      .login-logo-mark-word { font-size: 32px; font-weight: 800; letter-spacing: -0.025em; color: var(--ink); }
      .login-logo-mark-word-accent {
        font-size: 20px; font-weight: 700;
        background: linear-gradient(135deg, var(--brand-mid) 0%, var(--brand-dark) 100%);
        -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
      }
      .login-logo-mark-divider { width: 1px; height: 24px; background: var(--line); align-self: center; }
      .login-logo-bar {
        width: 40px; height: 3px;
        background: linear-gradient(90deg, var(--brand) 0%, var(--brand-mid) 100%);
        border-radius: 2px; margin: 0 auto;
      }
      .login-logo-tagline {
        margin: 0; text-align: center;
        font-size: 10px; font-weight: 700; letter-spacing: 0.16em;
        text-transform: uppercase; color: var(--muted-light);
      }
      .login-logo.has-image ~ .login-logo-bar,
      .login-logo.has-image ~ .login-logo-tagline { display: none; }
      .login-logo.has-image .login-logo-mark { display: none; }
      .login-logo img { max-width: 200px; max-height: 80px; object-fit: contain; }
      .login-logo img.hidden { display: none; }

      /* Title row */
      .login-title-row { display: grid; gap: 4px; }
      .login-card h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.025em; color: var(--ink); }
      .login-subtitle { margin: 0; font-size: 13px; color: var(--muted); }

      /* Input fields */
      .login-field { display: grid; gap: 6px; }
      .login-field-label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); letter-spacing: 0.01em; }
      .login-input-wrap { position: relative; }
      .login-input-icon {
        position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
        color: var(--muted-light); pointer-events: none;
        transition: color 0.15s;
      }
      .login-input {
        width: 100%; box-sizing: border-box;
        min-height: 46px; padding: 0 14px 0 40px;
        font-size: 14.5px; font-family: inherit;
        border: 1.5px solid #d4dce8;
        border-radius: 10px;
        background: #f8fafd;
        color: var(--ink);
        outline: none;
        transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
      }
      .login-input:focus {
        border-color: var(--brand-mid);
        background: #fff;
        box-shadow: 0 0 0 3px rgba(13,148,136,0.12), inset 0 0 0 1px rgba(13,148,136,0.06);
      }
      .login-input-wrap:has(.login-input:focus) .login-input-icon { color: var(--brand-mid); }

      /* Login button */
      .login-btn {
        display: flex; align-items: center; justify-content: center; gap: 8px;
        min-height: 48px; width: 100%;
        background: linear-gradient(135deg, var(--brand-mid) 0%, var(--brand-dark) 100%);
        color: #fff;
        border: none; border-radius: 10px;
        font-family: inherit; font-size: 15px; font-weight: 700;
        letter-spacing: 0.02em; cursor: pointer;
        box-shadow: 0 4px 16px rgba(var(--brand-rgb),0.40), 0 1px 4px rgba(var(--brand-rgb),0.25);
        transition: filter 0.15s, transform 0.12s, box-shadow 0.15s;
        margin-top: 4px;
      }
      .login-btn:hover {
        filter: brightness(1.08);
        transform: translateY(-1px);
        box-shadow: 0 6px 22px rgba(var(--brand-rgb),0.50), 0 2px 6px rgba(var(--brand-rgb),0.28);
      }
      .login-btn:active { transform: translateY(1px); filter: brightness(0.97); }

      /* Footer */
      .login-footer {
        margin: 0 !important; text-align: center;
        font-size: 11px; color: var(--muted-light);
        letter-spacing: 0.04em;
      }

      /* ═══════════════════════════════════════════════════════
         SESSION / USER
      ═══════════════════════════════════════════════════════ */

      .session-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

      .session-user {
        min-height: 34px;
        display: inline-flex;
        align-items: center;
        border: 1px solid #9ed8ce;
        border-radius: 999px;
        background: linear-gradient(90deg, var(--brand-light) 0%, var(--brand-pale) 100%);
        color: var(--brand-dark);
        padding: 0 14px;
        font-size: 13px;
        font-weight: 700;
        box-shadow: var(--shadow-xs);
      }

      .access-settings-box { gap: 18px; padding: 20px; }
      .access-settings-box .grid-2 { gap: 16px; }
      .access-settings-box input { min-height: 46px; font-size: 16px; }
      .access-settings-box .customer-list th,
      .access-settings-box .customer-list td { padding: 14px 16px; font-size: 15px; }

      /* ═══════════════════════════════════════════════════════
         MODALS
      ═══════════════════════════════════════════════════════ */

      .modal-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1000;
        display: grid;
        place-items: center;
        padding: 20px;
        background: rgba(8,16,30,0.64);
        backdrop-filter: blur(4px);
      }

      .modal-card {
        width: min(460px, 100%);
        display: grid;
        gap: 14px;
        padding: 24px;
        border-radius: 16px;
        border: 1px solid var(--line);
        background: #ffffff;
        box-shadow: var(--shadow-xl);
        animation: modal-in 0.18s cubic-bezier(0.2, 0.8, 0.4, 1) both;
      }

      @keyframes modal-in {
        from { opacity: 0; transform: scale(0.96) translateY(8px); }
        to   { opacity: 1; transform: scale(1) translateY(0); }
      }

      .modal-card h3 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
      .modal-card p { margin: 0; color: var(--muted); line-height: 1.5; font-size: 14px; }
      .modal-error { min-height: 20px; color: var(--danger); font-size: 13px; font-weight: 700; }
      .modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
      .modal-card.modal-wide { width: min(820px, 100%); max-height: 90vh; overflow-y: auto; }
      .inv-edit-line-input { width: 100%; box-sizing: border-box; padding: 4px 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; font-size: 13px; background: var(--surface); }
      .inv-edit-line-input:focus { outline: none; border-color: var(--brand-mid); }
      .inv-edit-del-btn { background: none; border: none; cursor: pointer; color: var(--danger); font-size: 16px; padding: 0 4px; line-height: 1; }
      #invoiceEditLinesBody td { padding: 3px 4px; vertical-align: middle; }
      .inv-edit-section-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 4px 0 2px; }
      .inv-edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
      @media (max-width: 600px) { .inv-edit-grid { grid-template-columns: 1fr; } }

      /* ═══════════════════════════════════════════════════════
         DOCUMENT CONTENT (print layout)
      ═══════════════════════════════════════════════════════ */

      .company-info { font-size: 13px; line-height: 1.35; }
      .company-info strong { display: block; font-size: 21px; margin-bottom: 8px; }

      .doc-title {
        align-self: end;
        margin: 0 0 6px;
        max-width: 260px;
        font-size: 28px;
        font-weight: 400;
        line-height: 1.15;
        text-align: right;
        overflow-wrap: anywhere;
      }

      .doc-meta { display: grid; grid-template-columns: 1fr 1fr; min-height: 72px; border-bottom: 1px solid #9b9b9b; }
      .doc-meta-left { padding: 8px 8px; border-right: 1px solid #9b9b9b; display: grid; gap: 5px; align-content: start; font-size: 13px; }
      .meta-row { display: grid; grid-template-columns: 190px 1fr; }
      .meta-row strong::before { content: ": "; }
      .customer-band { padding: 4px 8px; border-bottom: 1px solid #9b9b9b; background: #f0f1f2; font-size: 13px; font-weight: 800; }

      .address-grid { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid #9b9b9b; }
      .customer-box { min-height: 132px; padding: 8px; line-height: 1.45; font-size: 14px; }
      .customer-box:first-child { border-right: 1px solid #9b9b9b; }
      .address-heading { display: block; margin-bottom: 8px; font-weight: 800; }
      .address-text { display: block; white-space: pre-line; }

      .sales-receipt-copy .doc-header { grid-template-columns: 1fr 1fr; min-height: 178px; padding: 30px 26px 24px; border-bottom: 1px solid #9b9b9b; }
      .sales-receipt-copy .doc-header > div:first-child { grid-column: 2; grid-row: 1; justify-self: end; align-self: center; }
      .sales-receipt-copy .doc-logo { width: 360px; height: 88px; font-size: 48px; letter-spacing: 11px; }
      .sales-receipt-copy .doc-logo span { margin-top: 13px; font-size: 10px; letter-spacing: 1.8px; }
      .sales-receipt-copy .doc-logo img { width: 360px; max-height: 88px; }
      .sales-receipt-copy .company-info { grid-column: 1; grid-row: 1; font-size: 14px; line-height: 1.38; }
      .sales-receipt-copy .company-info strong { font-size: 22px; margin-bottom: 10px; }
      .sales-receipt-copy .doc-title { max-width: none; margin: 0 0 6px; font-size: 30px; font-weight: 800; text-align: left; }

      .sales-receipt-top { grid-template-columns: 1fr 1fr; display: grid; min-height: 150px; padding: 20px 26px 20px; column-gap: 44px; }
      .sales-receipt-top-left { display: grid; align-content: start; gap: 18px; }
      .sales-receipt-number { display: flex; gap: 8px; align-items: baseline; color: #333333; font-size: 15px; }
      .sales-receipt-number strong { font-weight: 700; }
      .sales-receipt-date { display: flex; justify-content: space-between; align-items: baseline; align-self: end; gap: 24px; padding-bottom: 48px; color: #333333; font-size: 15px; font-weight: 800; }
      .sales-receipt-date .meta-row { width: 100%; justify-content: space-between; }
      #creditNoteCopy .sales-receipt-date { align-self: start; padding-bottom: 0; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 6px; }
      .sales-receipt-copy .meta-row { display: flex; gap: 8px; align-items: baseline; }
      .sales-receipt-copy .meta-row strong::before { content: ""; }
      .sales-receipt-copy .customer-band,
      .sales-receipt-copy .address-grid { display: none; }
      .sales-receipt-bill-to { min-height: 0; padding: 0; white-space: pre-line; line-height: 1.42; color: #2c2c2c; font-size: 14px; }
      .sales-receipt-bill-to > strong { display: block; margin-bottom: 9px; color: #111111; font-size: 15px; }
      .receipt-customer-name { display: inline-block; margin-bottom: 2px; color: #333333; font-weight: 800; }

      .sales-receipt-summary { display: grid; grid-template-columns: 1fr minmax(330px, 380px); min-height: 0; border-bottom: 1px solid #9b9b9b; }
      .sales-receipt-summary-left { padding: 10px 10px 8px; display: grid; align-content: start; gap: 18px; min-height: 0; }
      .sales-receipt-copy .totals { width: 100%; border-bottom: 0; }
      .sales-receipt-payment-details { padding: 0; align-self: stretch; line-height: 1.5; font-size: 13px; }
      .sales-receipt-payment-details strong { display: block; margin-bottom: 6px; font-size: 14px; }
      .payment-detail-row { display: grid; grid-template-columns: 140px 1fr; gap: 10px; }
      .sales-receipt-copy .note { margin: 0; min-height: 0; padding: 0; }
      .sales-receipt-copy .note strong { color: #111111; font-weight: 800; }
      .sales-receipt-copy.no-discount .receipt-discount-column { display: none; }
      #salesReceiptEditorPanel .entry-actions { justify-content: flex-end; }

      .doc-block h3 { margin: 0 0 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0; }
      .doc-block p { margin: 0; line-height: 1.55; white-space: pre-line; }

      table { width: 100%; border-collapse: collapse; margin: 0; }

      th {
        padding: 9px 7px;
        text-align: left;
        border-right: 1px solid #9b9b9b;
        border-bottom: 1px solid #9b9b9b;
        background: #f0f1f2;
        font-size: 12px;
        color: #111111;
        vertical-align: bottom;
      }

      td {
        padding: 5px 7px;
        border-right: 1px solid #9b9b9b;
        border-bottom: 1px solid #9b9b9b;
        vertical-align: top;
        font-size: 13px;
      }

      th:last-child, td:last-child { border-right: 0; }
      th.index, th.qty, th.money,
      td.index, td.qty, td.money { text-align: right; }
      td.index { text-align: center; }

      .totals {
        margin-left: auto;
        width: min(360px, 100%);
        display: grid;
        gap: 0;
        border-left: 1px solid #9b9b9b;
        border-bottom: 1px solid #9b9b9b;
      }

      .total-row {
        display: flex;
        justify-content: space-between;
        gap: 18px;
        min-height: 28px;
        padding: 4px 8px;
        font-size: 13px;
      }

      .total-row.final { margin-top: 0; padding-top: 4px; border-top: 0; font-size: 14px; font-weight: 900; }
      .total-row.payment-made { color: #c1121f; }
      .total-row.balance-due { font-size: 16px; font-weight: 900; }

      .note {
        margin: -95px 380px 0 0;
        min-height: 95px;
        padding: 22px 10px 8px;
        border-left: 0;
        background: transparent;
        line-height: 1.55;
        font-size: 13px;
      }

      .note strong { display: block; margin-bottom: 4px; color: #444444; font-weight: 400; }

      .footer {
        margin-top: 545px;
        color: var(--muted);
        font-size: 12px;
        display: flex;
        justify-content: space-between;
        gap: 18px;
        border-top: 0;
        padding: 0 12px 8px;
      }

      /* ═══════════════════════════════════════════════════════
         RESPONSIVE
      ═══════════════════════════════════════════════════════ */

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

        .sidebar {
          display: none;
          position: fixed;
          top: 0; left: 0; bottom: 0;
          z-index: 200;
          width: 282px;
          height: 100%;
          overflow-y: auto;
        }

        body.sidebar-open .sidebar { display: flex; }
        body.sidebar-open .sidebar-backdrop { display: block; }
        .sidebar-toggle-btn { display: flex; }
        .content { grid-template-columns: 1fr; }
        body.preview-open #previewPanel { padding: 18px 12px; }
      }

      @media (max-width: 620px) {
        .topbar { align-items: flex-start; flex-direction: column; }
        .content { padding: 14px 16px; }
        .grid-2, .order-address-fields, .address-grid, .doc-grid, .doc-header { grid-template-columns: 1fr; }
        .line-item { grid-template-columns: 1fr; }
        .editor-bottom { grid-template-columns: 1fr; }
        .doc-body { padding: 24px; }
        .doc-title { max-width: none; text-align: left; }
        .document { min-height: 0; }
      }

      /* ═══════════════════════════════════════════════════════
         PACKING LIST
      ═══════════════════════════════════════════════════════ */

      #packingListPrintArea { display: none; }

      .packing-list-doc { font-family: sans-serif; color: #1f2937; }

      .pl-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding-bottom: 14px; border-bottom: 2px solid #1f2937; margin-bottom: 20px; }

      .pl-logo { max-height: 64px; max-width: 200px; object-fit: contain; }

      .pl-title-block { text-align: right; }

      .pl-title { font-size: 26px; font-weight: 700; letter-spacing: 3px; color: #1f2937; margin: 0 0 6px; }

      .pl-meta { font-size: 13px; line-height: 1.7; color: #374151; }

      .pl-table { width: 100%; border-collapse: collapse; margin-bottom: 28px; font-size: 13px; }

      .pl-table thead tr { background: #1f2937; }

      .pl-table th { padding: 8px 10px; color: #ffffff; font-size: 12px; font-weight: 600; text-align: left; }

      .pl-table td { padding: 8px 10px; border-bottom: 1px solid #e5e7eb; }

      .pl-tc { width: 80px; text-align: center !important; }

      .pl-table th.pl-tc { text-align: center; }

      .pl-total-pkg { display: flex; align-items: center; gap: 16px; margin: 24px 0 0; font-size: 14px; font-weight: 600; color: #1f2937; }

      .pl-pkg-box { display: inline-block; width: 120px; height: 36px; border: 1.5px solid #1f2937; border-radius: 4px; }

      .pl-delivery-note { margin-top: 24px; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 8.5px; color: #4b5563; line-height: 1.45; }
      .pl-delivery-note strong { display: block; margin-bottom: 5px; font-size: 8.5px; text-transform: uppercase; letter-spacing: 0.03em; }
      .pl-delivery-note span { white-space: pre-line; }

      .pl-footer { display: flex; justify-content: flex-end; align-items: flex-end; margin-top: 16px; }

      .pl-gen-date { font-size: 11px; color: #9ca3af; }

      /* Packing list — badge stato */
      .pl-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; margin-left: 8px; vertical-align: middle; }
      .pl-badge-todo { background: #fef9c3; color: #854d0e; }
      .pl-badge-partial { background: #fed7aa; color: #9a3412; }
      .pl-badge-done { background: #dcfce7; color: #166534; }

      /* Packing list — storico */
      .pl-history-row { display: grid; grid-template-columns: 140px 90px 1fr auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid #f3f4f6; font-size: 13px; }
      .pl-history-num { font-weight: 600; color: #1f2937; }
      .pl-history-date { color: #9ca3af; }
      .pl-history-lines { color: #374151; }

      /* Packing list — riga articolo completamente spedita */
      .pl-row-done td { color: #9ca3af; }

      /* ═══════════════════════════════════════════════════════
         TECHNICAL DRAWINGS
      ═══════════════════════════════════════════════════════ */

      #drawingsPanel { display: flex; flex-direction: column; gap: 0; padding-bottom: 40px; }

      .drawings-upload-form {
        background: var(--wash);
        border: 1px solid var(--line);
        border-radius: var(--radius);
        padding: 16px 20px;
        margin: 0 0 16px;
      }
      .drawings-upload-fields { display: flex; flex-wrap: wrap; gap: 16px; }
      .drawings-upload-field { display: flex; flex-direction: column; gap: 5px; min-width: 200px; flex: 1; }
      .drawings-upload-field label { font-size: 12px; font-weight: 600; color: var(--muted); }
      .drawings-upload-field input, .drawings-upload-field select { padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 13px; background: var(--panel); }
      .drawings-cat-row { display: flex; gap: 8px; align-items: center; }
      .drawings-upload-actions { display: flex; gap: 10px; margin-top: 14px; align-items: center; }
      #drawingsUploadError { font-size: 12px; margin-top: 8px; }

      .drawings-cat-manage {
        background: var(--brand-pale);
        border: 1px solid var(--brand-light);
        border-radius: var(--radius-sm);
        padding: 10px 14px;
        margin: 0 0 14px;
        display: flex;
        align-items: flex-start;
        gap: 12px;
        flex-wrap: wrap;
        font-size: 12px;
        color: var(--muted);
      }
      .drawings-cat-chips { display: flex; flex-wrap: wrap; gap: 8px; }
      .drawings-cat-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 3px 10px 3px 12px; font-size: 12px; font-weight: 500; }
      .drawings-cat-rename, .drawings-cat-delete { background: none; border: none; cursor: pointer; color: var(--muted); padding: 0 2px; font-size: 12px; line-height: 1; }
      .drawings-cat-rename:hover { color: var(--brand); }
      .drawings-cat-delete:hover { color: var(--danger); }
      .drawings-no-cats { font-size: 12px; color: var(--muted-light); font-style: italic; }

      .drawings-cat-filter {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 16px;
        border-bottom: 1px solid var(--line);
        background: var(--surface, var(--panel));
      }
      .drawings-filter-chip {
        background: var(--panel);
        border: 1px solid var(--line);
        border-radius: 20px;
        padding: 4px 14px;
        font-size: 12px;
        font-weight: 500;
        color: var(--ink);
        cursor: pointer;
        transition: background 0.15s, border-color 0.15s, color 0.15s;
      }
      .drawings-filter-chip:hover { border-color: var(--brand); color: var(--brand); }
      .drawings-filter-chip.drawings-filter-active {
        background: var(--brand);
        border-color: var(--brand);
        color: #fff;
      }

      .drawings-list { display: flex; flex-direction: column; gap: 20px; }

      .drawings-group { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
      .drawings-group-header { padding: 9px 16px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: #fff; background: var(--brand); border-bottom: none; }

      .drawings-table { width: 100%; border-collapse: collapse; font-size: 13px; }
      .drawings-table thead th { padding: 8px 12px; text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--wash); }
      .drawings-table tbody tr:not(:last-child) { border-bottom: 1px solid var(--line-soft); }
      .drawings-table tbody tr[data-drawing-id] { cursor: pointer; }
      .drawings-table tbody tr:hover { background: var(--brand-pale); }
      .drawings-table td { padding: 9px 12px; vertical-align: middle; }

      .drawings-col-name { font-weight: 500; }
      .drawings-orig-name { display: block; font-size: 11px; color: var(--muted-light); font-weight: 400; margin-top: 2px; }
      .drawings-col-date, .drawings-col-size { color: var(--muted); font-size: 12px; white-space: nowrap; }
      .drawings-col-actions { white-space: nowrap; text-align: right; }

      .drawings-action-btn { border: none; cursor: pointer; border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; padding: 5px 10px; margin-left: 6px; transition: background 0.15s, color 0.15s; }
      .drawings-open-btn { background: var(--brand-light); color: var(--brand-dark); }
      .drawings-open-btn:hover { background: var(--brand-mid); color: #fff; }
      .drawings-print-btn { background: #e0f2fe; color: #0369a1; }
      .drawings-print-btn:hover { background: #0369a1; color: #fff; }
      .drawings-delete-btn { background: var(--danger-light); color: var(--danger); }
      .drawings-delete-btn:hover { background: var(--danger); color: #fff; }

      .drawings-empty { padding: 40px; text-align: center; color: var(--muted-light); font-size: 14px; }

      /* Modal PDF preview */
      .drawings-modal {
        position: fixed;
        inset: 0;
        z-index: 1200;
        background: rgba(14,28,44,0.55);
        display: flex;
        align-items: stretch;
        justify-content: center;
        padding: 24px;
      }
      .drawings-modal.hidden { display: none; }
      .drawings-modal-inner {
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: 960px;
        background: var(--panel);
        border-radius: var(--radius-lg);
        overflow: hidden;
        box-shadow: var(--shadow-xl);
      }
      .drawings-modal-toolbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        background: var(--ink);
        gap: 12px;
        flex-shrink: 0;
      }
      .drawings-modal-title {
        font-size: 13px;
        font-weight: 600;
        color: #e2e8f0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        flex: 1;
      }
      .drawings-modal-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
      .drawings-modal-btn {
        border: none;
        cursor: pointer;
        border-radius: var(--radius-sm);
        font-size: 12px;
        font-weight: 700;
        padding: 6px 14px;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        gap: 5px;
        transition: opacity 0.15s;
      }
      .drawings-modal-btn:hover { opacity: 0.85; }
      .drawings-modal-print { background: var(--brand-mid); color: #fff; }
      .drawings-modal-download { background: #0369a1; color: #fff; }
      .drawings-modal-close { background: rgba(255,255,255,0.12); color: #e2e8f0; font-size: 14px; padding: 6px 10px; }
      .drawings-modal-frame { flex: 1; border: none; width: 100%; min-height: 0; }

      /* ═══════════════════════════════════════════════════════
         WAREHOUSE STATUS
      ═══════════════════════════════════════════════════════ */

      #warehousePanel { overflow: visible; display: flex; flex-direction: column; }

      .wh-table-wrap {
        overflow-x: auto;
        overflow-y: auto;
        max-height: calc(100vh - 120px);
        -webkit-overflow-scrolling: touch;
      }

      .wh-table {
        width: 100%;
        min-width: 860px;
        border-collapse: collapse;
        font-size: 13px;
      }

      .wh-table thead th {
        padding: 9px 10px;
        text-align: center;
        font-size: 11px;
        font-weight: 700;
        color: var(--muted);
        border-bottom: 2px solid var(--line);
        background: var(--wash);
        white-space: nowrap;
        position: sticky;
        top: 0;
        z-index: 1;
      }

      .wh-th-name  { text-align: center !important; width: 140px; }
      .wh-th-variations { text-align: left !important; min-width: 420px; }
      .wh-th-onorder { min-width: 140px; }
      .wh-th-actions { width: 130px; }

      .wh-table tbody tr:not(:last-child) { border-bottom: 1px solid var(--line-soft); }
      .wh-table tbody tr:hover { background: var(--brand-pale); }
      .wh-table td { padding: 8px 10px; vertical-align: middle; }

      /* Product cell: photo + name inline */
      .wh-product-cell { display: flex; flex-direction: column; align-items: center; gap: 5px; text-align: center; }
      .wh-thumb {
        width: 44px;
        height: 44px;
        object-fit: cover;
        border-radius: var(--radius-sm);
        border: 1px solid var(--line);
        display: block;
        flex-shrink: 0;
        box-shadow: var(--shadow-sm);
      }
      .wh-thumb-placeholder {
        width: 44px;
        height: 44px;
        border-radius: var(--radius-sm);
        background: var(--wash-deep);
        border: 1px dashed var(--line);
        flex-shrink: 0;
      }
      .wh-product-name { font-weight: 600; color: var(--ink); font-size: 12px; word-break: break-word; max-width: 140px; }

      /* Variations cell: one mini stepper card per applicable finish */
      .wh-variations-cell { padding-top: 10px; padding-bottom: 10px; }
      .wh-variations-row { display: flex; flex-wrap: wrap; gap: 10px; }
      .wh-variation-card {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 5px;
        padding: 7px 10px;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: var(--wash);
        min-width: 84px;
      }
      .wh-variation-label { font-size: 11px; font-weight: 600; color: var(--muted); white-space: nowrap; }
      .wh-variation-stepper { display: flex; align-items: center; gap: 8px; }
      .wh-qty-step {
        width: 22px;
        height: 22px;
        min-height: 22px;
        padding: 0;
        border: 1px solid var(--line);
        border-radius: 50%;
        background: #ffffff;
        color: var(--ink-soft);
        font-size: 14px;
        line-height: 1;
        cursor: pointer;
        flex-shrink: 0;
        transition: background 0.12s, border-color 0.12s;
      }
      .wh-qty-step:hover { background: var(--brand-light); border-color: var(--brand-mid); color: var(--brand-dark); }
      .wh-qty-value {
        min-width: 22px;
        text-align: center;
        font-weight: 700;
        color: var(--danger);
        cursor: pointer;
        border-radius: var(--radius-sm);
      }
      .wh-qty-value:hover { background: var(--brand-light); }
      .wh-qty-editable { transition: background 0.15s; }

      .wh-cell-input {
        width: 64px !important;
        min-height: 30px !important;
        padding: 4px 6px !important;
        text-align: center;
        font-size: 13px;
        border: 2px solid var(--brand-mid) !important;
        border-radius: var(--radius-sm);
        outline: none;
      }

      @keyframes wh-saved-flash {
        0%   { background: #dcfce7; color: #15803d; }
        70%  { background: #dcfce7; color: #15803d; }
        100% { background: transparent; color: inherit; }
      }
      .wh-qty-saved { animation: wh-saved-flash 1.4s ease-out forwards; }

      /* On-order cell */
      .wh-onorder-cell {
        cursor: pointer;
        min-width: 120px;
        font-size: 12px;
        color: var(--muted);
        border-radius: var(--radius-sm);
        transition: background 0.15s;
      }
      .wh-onorder-cell:hover { background: var(--warning-light); }
      .wh-onorder-input {
        width: 100% !important;
        min-height: 28px !important;
        padding: 3px 6px !important;
        font-size: 12px;
        border: 2px solid var(--warning) !important;
        border-radius: var(--radius-sm);
        outline: none;
      }

      @keyframes wh-order-pulse {
        0%, 100% { background: #fffbeb; }
        50%       { background: #fde68a; }
      }
      .wh-onorder-active {
        animation: wh-order-pulse 2.5s ease-in-out infinite;
        color: #92400e !important;
        font-weight: 700;
      }

      /* Actions cell */
      .wh-actions-cell { white-space: nowrap; text-align: right; }
      .wh-actions-cell .soft-button,
      .wh-actions-cell .danger-button { min-height: 28px; font-size: 11px; padding: 0 9px; margin-left: 4px; }

      /* Empty state */
      .wh-empty { text-align: center; padding: 48px 20px; color: var(--muted-light); font-size: 14px; }

      .wh-group-header td {
        background: var(--brand);
        color: #ffffff;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.09em;
        text-transform: uppercase;
        padding: 6px 12px;
        border-top: none;
      }
      @media (prefers-color-scheme: dark) {
        .wh-group-header td { background: var(--brand-dark); color: var(--brand-dark-text); }
      }
      :root[data-theme="dark"] .wh-group-header td { background: var(--brand-dark); color: var(--brand-dark-text); }
      :root[data-theme="light"] .wh-group-header td { background: var(--brand); color: #ffffff; }

      /* Product modal */
      .wh-modal {
        position: fixed;
        inset: 0;
        z-index: 1200;
        background: rgba(14,28,44,0.5);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 24px;
      }
      .wh-modal.hidden { display: none; }
      .wh-modal-inner {
        background: var(--panel);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-xl);
        width: 100%;
        max-width: 520px;
        display: flex;
        flex-direction: column;
        max-height: 90vh;
        overflow: hidden;
      }
      .wh-modal-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px;
        border-bottom: 1px solid var(--line);
        background: linear-gradient(180deg, #fafcff 0%, #f5f8fb 100%);
        flex-shrink: 0;
      }
      .wh-modal-title { margin: 0; font-size: 15px; font-weight: 700; color: var(--ink); }
      .wh-modal-close {
        background: none;
        border: none;
        cursor: pointer;
        color: var(--muted);
        font-size: 18px;
        padding: 0 4px;
        line-height: 1;
        min-height: auto;
        width: auto;
      }
      .wh-modal-close:hover { color: var(--danger); }
      .wh-modal-body {
        padding: 20px;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        gap: 16px;
      }
      .wh-modal-footer {
        display: flex;
        gap: 10px;
        justify-content: flex-end;
        padding: 14px 20px;
        border-top: 1px solid var(--line);
        background: var(--wash);
        flex-shrink: 0;
      }
      .wh-form-field { display: flex; flex-direction: column; gap: 6px; }
      .wh-form-field > label {
        font-size: 11px;
        font-weight: 700;
        color: var(--muted);
        text-transform: uppercase;
        letter-spacing: 0.06em;
        display: block;
      }
      .wh-form-field input[type="text"] { font-size: 14px; }

      .wh-finishes-grid {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
      }
      .wh-finish-label {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        font-size: 13px;
        font-weight: 500;
        color: var(--ink-soft);
        text-transform: none;
        letter-spacing: 0;
        cursor: pointer;
        background: var(--wash);
        border: 1px solid var(--line);
        border-radius: 20px;
        padding: 4px 12px 4px 8px;
        transition: background 0.12s, border-color 0.12s;
      }
      .wh-finish-label input[type="checkbox"] { width: auto; min-height: auto; margin: 0; cursor: pointer; }
      .wh-finish-label:hover { background: var(--brand-light); border-color: var(--brand-mid); }

      .wh-finish-label-custom { padding-right: 4px; gap: 3px; }
      .wh-finish-label-inner { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
      .wh-finish-delete {
        display: inline-flex; align-items: center; justify-content: center;
        width: 16px; height: 16px; min-height: 16px; padding: 0; margin: 0;
        border: none; border-radius: 50%; background: none;
        color: var(--muted); font-size: 11px; line-height: 1; cursor: pointer;
        transition: background 0.12s, color 0.12s;
      }
      .wh-finish-delete:hover { background: var(--danger); color: #ffffff; }

      .wh-altro-section { margin-top: 10px; display: flex; flex-direction: column; gap: 7px; }
      .wh-altro-row { display: flex; gap: 6px; align-items: center; }
      .wh-altro-row input[type="text"] { flex: 1; min-height: 32px; font-size: 13px; padding: 5px 9px; }
      .wh-altro-remove {
        background: none; border: 1px solid var(--line); border-radius: var(--radius-sm);
        cursor: pointer; color: var(--muted); font-size: 13px; padding: 0 8px; min-height: 32px;
        width: auto; flex-shrink: 0; transition: color 0.12s, border-color 0.12s;
      }
      .wh-altro-remove:hover { color: var(--danger); border-color: var(--danger); }
      .wh-altro-add-btn { align-self: flex-start; min-height: 30px; font-size: 12px; padding: 0 11px; }

      .wh-drop-zone {
        border: 2px dashed var(--line);
        border-radius: var(--radius);
        padding: 18px 14px;
        text-align: center;
        cursor: pointer;
        transition: border-color 0.15s, background 0.15s;
        min-height: 110px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--wash);
        user-select: none;
      }
      .wh-drop-zone:hover { border-color: var(--brand-mid); background: var(--brand-pale); }
      .wh-drop-zone.drag-over {
        border-color: var(--brand);
        border-style: solid;
        background: var(--brand-light);
      }
      .wh-drop-preview {
        max-width: 180px;
        max-height: 180px;
        border-radius: var(--radius);
        object-fit: cover;
        box-shadow: var(--shadow-md);
        display: block;
      }
      .wh-drop-hint { display: flex; flex-direction: column; gap: 5px; align-items: center; pointer-events: none; }
      .wh-drop-icon { font-size: 30px; line-height: 1; }
      .wh-drop-hint > div:not(.wh-drop-icon) { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
      .wh-drop-hint-sub { font-size: 11px; color: var(--muted); font-weight: 400 !important; }

      .wh-photo-url-row { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
      .wh-photo-url-input { flex: 1; min-height: 32px; font-size: 13px; padding: 5px 9px; }
      .wh-photo-url-row .soft-button { flex-shrink: 0; min-height: 32px; font-size: 12px; padding: 0 11px; }

      /* ═══════════════════════════════════════════════════════
         PRINT
      ═══════════════════════════════════════════════════════ */

      @media print {
        body { background: #ffffff; }
        .sidebar, .topbar, .editor { display: none; }
        .app, .main, .content { display: block; padding: 0; }
        .preview-wrap { padding: 0; }
        .document { box-shadow: none; border: 0; border-radius: 0; max-width: none; }

        body.printing-invoice .preview-wrap,
        body.printing-sales-receipt .preview-wrap,
        body.printing-credit-note .preview-wrap,
        body.printing-order #orderPanel,
        body.printing-order #customersPanel,
        body.printing-order #settingsPanel,
        body.printing-order .preview-modal-toolbar,
        body.printing-invoice #orderPanel,
        body.printing-sales-receipt #orderPanel,
        body.printing-credit-note #orderPanel,
        body.printing-invoice #customersPanel,
        body.printing-sales-receipt #customersPanel,
        body.printing-credit-note #customersPanel,
        body.printing-invoice #settingsPanel,
        body.printing-sales-receipt #settingsPanel,
        body.printing-credit-note #settingsPanel,
        body.printing-invoice #invoicesPanel .settings-box:first-child,
        body.printing-sales-receipt #salesReceiptsPanel .settings-box:first-child,
        body.printing-credit-note #creditNotesPanel .settings-box:first-child,
        body.printing-invoice #invoiceDetailPanel > :not(.invoice-copy),
        body.printing-sales-receipt #salesReceiptDetailPanel > :not(.invoice-copy),
        body.printing-credit-note #creditNoteDetailPanel > :not(.invoice-copy),
        body.printing-invoice .invoice-detail-actions,
        body.printing-sales-receipt .invoice-detail-actions,
        body.printing-credit-note .invoice-detail-actions,
        body.printing-invoice .invoice-footer-picker { display: none !important; }

        body.printing-order #previewPanel,
        body.printing-order .preview-wrap,
        body.printing-order .document,
        body.printing-invoice #invoicesPanel,
        body.printing-sales-receipt #salesReceiptsPanel,
        body.printing-credit-note #creditNotesPanel,
        body.printing-invoice #invoiceDetailPanel,
        body.printing-sales-receipt #salesReceiptDetailPanel,
        body.printing-credit-note #creditNoteDetailPanel,
        body.printing-invoice .invoice-copy,
        body.printing-sales-receipt .invoice-copy,
        body.printing-credit-note .invoice-copy { display: grid !important; border: 0; }

        body.printing-order #previewPanel { position: static !important; inset: auto !important; padding: 0 !important; background: #ffffff !important; overflow: visible !important; }

        body.printing-invoice #invoiceDetailPanel,
        body.printing-sales-receipt #salesReceiptDetailPanel,
        body.printing-credit-note #creditNoteDetailPanel { position: static !important; inset: auto !important; padding: 0 !important; background: #ffffff !important; overflow: visible !important; }

        body.printing-invoice .invoice-copy,
        body.printing-sales-receipt .invoice-copy,
        body.printing-credit-note .invoice-copy,
        body.printing-order .document { box-shadow: none; margin: 0; max-width: none; width: 100%; min-height: 0 !important; height: auto !important; overflow: visible !important; }

        @page { size: A4; margin: 10mm; }

        body.printing-order,
        body.printing-invoice,
        body.printing-sales-receipt,
        body.printing-credit-note { width: 190mm; min-height: 0; margin: 0 !important; box-sizing: border-box !important; background: #ffffff !important; }

        body.printing-order .app, body.printing-invoice .app, body.printing-sales-receipt .app, body.printing-credit-note .app,
        body.printing-order .main, body.printing-invoice .main, body.printing-sales-receipt .main, body.printing-credit-note .main,
        body.printing-order .content, body.printing-invoice .content, body.printing-sales-receipt .content, body.printing-credit-note .content { display: block !important; width: 190mm !important; min-height: 0 !important; margin: 0 !important; padding: 0 !important; box-sizing: border-box !important; }

        body.printing-order .content > :not(#previewPanel),
        body.printing-invoice .content > :not(#invoicesPanel),
        body.printing-sales-receipt .content > :not(#salesReceiptsPanel),
        body.printing-credit-note .content > :not(#creditNotesPanel),
        body.printing-order #previewPanel > :not(.document),
        body.printing-invoice #invoiceDetailPanel > :not(.invoice-copy),
        body.printing-sales-receipt #salesReceiptDetailPanel > :not(.invoice-copy),
        body.printing-credit-note #creditNoteDetailPanel > :not(.invoice-copy) { display: none !important; }

        body.printing-order #previewPanel,
        body.printing-invoice #invoicesPanel,
        body.printing-sales-receipt #salesReceiptsPanel,
        body.printing-credit-note #creditNotesPanel,
        body.printing-invoice #invoiceDetailPanel,
        body.printing-sales-receipt #salesReceiptDetailPanel,
        body.printing-credit-note #creditNoteDetailPanel { display: block !important; position: static !important; inset: auto !important; width: 190mm !important; margin: 0 !important; padding: 0 !important; box-sizing: border-box !important; background: #ffffff !important; overflow: visible !important; }

        body.printing-order #previewPanel .document,
        body.printing-invoice #invoiceDetailPanel .invoice-copy,
        body.printing-sales-receipt #salesReceiptDetailPanel .invoice-copy,
        body.printing-credit-note #creditNoteDetailPanel .invoice-copy { display: block !important; width: 190mm !important; max-width: 190mm !important; min-height: 0 !important; height: auto !important; margin: 0 !important; box-sizing: border-box !important; border: 0 !important; box-shadow: none !important; transform: none !important; }

        body.printing-invoice #invoicesPanel > .panel-header,
        body.printing-sales-receipt #salesReceiptsPanel > .panel-header,
        body.printing-credit-note #creditNotesPanel > .panel-header,
        body.printing-invoice #invoicesPanel .form > :not(#invoiceDetailPanel),
        body.printing-sales-receipt #salesReceiptsPanel .form > :not(#salesReceiptDetailPanel),
        body.printing-credit-note #creditNotesPanel .form > :not(#creditNoteDetailPanel),
        body.printing-order #previewPanel > .preview-modal-toolbar { display: none !important; }

        body.printing-invoice #invoicesPanel .form,
        body.printing-sales-receipt #salesReceiptsPanel .form,
        body.printing-credit-note #creditNotesPanel .form { display: block !important; margin: 0 !important; padding: 0 !important; }

        body.printing-order #previewPanel .document,
        body.printing-invoice #invoiceDetailPanel .invoice-copy,
        body.printing-sales-receipt #salesReceiptDetailPanel .invoice-copy,
        body.printing-credit-note #creditNoteDetailPanel .invoice-copy { height: auto !important; overflow: visible !important; page-break-before: avoid !important; page-break-after: auto !important; page-break-inside: auto !important; break-before: avoid !important; break-after: auto !important; break-inside: auto !important; }

        body.printing-order #previewPanel .document > *:last-child,
        body.printing-invoice #invoiceDetailPanel .invoice-copy > *:last-child,
        body.printing-sales-receipt #salesReceiptDetailPanel .invoice-copy > *:last-child,
        body.printing-credit-note #creditNoteDetailPanel .invoice-copy > *:last-child { margin-bottom: 0 !important; page-break-after: auto !important; break-after: auto !important; }

        body.printing-order .doc-body .footer { margin-top: 0 !important; }
        body.printing-order .doc-title { white-space: nowrap; font-size: 22px !important; overflow-wrap: normal !important; }

        /* Packing List */
        body.printing-packing-list { width: 190mm; margin: 0 !important; background: #ffffff !important; }

        body.printing-packing-list .app,
        body.printing-packing-list .main,
        body.printing-packing-list .content { display: block !important; width: 190mm !important; margin: 0 !important; padding: 0 !important; box-sizing: border-box !important; }

        body.printing-packing-list #packingListPanel { display: block !important; position: static !important; width: 190mm !important; margin: 0 !important; padding: 0 !important; background: #ffffff !important; overflow: visible !important; }

        body.printing-packing-list #packingListPanel > .panel-header,
        body.printing-packing-list #packingListPanel > .form { display: none !important; }

        body.printing-packing-list #packingListPrintArea { display: block !important; }

        body.printing-packing-list .content > :not(#packingListPanel) { display: none !important; }
      }

      /* ── Chat widget ─────────────────────────────────────────────── */
      .chat-widget {
        position: fixed;
        bottom: 24px;
        right: 24px;
        z-index: 1200;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 14px;
      }

      /* Window */
      .chat-window {
        display: none;
        flex-direction: column;
        width: 340px;
        height: 460px;
        background: var(--panel);
        border: 1px solid rgba(14,28,44,0.10);
        border-radius: 18px;
        box-shadow: 0 32px 80px rgba(14,28,44,0.22), 0 8px 24px rgba(14,28,44,0.10);
        overflow: hidden;
        transform-origin: bottom right;
      }
      .chat-widget.chat-open .chat-window {
        display: flex;
        animation: chatSlideIn 0.22s cubic-bezier(0.34,1.4,0.64,1) both;
      }
      @keyframes chatSlideIn {
        from { opacity: 0; transform: scale(0.88) translateY(16px); }
        to   { opacity: 1; transform: scale(1) translateY(0); }
      }

      /* Header */
      .chat-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 13px 14px;
        background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
        color: #fff;
        flex-shrink: 0;
      }
      .chat-header-left { display: flex; align-items: center; gap: 10px; }
      .chat-header-avatar {
        width: 34px; height: 34px;
        border-radius: 50%;
        background: rgba(255,255,255,0.2);
        border: 1.5px solid rgba(255,255,255,0.35);
        display: flex; align-items: center; justify-content: center;
        font-size: 13px; font-weight: 700; letter-spacing: 0.02em;
        color: #fff; flex-shrink: 0;
      }
      .chat-header-info { display: flex; flex-direction: column; gap: 2px; }
      .chat-header-title { font-size: 13.5px; font-weight: 700; line-height: 1; letter-spacing: -0.01em; }
      .chat-header-status { display: flex; align-items: center; gap: 5px; font-size: 11px; opacity: 0.8; line-height: 1; }
      .chat-status-dot {
        width: 7px; height: 7px; border-radius: 50%;
        background: #4ade80;
        box-shadow: 0 0 0 2px rgba(74,222,128,0.3);
        flex-shrink: 0;
      }
      .chat-header-actions { display: flex; align-items: center; gap: 4px; }
      .chat-icon-btn {
        background: rgba(255,255,255,0.12);
        border: 1px solid rgba(255,255,255,0.18);
        border-radius: 7px;
        color: #fff;
        cursor: pointer;
        width: 30px; height: 30px;
        display: flex; align-items: center; justify-content: center;
        transition: background 0.15s;
        flex-shrink: 0;
      }
      .chat-icon-btn:hover { background: rgba(255,255,255,0.25); }

      /* Messages area */
      .chat-messages {
        flex: 1;
        overflow-y: auto;
        padding: 14px 12px;
        display: flex;
        flex-direction: column;
        gap: 10px;
        background: #f7f9fb;
      }
      .chat-msg {
        display: flex;
        align-items: flex-end;
        gap: 7px;
        max-width: 86%;
      }
      .chat-msg.chat-msg-mine {
        align-self: flex-end;
        flex-direction: row-reverse;
      }
      .chat-avatar {
        width: 28px; height: 28px;
        border-radius: 50%;
        display: flex; align-items: center; justify-content: center;
        font-size: 10px; font-weight: 700; color: #fff;
        flex-shrink: 0;
        letter-spacing: 0.02em;
      }
      .chat-msg-body {
        display: flex; flex-direction: column; gap: 3px;
        align-items: flex-start;
      }
      .chat-msg-mine .chat-msg-body { align-items: flex-end; }
      .chat-sender { font-size: 10.5px; font-weight: 600; color: var(--muted); margin-left: 2px; }
      .chat-bubble {
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 14px 14px 14px 3px;
        padding: 8px 12px;
        font-size: 13px;
        color: var(--ink);
        word-break: break-word;
        white-space: pre-wrap;
        line-height: 1.45;
        box-shadow: 0 1px 3px rgba(14,28,44,0.06);
      }
      .chat-msg-mine .chat-bubble {
        background: linear-gradient(135deg, var(--brand-mid) 0%, var(--brand-dark) 100%);
        border-color: transparent;
        color: #fff;
        border-radius: 14px 14px 3px 14px;
        box-shadow: 0 2px 8px rgba(var(--brand-rgb),0.30);
      }
      .chat-time {
        font-size: 10px;
        color: var(--muted-light);
        margin: 0 2px;
        opacity: 0;
        transition: opacity 0.15s;
      }
      .chat-msg:hover .chat-time { opacity: 1; }

      /* Input row */
      .chat-input-row {
        display: flex;
        gap: 6px;
        padding: 10px 12px;
        border-top: 1px solid var(--line);
        background: var(--panel);
        flex-shrink: 0;
        align-items: center;
      }
      .chat-compose { flex: 1; display: flex; flex-direction: column; min-width: 0; }
      .chat-input {
        width: 100%;
        box-sizing: border-box;
        resize: none;
        border: 1.5px solid var(--line);
        border-radius: 20px;
        padding: 7px 14px;
        font-size: 13px;
        font-family: inherit;
        background: #f7f9fb;
        color: var(--ink);
        outline: none;
        max-height: 80px;
        overflow-y: auto;
        transition: border-color 0.15s, background 0.15s;
        line-height: 1.4;
      }
      .chat-input:focus { border-color: var(--brand-mid); background: var(--panel); }

      /* File attach button */
      .chat-file-btn {
        background: none;
        border: none;
        padding: 6px;
        cursor: pointer;
        color: var(--muted);
        flex-shrink: 0;
        border-radius: 50%;
        display: flex; align-items: center; justify-content: center;
        transition: color 0.15s, background 0.15s;
      }
      .chat-file-btn:hover { color: var(--brand); background: var(--brand-light); }

      /* Send button */
      .chat-send-btn {
        width: 34px; height: 34px;
        background: var(--brand);
        color: #fff;
        border: none;
        border-radius: 50%;
        display: flex; align-items: center; justify-content: center;
        cursor: pointer;
        flex-shrink: 0;
        box-shadow: 0 2px 8px rgba(var(--brand-rgb),0.35);
        transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
      }
      .chat-send-btn:hover {
        background: var(--brand-dark);
        transform: scale(1.08);
        box-shadow: 0 4px 12px rgba(var(--brand-rgb),0.45);
      }
      .chat-send-btn:active { transform: scale(0.95); }

      /* Toggle button */
      .chat-toggle-btn {
        position: relative;
        width: 54px; height: 54px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--brand-mid) 0%, var(--brand-dark) 100%);
        color: #fff;
        border: none;
        cursor: pointer;
        box-shadow: 0 8px 28px rgba(var(--brand-rgb),0.45), 0 2px 8px rgba(var(--brand-rgb),0.25);
        display: flex; align-items: center; justify-content: center;
        transition: transform 0.18s, box-shadow 0.18s;
      }
      .chat-toggle-btn:hover {
        transform: scale(1.08);
        box-shadow: 0 12px 36px rgba(var(--brand-rgb),0.55), 0 4px 12px rgba(var(--brand-rgb),0.30);
      }
      .chat-toggle-btn:active { transform: scale(0.96); }

      /* Unread badge */
      .chat-badge {
        position: absolute;
        top: -3px; right: -3px;
        background: #ef4444;
        color: #fff;
        font-size: 10px;
        font-weight: 700;
        min-width: 18px; height: 18px;
        border-radius: 9px;
        display: flex; align-items: center; justify-content: center;
        padding: 0 4px;
        border: 2px solid #fff;
        pointer-events: none;
      }
      .chat-badge.hidden { display: none; }

      /* Pulse ring when unread messages */
      .chat-toggle-btn.has-unread::before {
        content: '';
        position: absolute;
        inset: -6px;
        border-radius: 50%;
        border: 2px solid var(--brand-mid);
        animation: chatPulse 1.6s ease-out infinite;
        pointer-events: none;
      }
      @keyframes chatPulse {
        0%   { opacity: 0.7; transform: scale(1); }
        100% { opacity: 0; transform: scale(1.55); }
      }

      /* File message card */
      .chat-img-preview { max-width: 190px; max-height: 160px; border-radius: 10px; display: block; cursor: pointer; box-shadow: 0 2px 8px rgba(14,28,44,0.12); }
      .chat-file-link {
        display: inline-flex; align-items: center; gap: 10px; text-decoration: none;
        background: var(--brand-light); border: 1px solid var(--brand-mid);
        border-radius: 12px; padding: 9px 13px; max-width: 210px;
        color: var(--brand); transition: background 0.15s;
      }
      .chat-file-link:hover { background: #d1f0ed; }
      .chat-fl-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
      .chat-fl-name { font-size: 12.5px; font-weight: 600; word-break: break-word; line-height: 1.3; color: var(--ink); }
      .chat-fl-meta { font-size: 10.5px; color: var(--muted); font-weight: 500; }
      .chat-fl-arrow { flex-shrink: 0; opacity: 0.6; display: flex; align-items: center; }
      .chat-msg-mine .chat-file-link {
        background: rgba(255,255,255,0.18);
        border-color: rgba(255,255,255,0.35);
      }
      .chat-msg-mine .chat-file-link:hover { background: rgba(255,255,255,0.28); }
      .chat-msg-mine .chat-fl-name { color: #fff; }
      .chat-msg-mine .chat-fl-meta { color: rgba(255,255,255,0.75); }
      .chat-msg-mine .chat-fl-arrow { color: #fff; }

      /* Pending file preview chip */
      .chat-file-preview {
        display: flex; align-items: center; gap: 6px;
        background: var(--brand-light); border: 1.5px solid var(--brand-mid);
        border-radius: 20px 20px 0 0;
        padding: 5px 12px; font-size: 12px; color: var(--brand);
      }
      .chat-file-preview.hidden { display: none; }
      .chat-fp-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
      .chat-fp-clear {
        background: none; border: none; cursor: pointer; color: var(--brand);
        font-size: 12px; padding: 0 2px; flex-shrink: 0; opacity: 0.6; line-height: 1;
      }
      .chat-fp-clear:hover { opacity: 1; }
      .chat-file-preview:not(.hidden) + .chat-input { border-radius: 0 0 20px 20px; border-top: none; }

      /* Drag-over highlight */
      .chat-messages.chat-drop-active { background: var(--brand-light); outline: 2px dashed var(--brand-mid); }

      @media print { .chat-widget { display: none !important; } }

      /* ── Brand color picker ─────────────────────────────────── */
      .brand-color-section { display: flex; flex-direction: column; gap: 16px; }

      .brand-presets-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

      .brand-presets { display: flex; flex-wrap: wrap; gap: 10px; }

      .brand-preset-chip {
        width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent;
        cursor: pointer; transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
        box-shadow: 0 2px 6px rgba(0,0,0,0.18);
      }
      .brand-preset-chip:hover { transform: scale(1.15); box-shadow: 0 4px 12px rgba(0,0,0,0.25); }
      .brand-preset-chip.active { border-color: var(--ink); transform: scale(1.12); }

      .brand-picker-row { display: flex; align-items: center; gap: 14px; }
      .brand-picker-row label { font-size: 13px; font-weight: 600; color: var(--ink-soft); white-space: nowrap; }

      #brandColorInput {
        width: 52px; height: 36px; border: 2px solid var(--line);
        border-radius: 8px; cursor: pointer; padding: 2px;
        background: none; transition: border-color 0.15s;
      }
      #brandColorInput:hover { border-color: var(--brand-mid); }

      .brand-preview-bar {
        height: 8px; border-radius: 4px; width: 100%;
        background: linear-gradient(90deg, var(--brand-dark) 0%, var(--brand) 35%, var(--brand-mid) 65%, var(--brand-bright) 100%);
        transition: background 0.3s;
      }

      .brand-color-reset {
        font-size: 12px; color: var(--muted); background: none; border: none;
        cursor: pointer; text-decoration: underline; padding: 0;
      }
      .brand-color-reset:hover { color: var(--ink); }
