/* =============================================================================
 * JP Command Centre -- hub.css
 * Version:  0.2.0
 * Updated:  2026-07-02
 * File:     /var/www/hub.jphospitalityhub.com/public_html/assets/hub.css
 *
 * Changelog:
 *   0.2.0  Added KPI strip (6-card grid, hero numerals, state colors, dots,
 *          source pills), universal period toggle, HubModal (backdrop, dialog,
 *          drag cursor, search, drill table, pending panel), .w-2 span class.
 *   0.1.0  Initial: design tokens, sticky topbar, 12-col grid, widget cards,
 *          light/dark themes, source badges, spinner.
 * ============================================================================= */

/* ----- DESIGN TOKENS ------------------------------------------------------- */
:root {
  --bg:            #f5f6f8;
  --surface:      #ffffff;
  --surface-2:    #fafbfc;
  --border:       #e3e6ea;
  --border-strong:#c8ccd2;
  --text:         #1a1d21;
  --text-muted:   #5b6470;
  --text-faint:   #8a939f;

  --accent:       #185FA5;      /* JP blue */
  --accent-hover: #144e88;
  --gold:         #B98A22;      /* JP gold */

  --ok:           #1f9d55;
  --alert:        #d0342c;
  --warn:         #b98a22;
  --pending:      #8a939f;

  --shadow-sm:    0 1px 2px rgba(15,23,42,.06);
  --shadow-md:    0 4px 12px rgba(15,23,42,.10);
  --shadow-lg:    0 20px 40px rgba(15,23,42,.18);

  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    14px;

  --font-body:    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono:    ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg:            #12151a;
  --surface:      #1a1e25;
  --surface-2:    #232830;
  --border:       #2a2f38;
  --border-strong:#3a4150;
  --text:         #e8ecf1;
  --text-muted:   #a4adba;
  --text-faint:   #6c7684;

  --accent:       #4a91d9;
  --accent-hover: #6aa6e3;
  --gold:         #d4a944;

  --ok:           #35c26a;
  --alert:        #ff5b52;
  --warn:         #d4a944;
  --pending:      #6c7684;

  --shadow-sm:    0 1px 2px rgba(0,0,0,.4);
  --shadow-md:    0 4px 12px rgba(0,0,0,.5);
  --shadow-lg:    0 20px 40px rgba(0,0,0,.6);
}

/* ----- BASE --------------------------------------------------------------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ----- TOPBAR ------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.topbar h1 {
  margin: 0;
  font-size: 16px; font-weight: 600; letter-spacing: .2px;
}
.topbar .brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  display: inline-block; margin-right: 8px; vertical-align: middle;
}
.topbar .grow { flex: 1; }
.topbar button {
  background: transparent; border: 1px solid var(--border);
  color: var(--text); padding: 6px 12px;
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px;
}
.topbar button:hover { background: var(--surface-2); border-color: var(--border-strong); }

/* ----- GRID --------------------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
  padding: 20px;
  max-width: 1600px;
  margin: 0 auto;
}
.w-2  { grid-column: span 2; }
.w-4  { grid-column: span 4; }
.w-6  { grid-column: span 6; }
.w-8  { grid-column: span 8; }
.w-12 { grid-column: span 12; }

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .w-2, .w-4, .w-6, .w-8, .w-12 { grid-column: span 1; }
}

/* ----- WIDGET CARDS ------------------------------------------------------- */
.widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex; flex-direction: column;
}
.widget-hdr {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600; font-size: 14px;
}
.widget-hdr .grow { flex: 1; }
.widget-body {
  padding: 16px;
  flex: 1;
}
.widget-meta {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px; color: var(--text-muted);
}
.widget-empty,
.widget-error {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 0;
}
.widget-error { color: var(--alert); }

/* ----- SOURCE BADGE (widget-meta) ---------------------------------------- */
.source-badge {
  display: inline-block;
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted);
}
.source-badge.cache     { background: #e8f4fd; border-color: #a9d3f3; color: #1465a8; }
.source-badge.portfolio { background: #fff5db; border-color: #e8c76a; color: #7a5a10; }
.source-badge.fallback  { background: #f0f2f5; border-color: #c8ccd2; color: #5b6470; }
.source-badge.live      { background: #e6f7ec; border-color: #9ed4b2; color: #1f7a3d; }
.source-badge.partial   { background: #fef3d6; border-color: #e8c76a; color: #7a5a10; }
.source-badge.pending   { background: #f0f2f5; border-color: #c8ccd2; color: #5b6470; }
.meta-when { color: var(--text-faint); }

/* ----- SPINNER ------------------------------------------------------------ */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- AI BRIEF ----------------------------------------------------------- */
.brief-narrative {
  font-size: 14px; line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
}
.brief-highlights {
  margin: 12px 0 0; padding-left: 20px;
  color: var(--text-muted); font-size: 13px;
}
.brief-highlights li { margin: 4px 0; }

/* ============================================================================
 * KPI STRIP (v0.2.0)
 * ========================================================================== */
.widget-body.kpi-body {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  padding: 16px;
}
@media (max-width: 1200px) {
  .widget-body.kpi-body { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 700px) {
  .widget-body.kpi-body { grid-template-columns: repeat(2, 1fr); }
}

.kpi-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 14px 12px;
  text-align: left;
  font: inherit; color: inherit;
  cursor: default;
  transition: box-shadow .12s ease, border-color .12s ease, transform .12s ease;
  min-height: 96px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.kpi-card.is-clickable { cursor: pointer; }
.kpi-card.is-clickable:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.kpi-value {
  font-size: 30px; font-weight: 700; letter-spacing: -.5px;
  line-height: 1.1;
  color: var(--text);
}
.kpi-value.state-neutral { color: var(--text); }
.kpi-value.state-alert   { color: var(--alert); }
.kpi-value.state-warn    { color: var(--warn); }
.kpi-value.state-ok      { color: var(--ok); }
.kpi-value.state-money   { color: var(--gold); }
.kpi-value.state-pending { color: var(--text-faint); }

.kpi-label {
  display: flex; align-items: center; gap: 6px;
  margin-top: 8px;
  font-size: 12px; color: var(--text-muted);
}
.kpi-period { color: var(--text-faint); }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; flex: none;
}
.dot-ok      { background: var(--ok); }
.dot-alert   { background: var(--alert); }
.dot-warn    { background: var(--warn); }
.dot-pending { background: var(--pending); }

/* Source pill (PMS / Pulse) in corner of card */
.src-pill {
  position: absolute; top: 8px; right: 8px;
  font-size: 9px; font-weight: 700; letter-spacing: .5px;
  padding: 2px 6px; border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-transform: uppercase;
}
.src-pill.src-pms   { background: #e8f4fd; border-color: #a9d3f3; color: #1465a8; }
.src-pill.src-pulse { background: #fff0e6; border-color: #f0b892; color: #a5501a; }

html[data-theme="dark"] .src-pill.src-pms   { background: #1a2f47; border-color: #2b4a70; color: #7bb5e8; }
html[data-theme="dark"] .src-pill.src-pulse { background: #3a2418; border-color: #6b4028; color: #e8a878; }

/* ============================================================================
 * HUB TOGGLE (period pill bar)
 * ========================================================================== */
.hub-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px;
}
.hub-toggle .pill,
.hub-toggle .pill-reset {
  background: transparent; border: 0;
  color: var(--text-muted);
  font: inherit; font-size: 12px; font-weight: 600;
  padding: 5px 12px; border-radius: 999px;
  cursor: pointer; letter-spacing: .3px;
  transition: background .12s ease, color .12s ease;
}
.hub-toggle .pill:hover,
.hub-toggle .pill-reset:hover:not(:disabled) {
  background: var(--surface-2); color: var(--text);
}
.hub-toggle .pill.is-active {
  background: var(--accent); color: #fff;
}
.hub-toggle .pill-reset {
  font-size: 14px; padding: 3px 8px;
  border-left: 1px solid var(--border); margin-left: 2px;
  border-radius: 0 999px 999px 0;
}
.hub-toggle .pill-reset:disabled {
  opacity: .35; cursor: not-allowed;
}

/* ============================================================================
 * HUB MODAL (drill-down)
 * ========================================================================== */
body.hub-modal-open { overflow: hidden; }

.hub-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  animation: fadein .12s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.hub-modal {
  position: relative;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(880px, calc(100vw - 40px));
  max-height: calc(100vh - 60px);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: pop .12s ease;
}
@keyframes pop { from { transform: scale(.98); opacity: .6; } to { transform: scale(1); opacity: 1; } }

.hub-modal.is-dragging { transition: none; user-select: none; }

.hub-modal-hdr {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  cursor: move;
}
.hub-modal-title {
  margin: 0; flex: 1;
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hub-modal-actions {
  display: flex; align-items: center; gap: 8px;
  cursor: auto;
}
.hub-modal-search {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font: inherit; font-size: 13px;
  width: 200px;
}
.hub-modal-search:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(24, 95, 165, .15);
}
.hub-modal-close {
  background: transparent; border: 0;
  color: var(--text-muted);
  width: 28px; height: 28px; border-radius: 6px;
  cursor: pointer; font-size: 14px; line-height: 1;
}
.hub-modal-close:hover { background: var(--surface); color: var(--text); }

.hub-modal-body {
  padding: 16px;
  overflow: auto;
  flex: 1;
}
.hub-modal-loading {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 40px 0; color: var(--text-muted);
}
.hub-modal-empty,
.hub-modal-error {
  color: var(--text-muted);
  padding: 24px; text-align: center;
}
.hub-modal-error { color: var(--alert); }
.hub-modal-pending {
  padding: 20px; text-align: center;
  color: var(--text-muted);
}
.hub-modal-pending h4 {
  margin: 0 0 8px; color: var(--text); font-size: 15px;
}
.hub-modal-pending p { margin: 4px 0; }

.btn-link {
  background: transparent; border: 0;
  color: var(--accent);
  cursor: pointer; text-decoration: underline;
  font: inherit;
}

/* ----- DRILL TABLE (inside modal body) ------------------------------------ */
.drill-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.drill-table thead th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  position: sticky; top: 0;
}
.drill-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.drill-table tbody tr:hover { background: var(--surface-2); }
