/* ============================================================================
   Business OS Web App — app.css
   Layout + app-specific rules not already covered by tokens.css / ui.css.
   Only design-token values used — no hardcoded hex, no font-weight above 600.
   ========================================================================== */

.hidden { display: none !important; }

/* ── APP SHELL LAYOUT ─────────────────────────────────────────────────── */
.shell { display: flex; height: 100vh; width: 100%; }

.sidebar {
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding-top: var(--sp-4);
}

.sidebar-header { padding: 0 10px var(--sp-2); }
.sidebar-ws-name {
  font-size: var(--b1);
  font-weight: var(--w-semibold);
  letter-spacing: -.01em;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-section { display: flex; flex-direction: column; gap: 6px; }
.sidebar-section-head { display: flex; align-items: center; justify-content: space-between; padding: 0 10px; }
.sidebar-add-channel { margin-left: auto; }

.sidebar-channel-list, .sidebar-tree { display: flex; flex-direction: column; gap: 1px; }

.sidebar-channel-item, .tree-project-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px var(--sp-2);
  border-radius: var(--r-sm);
  color: var(--ink);
  text-decoration: none;
  font-size: var(--b3);
  font-weight: var(--w-medium);
  transition: background var(--dur-micro) ease;
}
.sidebar-channel-item:hover, .tree-project-row:hover { background: var(--grey-200); }

.channel-hash { color: var(--muted); flex-shrink: 0; }
.channel-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.unread-dot {
  width: var(--dot-scale); height: var(--dot-scale);
  border-radius: 50%; background: var(--func-peak); flex-shrink: 0;
}

.sidebar-empty { padding: 6px var(--sp-2); font-size: var(--b3); color: var(--muted); }

.tree-category-summary, .tree-subcategory-summary {
  display: flex; align-items: center; gap: 6px;
  padding: 6px var(--sp-2);
  font-size: var(--b3); font-weight: var(--w-medium);
  color: var(--ink);
  cursor: pointer;
  list-style: none;
}
.tree-category-summary::-webkit-details-marker,
.tree-subcategory-summary::-webkit-details-marker { display: none; }
.tree-category-summary svg, .tree-subcategory-summary svg {
  width: var(--ctrl-sm-icon); height: var(--ctrl-sm-icon);
  stroke: var(--muted); fill: none; stroke-width: 1.6;
  transition: transform var(--dur-micro) ease;
}
details[open] > summary svg { transform: rotate(90deg); }
.tree-subcategory { margin-left: var(--sp-3); }
.tree-project-row { margin-left: var(--sp-4); font-weight: var(--w-regular); }

.sidebar-user-chip {
  margin-top: auto;
  display: flex; align-items: center; gap: 8px;
  padding: var(--sp-2);
  border-top: var(--divider);
}
.sidebar-avatar {
  width: var(--ctrl-lg); height: var(--ctrl-lg);
  border-radius: 50%;
  background: var(--ink-900); color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--b3); font-weight: var(--w-semibold);
  flex-shrink: 0;
}
.sidebar-avatar.sm { width: var(--ctrl-md); height: var(--ctrl-md); font-size: var(--b4); }
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: var(--b3); font-weight: var(--w-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { font-size: var(--b4); color: var(--muted); text-transform: capitalize; }

.hamburger { display: none; position: fixed; top: var(--sp-3); left: var(--sp-3); z-index: 18; }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; z-index: 19;
  background: color-mix(in srgb, var(--ink-900) 35%, transparent);
}
.sidebar-backdrop.show { display: block; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.view-root { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.view-root > *:not(.chat-view) { padding: var(--sp-6); }

@media (max-width: 767px) {
  .hamburger { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 20;
    transform: translateX(-100%);
    transition: transform .22s var(--ease);
    background: var(--bg);
  }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 24px color-mix(in srgb, var(--ink-900) 16%, transparent); }
  .view-root > *:not(.chat-view) { padding: var(--sp-4); padding-top: calc(var(--sp-4) + 36px); }
}

/* ── VIEW COMMON STATES ───────────────────────────────────────────────── */
.view-loading, .empty-state, .error-card {
  padding: var(--sp-5);
  font-size: var(--b2);
  color: var(--muted);
  text-align: center;
}
.error-card {
  background: color-mix(in srgb, var(--func-danger) 8%, var(--white));
  border: none;
  color: var(--func-danger);
  border-radius: var(--r-sm);
}
.view-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-5); }
h1 { font-size: 20px; font-weight: var(--w-semibold); letter-spacing: -.01em; }
h2.section-label { margin-bottom: var(--sp-3); }

/* ── FORMS ────────────────────────────────────────────────────────────── */
.form-label {
  display: block; font-size: var(--b3); font-weight: var(--w-medium);
  color: var(--muted); margin: var(--sp-3) 0 6px;
}
.form-stack { display: flex; flex-direction: column; }
.form-stack .form-label:first-child { margin-top: 0; }

.input, .select {
  width: 100%;
  font-family: var(--font);
  font-size: var(--b2);
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--grey-400);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  transition: border-color var(--dur-micro) ease;
}
.input:focus, .select:focus, textarea:focus {
  outline: none;
  border-color: var(--ink-900);
}
.input:focus-visible, .select:focus-visible, button:focus-visible, a:focus-visible, [tabindex]:focus-visible,
.bx-inline-input:focus-visible, .bx-detail-textarea:focus-visible, .bx-modal-desc:focus-visible, .bx-add-card-composer textarea:focus-visible {
  outline: 2px solid var(--func-peak);
  outline-offset: 2px;
}

.role-select { padding: 6px 8px; font-size: var(--b3); width: auto; }

/* ── BUTTONS ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font); font-size: var(--b2); font-weight: var(--w-medium);
  padding: 9px 16px;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--dur-micro) ease, color var(--dur-micro) ease, border-color var(--dur-micro) ease;
}
.btn-primary { background: var(--ink-900); color: var(--white); }
.btn-primary:hover { background: var(--ink); opacity: .92; }
.btn-ghost { background: transparent; border-color: var(--grey-400); color: var(--ink); }
.btn-ghost:hover { background: var(--grey-200); }
.btn-danger { background: var(--func-danger); color: var(--white); }
.btn.sm { padding: 5px 12px; font-size: var(--b3); }

/* ── AUTH SCREEN ──────────────────────────────────────────────────────── */
.auth-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
  padding: var(--sp-5);
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--white);
  border-radius: var(--r-md);
  padding: var(--sp-6);
}
.auth-brand { font-size: var(--b1); font-weight: var(--w-semibold); margin-bottom: var(--sp-5); text-align: center; }
.auth-tabs { display: flex; gap: 2px; background: var(--grey-200); border-radius: var(--r-pill); padding: 3px; margin-bottom: var(--sp-5); }
.auth-tab {
  flex: 1; border: none; background: transparent; cursor: pointer;
  font-family: var(--font); font-size: var(--b3); font-weight: var(--w-medium); color: var(--muted);
  padding: 8px; border-radius: var(--r-pill);
  transition: background var(--dur-micro) ease, color var(--dur-micro) ease;
}
.auth-tab.active { background: var(--ink-900); color: var(--white); }
.auth-panel { display: flex; flex-direction: column; }
.auth-submit { margin-top: var(--sp-5); width: 100%; }
.auth-google { margin-top: var(--sp-3); width: 100%; }
.auth-error {
  margin-top: var(--sp-3);
  font-size: var(--b3); color: var(--func-danger);
  background: color-mix(in srgb, var(--func-danger) 8%, var(--white));
  border-radius: var(--r-sm);
  padding: 8px 10px;
}

/* ── MODAL ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 110;
  background: color-mix(in srgb, var(--ink-900) 40%, transparent);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-4);
}
.modal-dialog {
  width: 100%; max-width: 460px; max-height: 86vh;
  overflow-y: auto;
  background: var(--white);
  border-radius: var(--r-md);
  padding: var(--sp-5);
  display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-4); }
.modal-title { font-size: var(--b1); font-weight: var(--w-semibold); }
.modal-close { font-size: 18px; line-height: 1; }
.modal-body { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-5); }

/* ── TOAST ────────────────────────────────────────────────────────────── */
.toast-stack {
  position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: 50;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 320px;
}
.toast {
  padding: 10px 14px;
  border-radius: var(--r-sm);
  background: var(--ink-900); color: var(--white);
  font-size: var(--b3);
  box-shadow: 0 4px 16px color-mix(in srgb, var(--ink-900) 18%, transparent);
  opacity: 0; transform: translateY(6px);
  transition: opacity var(--dur-micro) ease, transform var(--dur-micro) ease;
  cursor: pointer;
}
.toast.toast-in { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--func-success); }
.toast-error { background: var(--func-danger); }

/* ── TABLES ───────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: var(--b3); }
.table th {
  text-align: left; padding: 8px 10px;
  font-size: var(--b4); font-weight: var(--label-w);
  text-transform: uppercase; letter-spacing: var(--label-ls);
  color: var(--muted);
  border-bottom: var(--divider);
}
.table td { padding: 10px; border-bottom: var(--divider); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.admin-table-wrap, .team-table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--r-md); }

.team-avatar-cell { display: flex; align-items: center; gap: 4px; }
.online-dot {
  width: var(--dot-scale); height: var(--dot-scale);
  border-radius: 50%; background: var(--func-success); flex-shrink: 0;
}

.badge-active { background: color-mix(in srgb, var(--func-success) 14%, var(--white)); color: var(--ink); font-weight: var(--w-pill); }
.badge-inactive { background: color-mix(in srgb, var(--func-danger) 12%, var(--white)); color: var(--ink); font-weight: var(--w-pill); }

.admin-section { margin-bottom: var(--sp-6); }
.audit-pager { display: flex; align-items: center; gap: var(--sp-3); margin-top: var(--sp-3); }
.audit-page-label { font-size: var(--b3); color: var(--muted); }

.invite-code-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.invite-code {
  font-family: monospace; font-size: var(--b2);
  background: var(--grey-200); padding: 8px 10px; border-radius: var(--r-sm);
  flex: 1; overflow-x: auto;
}

.member-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: var(--divider); }
.member-row:last-child { border-bottom: none; }
.member-name { font-weight: var(--w-medium); }
.member-role { color: var(--muted); font-size: var(--b3); text-transform: capitalize; }

/* ── CHAT VIEW ────────────────────────────────────────────────────────── */
.chat-view { display: flex; flex-direction: column; height: 100%; }
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4) var(--sp-6);
  border-bottom: var(--divider);
  flex-shrink: 0;
}
.chat-header-title { font-size: var(--b1); font-weight: var(--w-semibold); }
.chat-header-topic { font-size: var(--b3); color: var(--muted); margin-top: 2px; }
.chat-header-actions { display: flex; gap: 6px; }

.chat-messages { flex: 1; overflow-y: auto; padding: var(--sp-4) var(--sp-6); display: flex; flex-direction: column; }

.msg-date-sep { display: flex; align-items: center; justify-content: center; margin: var(--sp-4) 0; }
.msg-date-sep span {
  font-size: var(--b3); font-weight: var(--w-pill); color: var(--muted); text-transform: uppercase; letter-spacing: var(--label-ls);
  background: var(--grey-200); padding: 3px 10px; border-radius: var(--r-pill);
}

/* .badge lives in ui.css (read-only); override weight here — app.css loads last */
.badge { font-weight: var(--w-pill); }

.msg-row { display: flex; gap: 10px; padding: 3px 0; }
.msg-row.grouped { padding-top: 1px; }
.msg-avatar {
  width: var(--ctrl-lg); height: var(--ctrl-lg); border-radius: 50%;
  background: var(--ink-900); color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--b3); font-weight: var(--w-semibold);
  flex-shrink: 0;
}
.msg-avatar.spacer { background: transparent; }
.msg-body { flex: 1; min-width: 0; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-author { font-size: var(--b3); font-weight: var(--w-semibold); }
.msg-time { font-size: var(--b4); color: var(--muted); }
.msg-text { font-size: var(--b2); white-space: pre-wrap; word-break: break-word; }

.chat-composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: var(--sp-4) var(--sp-6);
  border-top: var(--divider);
  flex-shrink: 0;
  position: relative;
}
.composer-input {
  flex: 1;
  font-family: var(--font); font-size: var(--b2);
  border: 1px solid var(--grey-400); border-radius: var(--r-sm);
  padding: 10px 12px;
  resize: none;
  max-height: 160px;
}
.thinking-indicator {
  font-size: var(--b4); color: var(--muted);
  padding: 0 var(--sp-6) 4px;
}

@media (max-width: 640px) {
  :root { --b1: 15px; --b2: 14px; --b3: 13px; --b4: 11px; }
  .btn-icon, .btn-icon.sm { width: 40px; height: 40px; }
  .btn-icon svg { width: var(--ctrl-lg-icon); height: var(--ctrl-lg-icon); }
  .chat-header, .chat-messages, .chat-composer { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .thinking-indicator { padding: 0 var(--sp-4) 4px; }
}

/* [hidden] must beat any display rule (auth screen / app shell toggling). */
[hidden] { display: none !important; }
