/* The Sales and Planning pages (sales.html, planning.html). */
  :root {
    --ink: #1a1a2e; --accent: #e94560; --bg: #f6f6f8; --card: #fff; --line: #e4e4ea;
    --text: #222; --muted: #6b6b76; --faint: #9a9aa5;
    --good: #17603a; --good-bg: #eaf7f1; --warn: #8a4b00; --warn-bg: #fff3e2; --bad: #a3172f; --bad-bg: #fdecef;
    /* Chart colours (validated categorical order): this year / retail, trade, DIY. */
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --ly: #b9b8b2; --target: #1a1a2e;
    /* Product mix bar: the same validated order. */
    --m0: #2a78d6; --m1: #eb6834; --m2: #1baf7a; --m3: #eda100; --m4: #e87ba4; --m5: #6250d6;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body { font-family: Arial, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
  header { background: var(--ink); color: #fff; padding: 11px 18px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
  header h1 { font-size: 17px; font-weight: 600; }
  .site-nav { display: flex; gap: 4px; }
  .site-nav a { color: #ccc; text-decoration: none; font-size: 13px; padding: 6px 11px; border-radius: 6px; }
  .site-nav a:hover { background: rgba(255,255,255,0.1); color: #fff; }
  .site-nav a.here { background: rgba(255,255,255,0.14); color: #fff; }
  .head-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  #data-status { font-size: 12px; color: #bbb; }
  .btn { background: var(--accent); color: #fff; border: none; padding: 7px 13px; border-radius: 6px; cursor: pointer; font-size: 13px; white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; text-decoration: none; }
  .btn:hover { background: #c73652; }
  .btn.quiet { background: rgba(255,255,255,0.12); }
  .btn.dark { background: var(--ink); }
  .btn.light { background: #fff; color: var(--ink); border: 1px solid var(--line); }
  .btn:disabled { opacity: 0.55; cursor: default; }
  .btn.small { padding: 4px 9px; font-size: 12px; }
  .btn.light:hover { background: #f3f3f7; }

  .tabs { background: #fff; border-bottom: 1px solid #ddd; display: flex; align-items: center; gap: 6px; padding: 8px 12px; overflow-x: auto; position: sticky; top: 0; z-index: 20; }
  .tab-btn { border: 1px solid #ddd; background: #fff; padding: 7px 12px; border-radius: 999px; cursor: pointer; font-size: 13px; white-space: nowrap; color: var(--text); }
  .tab-btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }
  table.pl td { padding: 4px 5px; }
  table.pl td.cur { background: #f5f8fd; }
  table.pl input[type=number] { width: 66px; text-align: right; padding: 4px 5px; }
  table.pl input.pl-name { width: 170px; font-weight: 600; padding: 4px 5px; text-align: left; }
  table.pl .n { display: block; font-size: 10px; color: var(--muted); }
  .tabs .fy-pick { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
  select, input[type="text"], input[type="number"], input[type="search"] { height: 32px; border: 1px solid #ccc; border-radius: 6px; padding: 4px 8px; font-size: 13px; background: #fff; color: var(--text); font-family: inherit; }
  input:focus, select:focus { outline: 2px solid rgba(42,120,214,0.25); border-color: var(--s1); }

  main { max-width: 1600px; margin: 0 auto; padding: 18px 16px 60px; }
  .page-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
  .page-title h2 { font-size: 20px; color: var(--ink); }
  .page-title p { font-size: 13px; color: var(--muted); }
  section.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
  section.card > h3 { font-size: 14px; color: var(--ink); margin-bottom: 4px; }
  section.card { position: relative; }
  .snap-btn { position: absolute; top: 10px; right: 10px; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 3px 7px; font-size: 13px; cursor: pointer; opacity: .55; z-index: 2; }
  .snap-btn:hover { opacity: 1; }
  section.card > .row-flex:first-of-type, section.card > h3 { padding-right: 38px; }
  .snap-foot { font-size: 11px; color: #888; margin-top: 10px; text-align: right; }
  #snap-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1a1a2e; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 1000; }
  #snap-toast.on { opacity: 1; }
  .card-sub { font-size: 12px; color: var(--muted); margin-bottom: 12px; line-height: 1.45; }
  .grid { display: grid; gap: 16px; }
  .grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
  .row-flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

  /* Headline */
  .hero { display: grid; grid-template-columns: minmax(260px, 1.2fr) 2fr; gap: 16px; }
  .hero .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-main .label { font-size: 13px; color: var(--muted); }
  .hero-main .value { font-size: 44px; font-weight: 700; color: var(--ink); letter-spacing: -0.5px; margin: 2px 0 6px; font-variant-numeric: proportional-nums; }
  .hero-main .sub { font-size: 13px; color: var(--muted); line-height: 1.6; }
  .meter { position: relative; height: 12px; background: #ececf1; border-radius: 999px; margin: 12px 0 6px; overflow: visible; }
  .meter .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--s1); }
  .meter .pace { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); }
  .meter-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
  .tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
  .tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  @media (max-width: 760px) { .tiles.three { grid-template-columns: 1fr 1fr; } }
  .tile { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; background: #fff; }
  .tile .label { font-size: 12px; color: var(--muted); }
  .tile .value { font-size: 24px; font-weight: 700; color: var(--ink); margin: 3px 0; }
  .tile .sub { font-size: 12px; color: var(--muted); line-height: 1.5; }
  .delta { font-weight: 600; }
  .delta.up { color: var(--good); }
  .delta.down { color: var(--bad); }

  /* Needs attention */
  .alerts { display: flex; flex-direction: column; gap: 8px; }
  .alert { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border-radius: 8px; font-size: 13px; line-height: 1.45; background: var(--warn-bg); color: var(--warn); }
  .alert.bad { background: var(--bad-bg); color: var(--bad); }
  .alert.good { background: var(--good-bg); color: var(--good); }
  .alert .icon { font-size: 15px; line-height: 1.2; }
  .alert a { color: inherit; font-weight: 600; }

  /* Tables */
  .table-wrap { overflow-x: auto; }
  table { border-collapse: collapse; width: 100%; font-size: 13px; }
  th { text-align: right; font-weight: 600; color: var(--muted); font-size: 12px; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafafc; }
  td { text-align: right; padding: 6px 8px; border-bottom: 1px solid #f0f0f3; white-space: nowrap; font-variant-numeric: tabular-nums; }
  th:first-child, td:first-child { text-align: left; }
  td.left, th.left { text-align: left; }
  table.tight th, table.tight td { padding-left: 6px; padding-right: 6px; }
  tr.total td { font-weight: 700; border-top: 1px solid var(--line); background: #fafafc; }
  tr.current td { background: #f3f7fd; }
  tr.muted td { color: var(--faint); }
  table.long-plan td.actual { background: #f6f6f8; }
  table.long-plan input.plan-cell { width: 96px; text-align: right; }
  table.long-plan input.plan-cell.typed { font-weight: 700; border-color: #1f3864; background: #eef2fa; }
  table.long-plan thead th .n { display: block; font-weight: 400; font-size: 11px; opacity: .75; }
  /* Weekly KPIs: the targets tiles (sales/kpi-tiles.js; same look as the home page). */
  .kpi-row-title { font-size: 13px; font-weight: 700; color: var(--ink, #231f20); margin: 4px 0 8px; }
  .kpi-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 12px; }
  .kpi-tile { border: 1px solid #e4e4ea; border-radius: 10px; padding: 12px 14px; background: #fff; break-inside: avoid; }
  .kpi-tile .label { font-size: 12px; color: #6b6b78; }
  .kpi-tile .value { font-size: 24px; font-weight: 700; margin: 2px 0 4px; }
  .kpi-tile .sub { font-size: 12px; color: #6b6b78; line-height: 1.6; }
  .bubble { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 700; }
  .bubble.hit { background: #e3f4ea; color: #17603a; }
  .bubble.miss { background: #fbe3e6; color: #a3172f; }
  /* Weekly KPIs summary: good / behind / watch points (sales/kpi-tiles.js). */
  ul.kpi-summary { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
  ul.kpi-summary li { font-size: 13.5px; line-height: 1.5; padding: 8px 12px; border-radius: 8px; border-left: 4px solid; }
  ul.kpi-summary li.good { background: #eef8f2; border-color: #2e8b57; }
  ul.kpi-summary li.bad { background: #fdf0f2; border-color: #c0392b; }
  ul.kpi-summary li.watch { background: #fff7e6; border-color: #e0a100; }
  ul.kpi-summary .tag { display: inline-block; min-width: 56px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin-right: 8px; }
  ul.kpi-summary li.good .tag { color: #1e6b41; } ul.kpi-summary li.bad .tag { color: #a3172f; } ul.kpi-summary li.watch .tag { color: #8a6100; }
  @media print { ul.kpi-summary li { -webkit-print-color-adjust: exact; print-color-adjust: exact; break-inside: avoid; } }
  /* Weekly KPIs scorecard (sales/kpi-tiles.js). */
  table.scorecard { width: 100%; border-collapse: collapse; font-size: 13px; }
  table.scorecard th, table.scorecard td { padding: 7px 10px; text-align: right; border-bottom: 1px solid #eceef3; white-space: nowrap; }
  table.scorecard thead th { background: #1f3864; color: #fff; font-weight: 600; font-size: 12px; border-bottom: none; }
  table.scorecard thead tr:first-child th.p { font-size: 13px; font-weight: 700; text-align: center; }
  table.scorecard thead tr:last-child th { background: #2e4d82; }
  table.scorecard .m { text-align: left; font-weight: 600; color: #231f20; }
  table.scorecard tr.g th { background: #f3f5f9; color: #1f3864; text-align: left; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; padding: 5px 10px; }
  table.scorecard td.a { font-weight: 700; color: #231f20; }
  table.scorecard td .n { display: block; font-weight: 400; font-size: 11px; color: #8a8a96; }
  table.scorecard td.f { color: #8a8a96; }
  /* Parts of the row above (enquiries sent to trade / kept for retail): indented, lighter. */
  table.scorecard tr.sub td.m { padding-left: 28px; font-weight: 400; color: #55556a; }
  table.scorecard tr.sub td.a { font-weight: 600; }
  table.scorecard .y { border-left: 2px solid #d5dbe8; }
  table.scorecard thead .y { border-left: 2px solid #4a6aa0; }
  table.scorecard td.d.hit { background: #e3f4ea; color: #17603a; font-weight: 700; }
  table.scorecard td.d.miss { background: #fbe3e6; color: #a3172f; font-weight: 700; }
  table.scorecard tbody tr:not(.g):hover td { background-color: #fafbfd; }
  @media print { table.scorecard td.d.hit, table.scorecard td.d.miss, table.scorecard thead th, table.scorecard tr.g th { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
  table.kpi th { background: #1f3864; color: #fff; font-weight: 700; text-align: center; }
  table.kpi thead tr:nth-child(2) th { background: #2e4d82; font-size: 11px; }
  table.kpi td { text-align: center; }
  table.kpi td.left, table.kpi th.left { text-align: left; }
  table.kpi td.t { color: #555; }
  table.kpi td.sep, table.kpi th.sep { border-left: 2px solid #d5dbe8; }
  table.kpi td.hit { background: #e3f4ea !important; color: #17603a; font-weight: 700; }
  table.kpi td.miss { background: #fbe3e6 !important; color: #a3172f; font-weight: 700; }
  table.kpi tr.current td.t { font-weight: 700; color: #222; }
  table.kpi tr.total td { background: #1f3864; color: #fff; }
  td.up-cell, span.up-cell { background: #e3f4ea !important; }
  td.down-cell, span.down-cell { background: #fbe3e6 !important; }
  tr.month-row td { background: #eef2f9; border-top: 2px solid #d5dbe8; }
  td input[type="number"], td input[type="text"] { width: 100px; text-align: right; height: 28px; }
  td input.wide { width: 220px; text-align: left; }
  td select { height: 28px; max-width: 160px; }
  .link-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
  .pill { display: inline-block; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 600; white-space: nowrap; }
  .pill.good { background: var(--good-bg); color: var(--good); }
  .pill.warn { background: var(--warn-bg); color: var(--warn); }
  .pill.bad { background: var(--bad-bg); color: var(--bad); }
  .pill.plain { background: #eef0f4; color: var(--muted); }
  .seg { display: inline-flex; border: 1px solid #ccc; border-radius: 6px; overflow: hidden; }
  .seg button { border: none; background: #fff; padding: 6px 11px; font-size: 12px; cursor: pointer; color: var(--text); border-right: 1px solid #ddd; }
  .seg button:last-child { border-right: none; }
  .seg button.on { background: var(--ink); color: #fff; }

  /* Charts */
  .chart { position: relative; width: 100%; }
  .chart svg { display: block; width: 100%; height: auto; overflow: visible; }
  .chart .axis text, .chart text.axis { font-size: 11px; fill: var(--muted); }
  .chart .grid line { stroke: #ececf1; }
  .legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
  .legend span { display: inline-flex; align-items: center; gap: 6px; }
  .legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
  .legend i.line { height: 0; border-top: 2px dashed var(--target); border-radius: 0; width: 16px; }
  .tip { position: fixed; pointer-events: none; background: #fff; border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0,0,0,0.12); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.55; z-index: 50; display: none; min-width: 150px; }
  .tip b { color: var(--ink); }
  .tip .k { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }

  /* Upload */
  .drop { display: block; border: 2px dashed #c9c9d3; border-radius: 10px; padding: 26px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.6; background: #fcfcfd; cursor: pointer; }
  .drop.over { border-color: var(--s1); background: #f3f7fd; }
  .drop b { color: var(--ink); }
  #upload-input { display: none; }
  .note { font-size: 12px; color: var(--muted); line-height: 1.5; }
  .save-state { font-size: 12px; color: var(--muted); }
  .save-state.saved { color: var(--good); }
  .save-state.error { color: var(--bad); }

  a.cust-link { color: var(--ink); font-weight: 600; text-decoration: none; border-bottom: 1px dotted #9a9aa5; }
  a.cust-link:hover { color: var(--s1); border-bottom-color: var(--s1); }
  ul.points { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.6; }
  ul.points li { margin-bottom: 4px; }
  .mix-bar { display: flex; gap: 2px; height: 14px; margin-top: 14px; }
  .mix-bar i { display: block; height: 100%; border-radius: 3px; min-width: 3px; }
  @media print {
    header, .tabs, .no-print, #tip { display: none !important; }
    body { background: #fff; }
    main { padding: 0; max-width: none; }
    section.card { break-inside: avoid; border-color: #ddd; }
    .tiles { grid-template-columns: repeat(3, 1fr) !important; }
  }
  /* View-only logins: nothing to upload or change. */
  body.read-only header .btn, body.read-only #upload-card, body.read-only #upload-result, body.read-only #fill-months,
  body.read-only [data-add-partner], body.read-only .edit-only, body.read-only .save-state { display: none !important; }
  body.read-only.can-market #marketing .save-state { display: inline !important; }
  body.read-only input[data-set], body.read-only select[data-link], body.read-only [data-bud] { pointer-events: none; background: #f6f6f8; border-color: #e4e4ea; }
  .empty { padding: 30px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.6; }

  #login { position: fixed; inset: 0; background: rgba(26,26,46,0.92); z-index: 100; display: none; align-items: center; justify-content: center; padding: 16px; }
  #login.show { display: flex; }
  #login form { background: #fff; border-radius: 12px; padding: 26px 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; box-shadow: 0 8px 40px rgba(0,0,0,0.3); }
  #login h2 { color: var(--ink); font-size: 18px; }
  #login p { color: #666; font-size: 13px; line-height: 1.5; }
  #login input { height: 38px; font-size: 14px; }
  #login button { height: 38px; }
  #login-error { color: #c73652; font-size: 13px; min-height: 1em; }

  @media (max-width: 760px) {
    header { padding: 8px 10px; }
    #data-status { display: none; }
    .hero { grid-template-columns: 1fr; }
    .hero .tiles { grid-template-columns: 1fr; }
    .hero-main .value { font-size: 36px; }
    main { padding: 12px 10px 40px; }
    section.card { padding: 12px; }
    .tabs .fy-pick { margin-left: 8px; }
  }
