/*
 * BeeBrands panel — layout and components. Flat, pastel, one stylesheet.
 * Colours come from tokens.css only; nothing here names a hex value.
 */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--bb-font);
  font-size: var(--bb-size-md);
  color: var(--bb-text);
  background: var(--bb-bg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--bb-link); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--bb-focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--bb-muted); }
.small { font-size: var(--bb-size-sm); }
.xsmall { font-size: var(--bb-size-xs); }
.mono { font-family: var(--bb-mono); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-rows: var(--bb-header-h) 1fr; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: var(--bb-space-3);
  padding: 0 var(--bb-space-4);
  background: var(--bb-white);
  border-bottom: 1px solid var(--bb-line);
  position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: var(--bb-space-2); font-weight: 700; color: var(--bb-text); }
.brand img { width: 30px; height: 30px; }
.brand:hover { text-decoration: none; }
.search { flex: 1; display: flex; max-width: 560px; margin: 0 auto; }
.search input { flex: 1; border-radius: var(--bb-radius) 0 0 var(--bb-radius); }
.search button { border-radius: 0 var(--bb-radius) var(--bb-radius) 0; }
.usermenu { display: flex; align-items: center; gap: var(--bb-space-2); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bb-purple); color: var(--bb-purple-deep);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--bb-size-sm); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.topbar .menu-toggle { display: none; }

.body { display: grid; grid-template-columns: var(--bb-nav-w) 1fr; min-height: 0; }
.nav {
  background: var(--bb-surface); border-right: 1px solid var(--bb-line);
  overflow-y: auto; padding: var(--bb-space-3) 0;
}
.nav ul { list-style: none; margin: 0; padding: 0; }
.nav li > a, .nav .nav-head {
  display: flex; align-items: center; gap: var(--bb-space-2);
  padding: 6px var(--bb-space-4); color: var(--bb-text); font-size: var(--bb-size-sm);
}
.nav li > a:hover { background: var(--bb-grey-100); text-decoration: none; }
.nav li > a.active { background: var(--bb-yellow); font-weight: 600; }
.nav .nav-head { font-weight: 700; justify-content: space-between; }
.nav .indent-1 > a { padding-left: calc(var(--bb-space-4) + 14px); }
.nav .indent-2 > a { padding-left: calc(var(--bb-space-4) + 28px); }
.nav .indent-3 > a { padding-left: calc(var(--bb-space-4) + 42px); }
.nav .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .count {
  background: var(--bb-orange); border-radius: 999px; padding: 0 7px;
  font-size: var(--bb-size-xs); font-weight: 700;
}
.nav .add {
  border: none; background: none; cursor: pointer; color: var(--bb-muted);
  font-weight: 700; padding: 0 var(--bb-space-2);
}
.nav .add:hover { color: var(--bb-text); }
.nav .section { margin-top: var(--bb-space-3); }

.content { overflow-y: auto; padding: var(--bb-space-5); min-width: 0; }
.page-head {
  display: flex; align-items: center; gap: var(--bb-space-3); flex-wrap: wrap;
  margin-bottom: var(--bb-space-4);
}
.page-head h1 { font-size: var(--bb-size-xl); margin: 0; flex: 1; }
.crumbs { font-size: var(--bb-size-sm); color: var(--bb-muted); margin-bottom: var(--bb-space-2); }

/* ---------- Controls ---------- */
button, .btn {
  font: inherit; font-size: var(--bb-size-sm);
  border: 1px solid var(--bb-line); background: var(--bb-white); color: var(--bb-text);
  padding: 7px 14px; border-radius: var(--bb-radius); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: background var(--bb-ease);
}
button:hover, .btn:hover { background: var(--bb-grey-100); text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--bb-accent); border-color: var(--bb-honey-deep); color: var(--bb-accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--bb-honey-deep); }
.btn-danger { color: var(--bb-danger); border-color: var(--bb-danger); }
.btn-quiet { border-color: transparent; background: transparent; }
.btn-ai { background: var(--bb-purple); border-color: var(--bb-purple-deep); color: var(--bb-purple-deep); }
.btn-row { display: flex; gap: var(--bb-space-2); flex-wrap: wrap; align-items: center; }

input, select, textarea {
  font: inherit; font-size: var(--bb-size-sm);
  border: 1px solid var(--bb-line); border-radius: var(--bb-radius-sm);
  padding: 7px 10px; background: var(--bb-white); color: var(--bb-text); min-width: 0;
}
textarea { width: 100%; min-height: 90px; resize: vertical; }
label { display: block; font-size: var(--bb-size-sm); font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: var(--bb-space-3); }
.field input, .field select, .field textarea { width: 100%; }
.inline-form { display: flex; gap: var(--bb-space-2); flex-wrap: wrap; align-items: flex-end; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; }

/* ---------- Surfaces ---------- */
.card {
  background: var(--bb-white); border: 1px solid var(--bb-line);
  border-radius: var(--bb-radius); padding: var(--bb-space-4);
}
.card h2, .card h3 { margin: 0 0 var(--bb-space-3); font-size: var(--bb-size-lg); }
.card.tint-yellow { background: var(--bb-yellow); }
.card.tint-blue { background: var(--bb-blue); }
.card.tint-sea { background: var(--bb-sea); }
.card.tint-purple { background: var(--bb-purple); }
.card.tint-orange { background: var(--bb-orange); }
.grid { display: grid; gap: var(--bb-space-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack > * + * { margin-top: var(--bb-space-4); }
.empty { color: var(--bb-muted); padding: var(--bb-space-5); text-align: center; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: var(--bb-space-2) 0; border-bottom: 1px solid var(--bb-line); display: flex; gap: var(--bb-space-2); align-items: center; }
.list li:last-child { border-bottom: none; }

/* ---------- Traffic lights ---------- */
.tl { display: inline-flex; align-items: center; gap: 6px; font-size: var(--bb-size-sm); }
.tl::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  background: var(--bb-none-light); flex: none;
}
.tl-green::before { background: var(--bb-green-light); }
.tl-yellow::before { background: var(--bb-yellow-light); }
.tl-red::before { background: var(--bb-red-light); }
.tl-big::before { width: 18px; height: 18px; }

/* ---------- Badges, tables ---------- */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: var(--bb-size-xs); font-weight: 600; background: var(--bb-grey-100);
}
.badge-blue { background: var(--bb-blue); color: var(--bb-blue-deep); }
.badge-sea { background: var(--bb-sea); color: var(--bb-sea-deep); }
.badge-purple { background: var(--bb-purple); color: var(--bb-purple-deep); }
.badge-orange { background: var(--bb-orange); }
.badge-yellow { background: var(--bb-yellow); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--bb-size-sm); }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--bb-line); vertical-align: top; }
table.data th { font-weight: 600; color: var(--bb-muted); background: var(--bb-surface); position: sticky; top: 0; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data tr:hover td { background: var(--bb-grey-50); }
.table-wrap { overflow-x: auto; border: 1px solid var(--bb-line); border-radius: var(--bb-radius); }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: var(--bb-space-3); overflow-x: auto; }
.kcol { background: var(--bb-surface); border-radius: var(--bb-radius); padding: var(--bb-space-3); min-height: 200px; }
.kcol h3 { font-size: var(--bb-size-sm); text-transform: uppercase; letter-spacing: .04em; color: var(--bb-muted); margin: 0 0 var(--bb-space-2); }
.kcol.drop { outline: 2px dashed var(--bb-honey); }
.kcard {
  background: var(--bb-white); border: 1px solid var(--bb-line); border-radius: var(--bb-radius-sm);
  padding: var(--bb-space-2) var(--bb-space-3); margin-bottom: var(--bb-space-2); cursor: grab; font-size: var(--bb-size-sm);
}
.kcard.dragging { opacity: .5; }
.split { display: grid; grid-template-columns: 1fr 360px; gap: var(--bb-space-4); }
.group-head { font-weight: 700; font-size: var(--bb-size-sm); padding: var(--bb-space-2) 0; border-bottom: 2px solid var(--bb-line); margin-top: var(--bb-space-3); }
.row-item { display: flex; gap: var(--bb-space-2); align-items: center; padding: 6px var(--bb-space-2); border-radius: var(--bb-radius-sm); cursor: pointer; }
.row-item:hover { background: var(--bb-grey-50); }
.row-item.selected { background: var(--bb-yellow); }
.row-item .grow { flex: 1; }

/* ---------- Modal, toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(34, 38, 46, .35); display: flex; align-items: center; justify-content: center; z-index: 50; padding: var(--bb-space-4); }
.modal { background: var(--bb-white); border-radius: var(--bb-radius); padding: var(--bb-space-5); width: min(520px, 100%); max-height: 90vh; overflow-y: auto; }
.modal h2 { margin-top: 0; }
.toasts { position: fixed; bottom: var(--bb-space-4); right: var(--bb-space-4); display: grid; gap: var(--bb-space-2); z-index: 60; }
.toast { background: var(--bb-ink); color: var(--bb-white); padding: 10px 14px; border-radius: var(--bb-radius); font-size: var(--bb-size-sm); max-width: 360px; }
.toast.error { background: var(--bb-red-light); }

/* ---------- Welcome / sign-in ---------- */
.welcome { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, var(--bb-yellow), var(--bb-sea)); padding: var(--bb-space-4); }
.welcome .card { width: min(420px, 100%); text-align: center; padding: var(--bb-space-6); }
.welcome img { width: 72px; height: 72px; }
.welcome h1 { margin: var(--bb-space-3) 0 var(--bb-space-2); }
.code-input { font-family: var(--bb-mono); font-size: var(--bb-size-lg); letter-spacing: .2em; text-align: center; width: 100%; }
.qr { background: var(--bb-white); padding: var(--bb-space-3); border-radius: var(--bb-radius); display: inline-block; }
.qr img { width: 220px; height: 220px; image-rendering: pixelated; }
.codes { font-family: var(--bb-mono); columns: 2; background: var(--bb-surface); padding: var(--bb-space-3); border-radius: var(--bb-radius); }

/* ---------- Chat, frames ---------- */
.frame { width: 100%; height: calc(100vh - var(--bb-header-h) - 140px); border: 1px solid var(--bb-line); border-radius: var(--bb-radius); background: var(--bb-white); }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .topbar .menu-toggle { display: inline-flex; }
  .body { grid-template-columns: 1fr; }
  .nav {
    position: fixed; top: var(--bb-header-h); bottom: 0; left: 0; width: min(86vw, var(--bb-nav-w));
    transform: translateX(-100%); transition: transform var(--bb-ease); z-index: 30;
    box-shadow: 0 0 30px rgba(0, 0, 0, .15);
  }
  .nav.open { transform: none; }
  .content { padding: var(--bb-space-4) var(--bb-space-3); }
  .grid-2, .grid-3, .split { grid-template-columns: 1fr; }
  .search { display: none; }
  .search.open { display: flex; position: absolute; left: 0; right: 0; top: var(--bb-header-h); padding: var(--bb-space-2); background: var(--bb-white); border-bottom: 1px solid var(--bb-line); max-width: none; }
  .kanban { grid-template-columns: repeat(4, 80vw); }
  .brand span { display: none; }
}

@media print {
  .topbar, .nav, .no-print { display: none !important; }
  .app, .body { display: block; height: auto; }
  .content { overflow: visible; padding: 0; }
  .card { break-inside: avoid; }
  .tl::before { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { margin: 16mm; }
}

/* ---------- Utilities (no inline styles anywhere: the CSP forbids them) ---------- */
.mt-2 { margin-top: var(--bb-space-2); }
.mt-3 { margin-top: var(--bb-space-3); }
.mt-4 { margin-top: var(--bb-space-4); }
.w-100 { width: 100%; }
/* A split view with nothing selected gives the list the whole width. */
.split:has(> .detail:empty) { grid-template-columns: 1fr; }
.split > .detail:empty { display: none; }
.kanban { grid-template-columns: repeat(4, minmax(200px, 1fr)); }

/* ---------- Calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--bb-line); border-radius: var(--bb-radius); overflow: hidden; }
.cal-head { background: var(--bb-surface); font-size: var(--bb-size-xs); font-weight: 700; color: var(--bb-muted); padding: 6px 8px; text-transform: uppercase; }
.cal-day { min-height: 104px; border-top: 1px solid var(--bb-line); border-left: 1px solid var(--bb-line); padding: 4px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-day:nth-child(7n + 1) { border-left: none; }
.cal-out { background: var(--bb-grey-50); }
.cal-out .xsmall { opacity: .5; }
.cal-today { background: var(--bb-yellow); }
.cal-ev {
  display: block; width: 100%; text-align: left; border: none; border-radius: 4px; padding: 1px 6px;
  background: var(--bb-blue); color: var(--bb-blue-deep); font-size: var(--bb-size-xs);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-ev:hover { background: var(--bb-purple); }
@media (max-width: 860px) { .cal-day { min-height: 64px; } .cal-ev { padding: 0 3px; } }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.list.nested { margin-left: 22px; }

/* ---------- Chat ---------- */
.chat-split { grid-template-columns: 280px 1fr; }
.chat-split:has(> .detail:empty) { grid-template-columns: 280px 1fr; }
.messages { max-height: calc(100vh - 360px); min-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: var(--bb-space-2); }
.msg { padding: var(--bb-space-2) var(--bb-space-3); border-radius: var(--bb-radius-sm); background: var(--bb-surface); }
.rich p { margin: 4px 0; }
.rich pre { background: var(--bb-grey-100); padding: var(--bb-space-2); border-radius: var(--bb-radius-sm); overflow-x: auto; }
.rich blockquote { border-left: 3px solid var(--bb-honey); margin: 4px 0; padding-left: var(--bb-space-2); color: var(--bb-muted); }
@media (max-width: 860px) { .chat-split { grid-template-columns: 1fr; } }
.price { font-size: 1.4rem; font-weight: 800; margin: 6px 0; }
.msg-user { background: var(--bb-yellow); }

/* ---------- Report page editor ---------- */
.rp-editor { display: grid; grid-template-columns: 200px 1fr 1fr; gap: var(--bb-space-4); align-items: start; }
.rp-widget { display: flex; align-items: center; gap: var(--bb-space-2); padding: 8px 10px; margin: 4px 0; background: var(--bb-surface); border: 1px solid var(--bb-line); border-radius: var(--bb-radius-sm); cursor: grab; font-size: var(--bb-size-sm); }
.rp-gear { visibility: hidden; }
.rp-widget:hover .rp-gear, .rp-gear:focus { visibility: visible; }
.rp-slot { height: 10px; border-radius: 4px; }
.rp-slot.drop { background: var(--bb-honey); height: 24px; }
@media (max-width: 1100px) { .rp-editor { grid-template-columns: 1fr; } }
