html { scrollbar-gutter: stable; }

:root {
    --bg: #f5f5f5;
    --surface: #fff;
    --border: #e0e0e0;
    --text: #111;
    --muted: #888;
    --label: #555;
    --divider: #ddd;
    --pre-bg: #fafafa;
    --pre-border: #e0e0e0;
    --result-bg: #fafafa;
    --sell-bg: #111;
    --sell-text: #fff;
    --sell-note: #666;
    --sell-label: #888;
    --reset-border: #ddd;
    --reset-color: #bbb;
    --hint: #bbb;
    --zero: #ccc;
    --focus: #111;
    --red: #c0392b;
    --green: #27ae60;
    --tab-active-bg: #111;
    --tab-active-text: #fff;
  }
  [data-theme="dark"] {
    --bg: #111;
    --surface: #1a1a1a;
    --border: #2a2a2a;
    --text: #f0f0f0;
    --muted: #666;
    --label: #aaa;
    --divider: #2a2a2a;
    --pre-bg: #141414;
    --pre-border: #2a2a2a;
    --result-bg: #141414;
    --sell-bg: #f0f0f0;
    --sell-text: #111;
    --sell-note: #888;
    --sell-label: #666;
    --reset-border: #2a2a2a;
    --reset-color: #444;
    --hint: #444;
    --zero: #333;
    --focus: #f0f0f0;
    --tab-active-bg: #f0f0f0;
    --tab-active-text: #111;
  }
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    min-height: 100vh;
    transition: background 0.2s, color 0.2s;
  }
  /* Shared wide container for all pages */
  .container {
    margin: 0 auto;
    padding: 32px 24px 60px;
    max-width: 1280px;
  }

  /* Calculator: inner form card stays narrow and centered */
  body[data-page="calculator"] #tab-calculator {
    max-width: 560px;
    margin: 0 auto;
  }

  /* ── Header ── */
  header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 24px;
  }
  .logo-block { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
  .logo-block img { height: 72px; width: auto; display: block; }
  .logo-sub { font-size: 10px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
  .dm-toggle { display: flex; align-items: center; gap: 8px; }
  #global-sync-btn { background: none; border: 1.5px solid var(--border); cursor: pointer; font-size: 15px; color: var(--muted); width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: color 0.2s, border-color 0.2s; margin-right: 4px; }
  #global-sync-btn:hover { color: var(--text); border-color: var(--text); }
  #global-sync-btn.spinning { animation: globalSpin 0.7s linear infinite; }
  @keyframes globalSpin { to { transform: rotate(360deg); } }
  .dm-label { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); user-select: none; }
  .page-nav {
    order: 3; width: 100%; justify-content: center;
  }

  /* ── Page Nav ── */
  .page-nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 8px; padding: 3px; width: 100%; }
  .nav-link { text-align: center; padding: 8px 6px; border-radius: 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; text-decoration: none; color: var(--muted); transition: all 0.15s; white-space: nowrap; }
  .nav-link:hover { color: var(--text); }
  .nav-link.active { background: var(--tab-active-bg); color: var(--tab-active-text); }

  /* ── Switch ── */
  .switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
  .switch input { opacity: 0; width: 0; height: 0; }
  .sw-track { position: absolute; inset: 0; background: var(--divider); border-radius: 22px; cursor: pointer; transition: background 0.2s; }
  .sw-track:before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
  .switch input:checked + .sw-track { background: var(--red); }
  .switch input:checked + .sw-track:before { transform: translateX(18px); }

  /* ── Tab Nav ── */
  .tab-nav {
    display: flex; gap: 0; margin-bottom: 28px;
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: 8px; overflow: hidden;
  }
  .tab-btn {
    flex: 1; padding: 11px 0; text-align: center;
    font-family: inherit; font-size: 12px; font-weight: 700;
    letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--muted); background: transparent; border: none; cursor: pointer;
    transition: all 0.15s; border-right: 1px solid var(--border);
  }
  .tab-btn:last-child { border-right: none; }
  .tab-btn.active { background: var(--tab-active-bg); color: var(--tab-active-text); }
  .tab-panel { display: none; }
  .tab-panel.active { display: block; }

  /* ── Section ── */
  .section { margin-bottom: 24px; }
  .section-title { font-size: 10px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
  .section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }

  /* ── Fields ── */
  .field { margin-bottom: 10px; }
  .field label { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.05em; color: var(--label); margin-bottom: 5px; text-transform: uppercase; }
  .input-group { display: flex; align-items: center; background: var(--surface); border: 1.5px solid var(--border); border-radius: 8px; overflow: hidden; transition: border-color 0.15s; }
  .input-group:focus-within { border-color: var(--focus); }
  .input-group .pre { padding: 0 12px; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--pre-bg); border-right: 1px solid var(--pre-border); height: 44px; display: flex; align-items: center; white-space: nowrap; flex-shrink: 0; transition: background 0.2s, border-color 0.2s; }
  .input-group .cur-inline-select { flex: 0 0 auto; width: 76px; border-right: 1px solid var(--pre-border); background: var(--pre-bg); font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 8px; cursor: pointer; height: 44px; border-radius: 0; }
  .input-group input, .input-group select { flex: 1; border: none; outline: none; background: transparent; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; font-weight: 500; color: var(--text); padding: 0 14px; height: 44px; -moz-appearance: textfield; min-width: 0; transition: color 0.2s; }
  .input-group input::-webkit-outer-spin-button, .input-group input::-webkit-inner-spin-button { -webkit-appearance: none; }
  .input-group select { cursor: pointer; font-size: 13px; padding: 0 10px; }
  .input-group .suf { padding: 0 12px; font-size: 12px; color: var(--muted); flex-shrink: 0; }
  .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .hint { font-size: 11px; color: var(--hint); margin-top: 4px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; }

  /* ── Toggle field ── */
  .toggle-field { display: flex; align-items: center; justify-content: space-between; background: var(--surface); border: 1.5px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; transition: background 0.2s, border-color 0.2s; }
  .toggle-field span { font-size: 13px; font-weight: 500; color: var(--text); }

  /* ── Unit tabs ── */
  .unit-tabs { display: flex; background: var(--surface); border: 1.5px solid var(--border); border-radius: 8px; overflow: hidden; }
  .unit-tab { flex: 1; padding: 10px 0; text-align: center; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); cursor: pointer; border: none; background: transparent; font-family: inherit; transition: all 0.15s; border-right: 1px solid var(--border); }
  .unit-tab:last-child { border-right: none; }
  .unit-tab.active { background: var(--text); color: var(--bg); }

  /* ── Result ── */
  .result-box { background: var(--surface); border: 1.5px solid var(--border); border-radius: 12px; overflow: hidden; transition: background 0.2s, border-color 0.2s; }
  .breakdown { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
  .b-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
  .b-row .b-key { color: var(--muted); }
  .b-row .b-val { font-weight: 600; color: var(--text); }
  .b-row .b-val.zero { color: var(--zero); font-weight: 400; }
  .total-block { border-top: 1.5px solid var(--border); padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; background: var(--result-bg); transition: background 0.2s, border-color 0.2s; }
  .total-block .t-label { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--label); }
  .total-block .t-val { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }

  /* ── Sell block ── */
  .sell-block { background: var(--sell-bg); border-radius: 12px; padding: 18px 20px; margin-top: 10px; display: flex; justify-content: space-between; align-items: center; transition: background 0.2s; }
  .sell-left .s-label { font-size: 10px; font-weight: 700; letter-spacing: 0.15em; text-transform: uppercase; color: var(--sell-label); margin-bottom: 4px; }
  .sell-left .s-note { font-size: 11px; color: var(--sell-note); }
  .sell-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
  .sell-price { font-size: 26px; font-weight: 700; color: var(--sell-text); letter-spacing: -0.03em; transition: color 0.2s; }
  .copy-btn { display: flex; align-items: center; gap: 5px; background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.18); border-radius: 6px; padding: 5px 10px; font-family: inherit; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--sell-text); cursor: pointer; transition: all 0.15s; }
  [data-theme="dark"] .copy-btn { background: rgba(0,0,0,0.12); border-color: rgba(0,0,0,0.2); color: #111; }
  .copy-btn:hover { background: rgba(255,255,255,0.22); }
  [data-theme="dark"] .copy-btn:hover { background: rgba(0,0,0,0.2); }
  .copy-btn.copied { background: var(--green) !important; border-color: var(--green) !important; color: #fff !important; }
  .reset-btn { display: block; width: 100%; margin-top: 10px; padding: 12px; background: transparent; border: 1.5px solid var(--reset-border); border-radius: 8px; font-family: inherit; font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--reset-color); cursor: pointer; transition: all 0.15s; }
  .reset-btn:hover { border-color: var(--text); color: var(--text); }

  /* ── DATABASE TAB ── */
  .db-search-row { margin-bottom: 10px; }
  .db-search {
    width: 100%;
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: 8px; padding: 0 14px; height: 40px;
    font-family: inherit; font-size: 14px; color: var(--text); outline: none;
    transition: border-color 0.15s;
  }
  .db-search:focus { border-color: var(--focus); }
  .db-search::placeholder { color: var(--muted); }
  .db-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .db-toolbar::-webkit-scrollbar { display: none; }
  .db-filter {
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: 8px; padding: 0 10px; height: 40px;
    font-family: inherit; font-size: 13px; color: var(--text); outline: none; cursor: pointer;
    white-space: nowrap; flex-shrink: 0;
  }
  /* ── Action buttons row ── */
  .db-actions {
    display: flex; gap: 8px; margin-bottom: 12px;
  }
  .add-btn {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    background: var(--text); color: var(--bg);
    border: none; border-radius: 8px; padding: 0 16px; height: 40px;
    font-family: inherit; font-size: 12px; font-weight: 700;
    letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
    transition: opacity 0.15s; white-space: nowrap; flex-shrink: 0;
  }
  .add-btn:hover { opacity: 0.85; }

  /* ── Item cards ── */
  .db-list { display: flex; flex-direction: column; gap: 10px; }
  .db-empty { text-align: center; padding: 48px 0; color: var(--muted); font-size: 13px; }

  .item-card {
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: 10px; overflow: hidden; transition: border-color 0.15s;
  }
  .item-card:hover { border-color: var(--text); }
  .item-card-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 14px 16px 10px;
  }
  .item-name { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
  .item-cat {
    display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
    text-transform: uppercase; color: var(--red);
    background: rgba(192,57,43,0.08); border-radius: 4px; padding: 2px 7px;
  }
  .item-card-actions { display: flex; gap: 6px; flex-shrink: 0; margin-left: 10px; }
  .icon-btn {
    width: 30px; height: 30px; border-radius: 6px; border: 1.5px solid var(--border);
    background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--muted); transition: all 0.15s;
  }
  .icon-btn:hover { border-color: var(--text); color: var(--text); }
  .icon-btn.danger:hover { border-color: var(--red); color: var(--red); }

  .item-card-stats {
    display: grid; grid-template-columns: repeat(4, 1fr);
    border-top: 1px solid var(--border);
  }
  .stat { padding: 10px 14px; border-right: 1px solid var(--border); }
  .stat:last-child { border-right: none; }
  .stat-label { font-size: 9px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
  .stat-val { font-size: 13px; font-weight: 700; color: var(--text); }
  .stat-val.green { color: var(--green); }

  .reprice-btn {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    width: 100%; padding: 10px; background: transparent;
    border: none; border-top: 1.5px solid var(--border);
    font-family: inherit; font-size: 11px; font-weight: 700;
    letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--muted); cursor: pointer; transition: all 0.15s;
  }
  .reprice-btn:hover { background: var(--text); color: var(--bg); }

  /* ── Modal ── */
  .modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 100;
    align-items: center; justify-content: center; padding: 16px;
  }
  .modal-overlay.open { display: flex; }
  .modal {
    background: var(--surface); border-radius: 14px; width: 100%; max-width: 440px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  }
  .modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 20px 14px; border-bottom: 1px solid var(--border);
  }
  .modal-title { font-size: 14px; font-weight: 700; color: var(--text); }
  .modal-close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 20px; line-height: 1; padding: 2px 6px; }
  .modal-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
  .modal-footer { padding: 0 20px 20px; display: flex; gap: 8px; }
  .btn-primary { flex: 1; padding: 12px; background: var(--text); color: var(--bg); border: none; border-radius: 8px; font-family: inherit; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; cursor: pointer; transition: opacity 0.15s; }
  .btn-primary:hover { opacity: 0.85; }
  .btn-secondary { padding: 12px 16px; background: transparent; color: var(--muted); border: 1.5px solid var(--border); border-radius: 8px; font-family: inherit; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; cursor: pointer; transition: all 0.15s; }
  .btn-secondary:hover { border-color: var(--text); color: var(--text); }

  .modal .field label { font-size: 10px; }
  .modal .input-group input, .modal .input-group select { font-size: 14px; }

  .custom-cat-wrap { margin-top: -4px; }



  .db-upload-btn {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    background: transparent; border: 1.5px solid var(--border);
    border-radius: 8px; padding: 0 14px; height: 40px;
    font-family: inherit; font-size: 12px; font-weight: 700;
    letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--muted); cursor: pointer; white-space: nowrap;
    transition: all 0.15s;
  }
  .db-upload-btn:hover { border-color: var(--text); color: var(--text); }
  .db-upload-hint { font-size: 11px; color: var(--hint); display: flex; align-items: center; }

  .db-pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 6px; margin-top: 16px; flex-wrap: wrap;
  }
  .pg-btn {
    min-width: 34px; height: 34px; padding: 0 8px;
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: 6px; font-family: inherit; font-size: 12px;
    font-weight: 700; color: var(--muted); cursor: pointer;
    transition: all 0.15s; display: flex; align-items: center; justify-content: center;
  }
  .pg-btn:hover { border-color: var(--text); color: var(--text); }
  .pg-btn.active { background: var(--text); color: var(--bg); border-color: var(--text); }
  .pg-btn:disabled { opacity: 0.3; cursor: default; }
  .pg-info { font-size: 11px; color: var(--muted); padding: 0 4px; }

  .save-db-btn {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    width: 100%; margin-top: 8px; padding: 13px;
    background: var(--text); color: var(--bg);
    border: none; border-radius: 8px;
    font-family: inherit; font-size: 12px; font-weight: 700;
    letter-spacing: 0.1em; text-transform: uppercase;
    cursor: pointer; transition: opacity 0.15s;
  }
  .save-db-btn:hover { opacity: 0.8; }
  .save-db-btn.saved { background: var(--green) !important; color: #fff !important; }

  /* ── Table ── */
  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1.5px solid var(--border); border-radius: 10px; }
  .db-table { width: 100%; border-collapse: collapse; font-size: 13px; }
  .db-table thead { background: var(--pre-bg); }
  .db-table th { padding: 11px 14px; text-align: left; font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); border-bottom: 1.5px solid var(--border); white-space: nowrap; }
  .db-table th.sortable { cursor: pointer; user-select: none; }
  .db-table th.sortable:hover { color: var(--text); }
  .db-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text); }
  .db-table tbody tr:last-child td { border-bottom: none; }
  .db-table tbody tr:hover { background: var(--pre-bg); }
  .sort-icon { font-size: 10px; margin-left: 3px; }
  .td-po { font-size: 11px; color: var(--muted); white-space: nowrap; }
  .td-name { font-weight: 600; min-width: 140px; }
  .td-cost, .td-kurs, .td-sell { white-space: nowrap; min-width: 120px; }
  .td-margin { font-weight: 700; color: var(--green); }
  .td-margin.neg { color: var(--red); }
  .td-actions { display: flex; gap: 5px; white-space: nowrap; }

  /* ── Notion Sync btn ── */
  .notion-sync-btn {
    display: flex; align-items: center; gap: 6px;
    background: #000; color: #fff;
    border: none; border-radius: 8px; padding: 0 16px; height: 40px;
    font-family: inherit; font-size: 12px; font-weight: 700;
    letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
    transition: opacity 0.15s; white-space: nowrap;
  }
  .notion-sync-btn:hover { opacity: 0.8; }
  .notion-sync-btn:disabled { opacity: 0.5; cursor: not-allowed; }
  [data-theme="dark"] .notion-sync-btn { background: #fff; color: #111; }

  /* ── Export btn ── */
  .db-export-btn { display: flex; align-items: center; justify-content: center; gap: 6px; background: transparent; border: 1.5px solid var(--border); border-radius: 8px; padding: 0 14px; height: 40px; font-family: inherit; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); cursor: pointer; white-space: nowrap; transition: all 0.15s; }
  .db-export-btn:hover { border-color: var(--text); color: var(--text); }

  /* ── Calculator page: no tab-panel wrapper needed ── */
  #tab-calculator { display: block; }

  /* ── Mobile: stack two-col on phones ── */
  @media (max-width: 500px) {
    .two-col { grid-template-columns: 1fr; }
    .item-card-stats { grid-template-columns: repeat(2,1fr); }
    .stat:nth-child(2) { border-right: none; }
    .stat:nth-child(3) { border-right: 1px solid var(--border); }
  }

/* ═══════════════════════════════════════
   RESPONSIVE — Tablet (≥ 600px)
═══════════════════════════════════════ */
@media (min-width: 600px) {
  /* Nav: single-row flex on tablet */
  .page-nav { display: flex; gap: 4px; padding: 4px; justify-content: center; }
  .nav-link { flex: none; padding: 7px 14px; font-size: 12px; letter-spacing: 0.07em; }

  /* DB toolbar on tablet+ — no scroll, wrap instead */
  .db-toolbar {
    flex-wrap: wrap; gap: 10px;
    overflow-x: visible; padding-bottom: 0;
  }
}

/* ═══════════════════════════════════════
   RESPONSIVE — Desktop (≥ 1024px)
═══════════════════════════════════════ */
@media (min-width: 1024px) {
  .container {
    padding: 40px 40px 60px;
  }

  /* Header: single row with centered nav on desktop */
  header { flex-wrap: nowrap; }
  .page-nav { width: fit-content; flex: none; order: 0; margin: 0 auto; }
  .nav-link { flex: none; }

  /* DB toolbar: single row on desktop */
  .db-toolbar {
    flex-wrap: nowrap;
    overflow-x: visible;
    padding-bottom: 0;
  }

  /* DB cards: 2 columns (legacy) */
  .db-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}

/* ═══════════════════════════════════════
   RESPONSIVE — Desktop (≥ 1080px)
═══════════════════════════════════════ */
@media (min-width: 1080px) {
  .container {
    max-width: 1200px;
    padding: 48px 48px 60px;
  }

  /* ── Calculator: inputs left, result sticky right ── */
  #tab-calculator {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 32px;
    align-items: start;
  }

  /* Sections 1–4 fill left column naturally */
  #tab-calculator .section {
    grid-column: 1;
  }

  /* Section 5 (Result) → sticky right sidebar */
  #tab-calculator .section:last-child {
    grid-column: 2;
    grid-row: 1 / span 10;
    position: sticky;
    top: 32px;
  }

  /* Table: taller rows look better on desktop */
  .db-table th, .db-table td { padding: 13px 16px; }

  /* ── Database: 3-column card grid ── */
  .db-list {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Wider modal */
  .modal { max-width: 560px; }

  /* Header sizing bump */
  .logo-block img { height: 96px; }
  .logo-sub { font-size: 11px; }

  /* Invoice: wider builder on desktop */
  /* Invoice layout already centered via max-width on .inv-layout */
}

/* ═══════════════════════════════════════
   INVOICE PAGE
═══════════════════════════════════════ */

/* ── Layout (top = builder, bottom = preview, centered) ── */
.inv-layout { display: flex; flex-direction: column; gap: 24px; max-width: 100%; }
.inv-builder { flex: none; }
.inv-preview {
  background: #f0f0f0; border-radius: 12px; padding: 20px; min-height: 120px;
}
[data-theme="dark"] .inv-preview { background: #1a1a1a; }
.inv-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 32px; }
.inv-save-row { display: flex; flex-direction: row; gap: 8px; }
.inv-save-row .inv-png-btn, .inv-save-row .inv-print-btn { flex: 1; width: auto; min-width: 0; }
.inv-sync-bar { margin-bottom: 12px; }
.inv-sync-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--text); color: var(--bg); border: none; border-radius: 8px;
  width: 100%; height: 40px; font-family: inherit; font-size: 12px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
  transition: opacity 0.15s;
}
.inv-sync-btn:hover { opacity: 0.85; }
.inv-sync-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.inv-disclaimer {
  margin-top: 16px; padding: 10px 14px; background: #fffbe6; border: 1px solid #f0e6a0;
  border-radius: 8px; font-size: 11px; color: #8a7600; font-weight: 500; text-align: center;
}

/* Empty state in preview */
.inv-preview-empty {
  text-align: center; padding: 48px 20px; color: #888;
}

/* ── Builder helpers ── */
.inv-notice {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; background: var(--pre-bg); border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 12px; color: var(--muted); margin-top: 8px;
}
.inv-placeholder {
  font-size: 13px; color: var(--muted); padding: 20px 0; text-align: center;
}

/* Items mini-table inside builder */
.inv-items-tbl { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
.inv-items-tbl th {
  font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.08em; padding: 6px 8px; border-bottom: 1.5px solid var(--border);
  text-align: left; white-space: nowrap;
}
.inv-items-tbl td { padding: 8px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.inv-items-tbl tbody tr:last-child td { border-bottom: none; }
.inv-items-tbl td.td-r { text-align: right; white-space: nowrap; }
.inv-items-tbl td.td-c { text-align: center; }
.inv-row-name  { font-weight: 600; font-size: 12px; }
.inv-row-sub   { font-size: 10px; color: var(--muted); margin-top: 2px; }
.inv-row-check { width: 16px; height: 16px; cursor: pointer; accent-color: var(--text); }

/* Print/action buttons */
.inv-print-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--text); color: var(--bg); border: none; border-radius: 8px;
  width: 100%; height: 44px; font-family: inherit; font-size: 13px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
  transition: opacity 0.15s;
}
.inv-print-btn:hover { opacity: 0.85; }
.inv-png-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface); color: var(--text); border: 1.5px solid var(--border); border-radius: 8px;
  width: 100%; height: 44px; font-family: inherit; font-size: 13px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
  transition: opacity 0.15s;
}
.inv-png-btn:hover { opacity: 0.85; }
[data-theme="dark"] .inv-png-btn { border-color: var(--border); }
.inv-bulk-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; height: 44px; border-radius: 8px;
  border: 1.5px dashed var(--border); background: transparent;
  color: var(--muted); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: border-color 0.15s, color 0.15s;
}
.inv-bulk-btn:hover { border-color: var(--text); color: var(--text); }

/* ── Invoice document (always light/print-safe) ── */
.invoice-wrap {
  background: #fff; border-radius: 10px; border: 1px solid #e0e0e0; padding: 24px;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; color: #111;
}
.invoice-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid #e0e0e0;
}
.invoice-logo { height: 80px; width: auto; }
.invoice-right { text-align: right; }
.invoice-title { font-size: 20px; font-weight: 700; color: #111; }
.invoice-no    { font-size: 14px; font-weight: 400; color: #888; margin-left: 6px; }
.invoice-meta  { font-size: 12px; color: #888; margin-top: 3px; }

/* Invoice table */
.invoice-wrap table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; margin-bottom: 8px; }
.invoice-wrap col:nth-child(1) { width: 40%; }
.invoice-wrap col:nth-child(2) { width: 10%; }
.invoice-wrap col:nth-child(3) { width: 24%; }
.invoice-wrap col:nth-child(4) { width: 26%; }
.invoice-wrap thead th {
  font-size: 12px; font-weight: 600; color: #555; text-align: right;
  padding: 10px 6px; border-bottom: 1px solid #e0e0e0;
  white-space: normal; line-height: 1.4; vertical-align: bottom;
}
.invoice-wrap thead th:first-child { text-align: left; }
.invoice-wrap thead th:nth-child(2) { text-align: center; }
.invoice-wrap thead th.col-total { color: #111; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.invoice-wrap tbody tr { border-bottom: 1px solid #f0f0f0; }
.invoice-wrap tbody tr:last-child { border-bottom: none; }
.invoice-wrap tbody td {
  padding: 10px 6px; vertical-align: middle; color: #111;
  text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.invoice-wrap tbody td:first-child { text-align: left; white-space: normal; }
.invoice-wrap tbody td:nth-child(2) { text-align: center; }
.invoice-wrap tbody td.col-total { font-weight: 500; background: #fafafa; }

/* Card name + condition */
.inv-card-name { font-weight: 600; font-size: 12px; line-height: 1.4; color: #111; }
.inv-card-sub  { font-size: 10px; color: #888; margin-top: 2px; }

/* (fee badges removed — local shipping now in summary) */

/* Summary box */
.inv-summary { margin-top: 16px; border: 1px solid #e0e0e0; border-radius: 10px; overflow: hidden; }
.inv-sum-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid #f0f0f0; font-size: 12px;
}
.inv-sum-row:last-child { border-bottom: none; }
.inv-sum-label { color: #888; }
.inv-sum-val   { font-weight: 500; color: #111; }
.inv-sum-row.row-dp   .inv-sum-label { color: #185FA5; }
.inv-sum-row.row-dp   .inv-sum-val   { color: #185FA5; }
.inv-sum-row.row-paid .inv-sum-label { color: #27ae60; }
.inv-sum-row.row-paid .inv-sum-val   { color: #27ae60; }
.inv-sum-row.row-outstanding { background: #fafafa; }
.inv-sum-row.row-outstanding .inv-sum-label { font-size: 13px; font-weight: 600; color: #111; }
.inv-sum-row.row-outstanding .inv-sum-val   { font-size: 15px; font-weight: 700; color: #111; }
.inv-sum-row.row-negative .inv-sum-val { color: #27ae60; }

/* Payment box */
.inv-payment { margin-top: 12px; border: 1px solid #e0e0e0; border-radius: 10px; overflow: hidden; }
.inv-pay-hdr {
  padding: 8px 16px; background: #fafafa; border-bottom: 1px solid #e0e0e0;
  font-size: 10px; font-weight: 600; color: #888; text-transform: uppercase; letter-spacing: 0.06em;
}
.inv-pay-row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.inv-bank-logo {
  width: 40px; height: 40px; border-radius: 8px; background: #003087;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.inv-bank-logo span { font-size: 11px; font-weight: 600; color: #fff; letter-spacing: 0.04em; }
.inv-bank-name    { font-size: 12px; font-weight: 600; color: #111; }
.inv-bank-account { font-size: 15px; font-weight: 600; color: #111; letter-spacing: 0.06em; margin-top: 2px; }
.inv-bank-holder  { font-size: 11px; color: #888; margin-top: 2px; }

/* (legend removed — local shipping simplified) */

/* ══════════════════════════════════════════════════════════════════════════════
   CLIENT PAGE
   ══════════════════════════════════════════════════════════════════════════════ */

/* Sync button (shared) */
.sync-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--text); color: var(--bg); border: none; border-radius: 8px;
  width: 100%; height: 40px; font-family: inherit; font-size: 12px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
  transition: opacity 0.15s; margin-bottom: 16px;
}
.sync-btn:hover { opacity: 0.85; }
.sync-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Sub-tabs */
.cl-tabs {
  display: flex; gap: 3px; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 8px; padding: 3px; margin-bottom: 16px;
}
.cl-tab {
  flex: 1; text-align: center; padding: 9px 12px; border: none; border-radius: 6px;
  background: transparent; color: var(--muted); font-family: inherit;
  font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  cursor: pointer; transition: all 0.15s;
}
.cl-tab:hover { color: var(--text); }
.cl-tab.active { background: var(--tab-active-bg); color: var(--tab-active-text); }

/* Shipping Label form */
.cl-ship-section { margin-bottom: 16px; }
.cl-select {
  width: 100%; height: 44px; padding: 0 12px; border: 1.5px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text);
  font-size: 13px; font-family: inherit; cursor: pointer; outline: none;
}
.field-label {
  display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.05em;
  color: var(--label); margin-bottom: 5px; text-transform: uppercase;
}

/* Shipping Labels Section */
.cl-label-clients { margin-top: 12px; }
.cl-label-card {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 8px;
  margin-bottom: 6px; cursor: pointer; transition: border-color 0.15s;
}
.cl-label-card:hover { border-color: var(--text); }
.cl-label-card input[type="checkbox"] { flex-shrink: 0; }
.cl-label-card-info { flex: 1; }
.cl-label-card-name { font-size: 13px; font-weight: 700; color: var(--text); }
.cl-label-card-detail { font-size: 11px; color: var(--muted); margin-top: 2px; }

.cl-sender-section { margin-bottom: 12px; }
.cl-sender-section input {
  display: block; width: 100%; height: 38px; padding: 0 12px; margin-top: 6px;
  border: 1.5px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); font-size: 13px; font-family: inherit; outline: none;
  box-sizing: border-box;
}
.cl-sender-section input:focus { border-color: var(--text); }

.cl-print-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 48px; border: none; border-radius: 8px;
  background: var(--text); color: var(--bg); font-size: 13px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; cursor: pointer;
  font-family: inherit; transition: opacity 0.15s;
}
.cl-print-btn:hover { opacity: 0.85; }

.cl-label-actions { margin-top: 16px; }

/* Shipping Label Print Area */
.cl-print-area { display: none; }

@media print {
  body[data-page="client"] .container { display: none !important; }
  body[data-page="client"] .cl-print-area {
    display: block !important;
    margin: 0; padding: 8mm;
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    /* 4-column grid matching draft */
    display: grid !important;
    grid-template-columns: repeat(4, 1fr);
    gap: 3mm;
    align-content: start;
    width: 210mm;
  }
  /* Individual label */
  .cl-label {
    border: 1.5px solid #222;
    border-radius: 3px;
    overflow: hidden;
    font-size: 6.5pt;
    line-height: 1.35;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  /* Header: logo + brand name */
  .cl-label-header {
    display: flex; align-items: center; gap: 4px;
    padding: 3px 5px; border-bottom: 1px solid #222;
    background: #fff;
  }
  .cl-label-logo { height: 26px; width: auto; }
  .cl-label-brand {
    font-size: 7pt; font-weight: 800; letter-spacing: 0.04em;
    color: #c0392b; text-transform: uppercase;
  }
  /* FROM block */
  .cl-label-from-block {
    padding: 3px 5px; border-bottom: 1px dashed #bbb; background: #fafafa;
  }
  /* TO block */
  .cl-label-to-block { padding: 4px 5px; }
  /* Section tag */
  .cl-lbl-tag {
    font-size: 5pt; font-weight: 800; letter-spacing: 0.08em;
    text-transform: uppercase; color: #888; margin-bottom: 1px;
    display: block;
  }
  /* FROM name */
  .cl-lbl-from-name { font-size: 7pt; font-weight: 700; color: #111; }
  .cl-lbl-from-detail { font-size: 6pt; color: #444; line-height: 1.3; }
  /* TO recipient */
  .cl-lbl-to-name { font-size: 8pt; font-weight: 800; color: #111; margin-bottom: 1px; }
  .cl-lbl-to-phone { font-size: 7pt; font-weight: 600; color: #222; margin-bottom: 2px; }
  .cl-lbl-to-addr { font-size: 6pt; color: #333; line-height: 1.4; }
  /* Thank you footer */
  .cl-label-thanks {
    padding: 3px 5px; border-top: 1px dashed #bbb;
    font-size: 6pt; color: #c0392b; font-style: italic; font-weight: 600;
    text-align: center; background: #fff8f8;
  }
}

/* ── Print styles (Invoice) ── */
@media print {
  body[data-page="invoice"] { background: #fff; }
  body[data-page="invoice"] .container { padding: 0; max-width: 100%; }
  body[data-page="invoice"] header,
  body[data-page="invoice"] .inv-builder,
  body[data-page="invoice"] .inv-actions { display: none !important; }
  body[data-page="invoice"] .inv-layout { display: block; }
  body[data-page="invoice"] .inv-preview {
    background: transparent; border-radius: 0; padding: 0;
    position: static; display: block !important;
  }
  body[data-page="invoice"] .invoice-wrap { border: none; border-radius: 0; padding: 16px; }
}
