/* POURA v0.4.1 — tenant security, accessible states and portal repairs */
:root {
  --v041-canvas: var(--bg, #090909);
  --v041-surface: var(--card, #141414);
  --v041-surface-raised: var(--card-raised, #1a1a1a);
  --v041-surface-muted: rgba(255,255,255,.045);
  --v041-border: rgba(255,255,255,.12);
  --v041-text: var(--text, #f7f7f7);
  --v041-muted: var(--text-dim, #a0a0a0);
  --v041-shadow: 0 18px 45px rgba(0,0,0,.20);
  --v041-success-bg: rgba(33,180,105,.12);
  --v041-warning-bg: rgba(245,158,11,.12);
  --v041-danger-bg: rgba(239,68,68,.12);
}
[data-theme="light"] {
  --v041-canvas: #f6f6f7;
  --v041-surface: #ffffff;
  --v041-surface-raised: #ffffff;
  --v041-surface-muted: #f2f2f4;
  --v041-border: #dedee3;
  --v041-text: #17171a;
  --v041-muted: #64646e;
  --v041-shadow: 0 16px 44px rgba(20,20,25,.09);
}

.v04-card,
.portal-access-card,
.retention-card,
.coach-chat-card,
.coach-message.assistant,
.v041-card,
.v041-action-panel {
  background: var(--v041-surface) !important;
  color: var(--v041-text) !important;
  border: 1px solid var(--v041-border) !important;
  box-shadow: var(--v041-shadow);
}
.v04-card p,.v041-card p,.coach-message.assistant,.v041-action-panel p { color: var(--v041-muted) !important; }
.v04-card .input,.coach-chat-card .input { background: var(--v041-surface-muted); color: var(--v041-text); border-color: var(--v041-border); }
.quick-prompt { background: var(--v041-surface-muted); color: var(--v041-text); border-color: var(--v041-border); }

.v041-loading-page { padding: clamp(18px,3vw,36px); max-width: 1240px; margin: 0 auto; }
.v041-loading-head,.v041-skeleton-card,.v041-skeleton-line {
  background: linear-gradient(90deg,var(--v041-surface-muted),var(--v041-surface),var(--v041-surface-muted));
  background-size: 220% 100%; animation: v041-shimmer 1.35s infinite linear; border:1px solid var(--v041-border);
}
.v041-loading-head { height: 132px; border-radius: 22px; }
.v041-loading-grid { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:14px; margin-top:16px; }
.v041-skeleton-card { height:115px; border-radius:18px; }
@keyframes v041-shimmer { to { background-position:-220% 0; } }

.v041-action-panel { margin-top:16px; padding:22px; border-radius:18px; display:flex; align-items:center; justify-content:space-between; gap:20px; }
.v041-action-panel h2 { margin:.25rem 0 .35rem; }

.v041-delegation-banner {
  position:sticky; top:0; z-index:1000; min-height:46px; padding:8px 18px;
  display:flex; align-items:center; justify-content:center; gap:18px;
  background:#ff4d17; color:#fff; font-weight:750; box-shadow:0 4px 18px rgba(0,0,0,.25);
}
.v041-delegation-banner button { border:1px solid rgba(255,255,255,.55); background:rgba(0,0,0,.18); color:#fff; border-radius:9px; padding:7px 11px; cursor:pointer; font-weight:700; }

.v041-page { width:min(1280px,calc(100% - 32px)); margin:0 auto; padding:24px 0 48px; }
.v041-page-head { display:flex; align-items:flex-end; justify-content:space-between; gap:20px; margin-bottom:18px; }
.v041-page-head h1 { margin:3px 0 4px; font-size:clamp(30px,4vw,52px); }
.v041-page-head p { color:var(--v041-muted); margin:0; max-width:760px; }
.v041-kicker { color:var(--accent,#ff4d17); font-size:.72rem; font-weight:850; letter-spacing:.12em; text-transform:uppercase; }
.v041-grid { display:grid; gap:16px; }
.v041-grid-2 { grid-template-columns:repeat(2,minmax(0,1fr)); }
.v041-grid-3 { grid-template-columns:repeat(3,minmax(0,1fr)); }
.v041-grid-4 { grid-template-columns:repeat(4,minmax(0,1fr)); }
.v041-card { border-radius:18px; padding:20px; }
.v041-card h2,.v041-card h3 { margin:.1rem 0 .5rem; }
.v041-card-header { display:flex; justify-content:space-between; align-items:center; gap:14px; margin-bottom:14px; }
.v041-metric strong { display:block; font-size:clamp(28px,4vw,42px); line-height:1; }
.v041-metric span { display:block; margin-top:9px; font-weight:750; }
.v041-metric small { color:var(--v041-muted); }
.v041-status { display:inline-flex; align-items:center; gap:6px; padding:5px 9px; border-radius:999px; font-size:.72rem; font-weight:800; text-transform:uppercase; letter-spacing:.04em; }
.v041-status.is-active { background:var(--v041-success-bg); color:#29a868; }
.v041-status.is-warning { background:var(--v041-warning-bg); color:#d78a00; }
.v041-status.is-danger { background:var(--v041-danger-bg); color:#dc4040; }

.v041-toolbar { display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin:14px 0; }
.v041-toolbar .input { min-width:220px; flex:1; }
.v041-filter { border:1px solid var(--v041-border); background:var(--v041-surface); color:var(--v041-text); border-radius:999px; padding:8px 12px; cursor:pointer; }
.v041-filter.is-active { border-color:var(--accent,#ff4d17); color:var(--accent,#ff4d17); background:rgba(255,77,23,.08); }

.v041-people-table { overflow:auto; border:1px solid var(--v041-border); border-radius:16px; background:var(--v041-surface); }
.v041-people-row { min-width:1000px; display:grid; grid-template-columns:1.55fr 1fr .9fr 1fr 1fr 1.15fr auto; gap:12px; align-items:center; padding:13px 15px; border-top:1px solid var(--v041-border); }
.v041-people-row:first-child { border-top:0; }
.v041-people-row.is-head { font-size:.72rem; text-transform:uppercase; letter-spacing:.07em; color:var(--v041-muted); font-weight:800; background:var(--v041-surface-muted); }
.v041-person-name strong { display:block; }
.v041-person-name small { display:block; color:var(--v041-muted); margin-top:3px; }
.v041-inline-select { width:100%; min-width:110px; padding:9px; border-radius:10px; border:1px solid var(--v041-border); background:var(--v041-surface-muted); color:var(--v041-text); }
.v041-row-actions { display:flex; gap:7px; }
.v041-empty,.v041-error { padding:28px; text-align:center; border:1px dashed var(--v041-border); border-radius:16px; background:var(--v041-surface); }
.v041-error { border-color:rgba(239,68,68,.45); }
.v041-empty h3,.v041-error h3 { margin:.2rem 0 .45rem; }
.v041-empty p,.v041-error p { color:var(--v041-muted); }

.v041-tenant-list { display:grid; gap:12px; }
.v041-tenant-row { display:grid; grid-template-columns:minmax(220px,1.5fr) repeat(4,minmax(90px,.5fr)) auto; align-items:center; gap:12px; padding:16px; border:1px solid var(--v041-border); background:var(--v041-surface); border-radius:15px; }
.v041-tenant-row strong { display:block; }
.v041-tenant-row small { color:var(--v041-muted); }
.v041-tenant-name { cursor:pointer; text-align:left; background:none; border:0; color:var(--v041-text); padding:0; }
.v041-tenant-name:hover strong { color:var(--accent,#ff4d17); }

.v041-tabs { display:flex; gap:8px; flex-wrap:wrap; margin:12px 0 18px; }
.v041-tab { border:1px solid var(--v041-border); background:var(--v041-surface); color:var(--v041-text); border-radius:10px; padding:9px 13px; cursor:pointer; font-weight:750; }
.v041-tab.is-active { border-color:var(--accent,#ff4d17); color:var(--accent,#ff4d17); }
.v041-settings-section { display:grid; grid-template-columns:240px minmax(0,1fr); gap:22px; padding:21px 0; border-top:1px solid var(--v041-border); }
.v041-settings-section:first-child { border-top:0; }
.v041-settings-section p { color:var(--v041-muted); }
.v041-form-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:14px; }
.v041-check { display:flex; align-items:center; gap:10px; min-height:42px; }

/* Nutrition repair */
.v041-nutrition { width:min(1320px,calc(100% - 32px)); margin:0 auto; padding:22px 0 50px; }
.v041-nutrition-head { display:flex; justify-content:space-between; align-items:flex-end; gap:18px; margin-bottom:16px; }
.v041-nutrition-head h1 { margin:0; font-size:clamp(30px,4vw,48px); }
.v041-date-strip { display:flex; align-items:center; gap:8px; border:1px solid var(--v041-border); border-radius:14px; padding:6px; background:var(--v041-surface); }
.v041-date-strip button { width:38px; height:38px; border-radius:10px; border:0; background:var(--v041-surface-muted); color:var(--v041-text); cursor:pointer; }
.v041-date-strip #foodDate { min-width:150px; text-align:center; font-weight:800; cursor:pointer; }
.v041-nutrition-grid { display:grid; grid-template-columns:minmax(0,1.65fr) minmax(330px,.8fr); gap:18px; align-items:start; }
.v041-nutrition-main,.v041-nutrition-side { display:grid; gap:16px; }
.v041-food-log,.v041-section-card { border:1px solid var(--v041-border); background:var(--v041-surface); border-radius:18px; padding:18px; box-shadow:var(--v041-shadow); }
.v041-food-log .ai-add-input-row { display:grid; grid-template-columns:minmax(0,1fr) 150px; gap:10px; }
.v041-food-log .ai-add-actions { display:flex; gap:8px; flex-wrap:wrap; margin-top:10px; }
.v041-food-log .food-hero-footer { margin-top:6px; }
.v041-section-title { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:12px; }
.v041-section-title h2 { margin:0; }
.v041-section-title small { color:var(--v041-muted); }
.v041-nutrition #foodTotals .card { margin:0; background:var(--v041-surface); border-color:var(--v041-border); color:var(--v041-text); }
.v041-nutrition .qa-grid { grid-template-columns:1fr !important; }
.v041-nutrition .food-item,.v041-nutrition .food-result { background:var(--v041-surface-muted); border-color:var(--v041-border); }

/* Challenges repair */
.v041-challenge-select { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:10px; }
.v041-board-list { display:grid; gap:8px; }
.v041-board-row { display:grid; grid-template-columns:54px minmax(0,1fr) 120px 120px; gap:12px; align-items:center; padding:14px; border:1px solid var(--v041-border); border-radius:13px; background:var(--v041-surface); }
.v041-board-row.is-me { border-color:var(--accent,#ff4d17); background:rgba(255,77,23,.06); }

@media (max-width:1000px) {
  .v041-loading-grid,.v041-grid-4 { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .v041-grid-3 { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .v041-nutrition-grid { grid-template-columns:1fr; }
  .v041-settings-section { grid-template-columns:1fr; }
  .v041-tenant-row { grid-template-columns:1fr 1fr 1fr; }
  .v041-tenant-row > :first-child { grid-column:1/-1; }
}
@media (max-width:680px) {
  .v041-page,.v041-nutrition { width:min(100% - 20px,1280px); padding-top:14px; }
  .v041-grid-2,.v041-grid-3,.v041-grid-4,.v041-loading-grid { grid-template-columns:1fr; }
  .v041-page-head,.v041-nutrition-head,.v041-action-panel { align-items:flex-start; flex-direction:column; }
  .v041-form-grid { grid-template-columns:1fr; }
  .v041-food-log .ai-add-input-row { grid-template-columns:1fr; }
  .v041-board-row { grid-template-columns:42px 1fr; }
  .v041-board-row > :nth-child(3),.v041-board-row > :nth-child(4) { grid-column:2; }
  .v041-delegation-banner { position:relative; flex-wrap:wrap; text-align:center; }
}

/* v0.4.2 theme and mobile navigation hardening */
.coach-chat-card,
.coach-chat-card .coach-conversation,
.coach-tip,
.coach-tip-loading,
.coach-message.assistant {
  background-color: var(--v041-surface) !important;
  color: var(--v041-text) !important;
}
.coach-chat-card .coach-conversation { background: transparent !important; }
.coach-tip-error { color: #d94727 !important; }
[data-theme="dark"] .coach-tip-error { color: #ff9a7d !important; }
.more-menu-item.is-danger { color: #d94727; }
.v042-control-session { display:flex; align-items:center; gap:.65rem; }
.v042-signout { white-space:nowrap; }

@media (max-width:760px) {
  .bottom-nav .nav-more-btn { display:flex !important; }
  .bottom-nav { grid-template-columns:repeat(5,minmax(0,1fr)); }
  .v042-signout { display:none; }
}
