/* AI Project OS v31 — Finish Product Shell
 * Stacked over v30-shell.css. Tightens typography, fixes overlapping buttons,
 * adds top status strip, status badges system, command-center home, servers page,
 * truth panel, builderp-modular stages, app workspace tabs unified.
 *
 * RTL Hebrew. Dark theme by default (matches v9 styles.css). High contrast.
 */

:root {
  --v31-bg: #0e1014;
  --v31-bg-alt: #161a21;
  --v31-card: #1a1f28;
  --v31-card-2: #20262f;
  --v31-border: #2a3140;
  --v31-text: #e8ecf3;
  --v31-text-muted: #9aa3b2;
  --v31-text-faint: #6b7382;
  --v31-accent: #4f98a3;
  --v31-accent-hover: #66b4c1;
  --v31-ok: #4ec27a;
  --v31-warn: #e0a83a;
  --v31-err: #d65a76;
  --v31-info: #6a9bd8;
  --v31-purple: #a87bdc;
  --v31-shadow: 0 1px 0 rgba(255,255,255,.03), 0 4px 14px rgba(0,0,0,.18);
  --v31-radius: 10px;
}

/* ── Body when v31 active ───────────────────────────────────────────── */
body.v31-shell {
  font-family: 'Satoshi', 'Heebo', 'Assistant', system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: 0;
  background: var(--v31-bg);
  color: var(--v31-text);
}

body.v31-shell .v30-sidebar { font-family: inherit; }

/* ── Top status strip (server health + active jobs + login) ─────────── */
.v31-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 240px; /* sidebar on the right (RTL) */
  height: 44px;
  background: linear-gradient(180deg, rgba(20,24,32,0.96), rgba(14,16,20,0.96));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--v31-border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 14px;
  z-index: 90;
  font-size: 13px;
  direction: rtl;
}
@media (max-width: 900px) {
  .v31-topbar { right: 0; left: 0; }
}
.v31-topbar .v31-tb-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--v31-card);
  border: 1px solid var(--v31-border);
  color: var(--v31-text-muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.v31-topbar .v31-tb-item strong {
  color: var(--v31-text);
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
}
.v31-topbar .v31-tb-item.ok    { border-color: rgba(78,194,122,.4); }
.v31-topbar .v31-tb-item.ok    strong { color: var(--v31-ok); }
.v31-topbar .v31-tb-item.warn  { border-color: rgba(224,168,58,.4); }
.v31-topbar .v31-tb-item.warn  strong { color: var(--v31-warn); }
.v31-topbar .v31-tb-item.err   { border-color: rgba(214,90,118,.4); }
.v31-topbar .v31-tb-item.err   strong { color: var(--v31-err); }
.v31-topbar .v31-tb-spacer { flex: 1; }
.v31-topbar .v31-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--v31-text-faint);
}
.v31-topbar .v31-dot.ok { background: var(--v31-ok); box-shadow: 0 0 8px rgba(78,194,122,.5); }
.v31-topbar .v31-dot.warn { background: var(--v31-warn); }
.v31-topbar .v31-dot.err { background: var(--v31-err); }

/* Push main content below topbar */
body.v31-shell .v30-main,
body.v31-shell main.main,
body.v31-shell main {
  padding-top: 56px !important;
}

/* ── Sidebar refinements ────────────────────────────────────────────── */
body.v31-shell .v30-sidebar {
  background: var(--v31-bg-alt);
  border-left: 1px solid var(--v31-border);
}
body.v31-shell .v30-sidebar .v30-nav-group .v30-nav-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--v31-text-faint);
  padding: 14px 16px 6px;
}
body.v31-shell .v30-sidebar .v30-nav-item {
  font-size: 14.5px;
  font-weight: 500;
  padding: 9px 14px;
  margin: 1px 8px;
  border-radius: 8px;
  color: var(--v31-text);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% - 16px);
  cursor: pointer;
  text-align: right;
}
body.v31-shell .v30-sidebar .v30-nav-item:hover {
  background: var(--v31-card);
  border-color: var(--v31-border);
}
body.v31-shell .v30-sidebar .v30-nav-item.active {
  background: var(--v31-card-2);
  border-color: var(--v31-accent);
  color: var(--v31-text);
  font-weight: 700;
}
body.v31-shell .v30-sidebar .v30-nav-item .v30-nav-icon { font-size: 17px; opacity: .9; }
body.v31-shell .v30-sidebar .v30-nav-item .v30-nav-label-text { flex: 1; }

/* ── Status badges (universal vocabulary) ───────────────────────────── */
.v31-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
  letter-spacing: 0;
  vertical-align: middle;
}
.v31-badge.working { background: rgba(78,194,122,.14); color: var(--v31-ok); border-color: rgba(78,194,122,.35); }
.v31-badge.partial { background: rgba(224,168,58,.14); color: var(--v31-warn); border-color: rgba(224,168,58,.35); }
.v31-badge.planned { background: rgba(130,138,150,.14); color: var(--v31-text-muted); border-color: rgba(130,138,150,.35); }
.v31-badge.token   { background: rgba(168,123,220,.14); color: var(--v31-purple); border-color: rgba(168,123,220,.35); }
.v31-badge.readonly{ background: rgba(106,155,216,.14); color: var(--v31-info); border-color: rgba(106,155,216,.35); }
.v31-badge.err     { background: rgba(214,90,118,.14); color: var(--v31-err); border-color: rgba(214,90,118,.35); }

/* Hebrew labels via data attribute? No — JS supplies the text. */

/* ── Card / Panel system ────────────────────────────────────────────── */
.v31-card {
  background: var(--v31-card);
  border: 1px solid var(--v31-border);
  border-radius: var(--v31-radius);
  padding: 18px;
  box-shadow: var(--v31-shadow);
  margin-bottom: 14px;
}
.v31-card h2 {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--v31-text);
}
.v31-card h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 12px 0 6px;
  color: var(--v31-text);
}
.v31-card .muted { color: var(--v31-text-muted); font-size: 13px; }
.v31-card .subtitle { font-size: 13px; color: var(--v31-text-muted); margin-top: -4px; margin-bottom: 12px; }

/* ── Command center home grid ───────────────────────────────────────── */
.v31-home {
  max-width: 1320px;
  margin: 0 auto;
  padding: 8px 18px 40px;
  direction: rtl;
}
.v31-home .v31-hero {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 22px;
  margin-bottom: 18px;
  background: linear-gradient(135deg, #1c2330 0%, #161a21 100%);
  border: 1px solid var(--v31-border);
  border-radius: 14px;
}
.v31-home .v31-hero h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.v31-home .v31-hero p {
  font-size: 14px;
  color: var(--v31-text-muted);
  margin: 0;
}
.v31-home .v31-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}
@media (max-width: 1000px) {
  .v31-home .v31-grid { grid-template-columns: 1fr; }
}

/* ── Command bar (agent input) ─────────────────────────────────────── */
.v31-cmd {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 14px;
}
.v31-cmd input {
  flex: 1;
  background: var(--v31-bg);
  border: 1.5px solid var(--v31-border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--v31-text);
  font-size: 15px;
  font-family: inherit;
  direction: rtl;
}
.v31-cmd input:focus { outline: none; border-color: var(--v31-accent); }
.v31-cmd button {
  background: var(--v31-accent);
  color: #06181c;
  font-weight: 700;
  font-size: 14px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
.v31-cmd button:hover { background: var(--v31-accent-hover); }

/* ── Quick actions row ──────────────────────────────────────────────── */
.v31-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.v31-quick-actions .v31-qa {
  background: var(--v31-card);
  border: 1px solid var(--v31-border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--v31-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  white-space: nowrap;
}
.v31-quick-actions .v31-qa:hover {
  background: var(--v31-card-2);
  border-color: var(--v31-accent);
}

/* ── KPI tiles ──────────────────────────────────────────────────────── */
.v31-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.v31-kpi {
  background: var(--v31-card);
  border: 1px solid var(--v31-border);
  border-radius: 10px;
  padding: 12px 14px;
}
.v31-kpi .v31-kpi-label {
  font-size: 11px;
  color: var(--v31-text-faint);
  font-weight: 600;
  letter-spacing: .04em;
  margin-bottom: 4px;
}
.v31-kpi .v31-kpi-value {
  font-size: 22px;
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: -0.02em;
}
.v31-kpi.ok .v31-kpi-value { color: var(--v31-ok); }
.v31-kpi.warn .v31-kpi-value { color: var(--v31-warn); }
.v31-kpi.err .v31-kpi-value { color: var(--v31-err); }

/* ── Truth/Readiness panel (home + dedicated) ───────────────────────── */
.v31-truth {
  background: var(--v31-card);
  border: 1px solid var(--v31-border);
  border-radius: 10px;
  padding: 16px 18px;
}
.v31-truth h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.v31-truth-list { display: grid; gap: 6px; }
.v31-truth-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--v31-bg-alt);
  border: 1px solid var(--v31-border);
  border-radius: 8px;
  font-size: 13px;
}
.v31-truth-row .v31-truth-name { flex: 1; font-weight: 600; }
.v31-truth-row .v31-truth-note { color: var(--v31-text-muted); font-size: 12px; }

/* ── Servers page cards ─────────────────────────────────────────────── */
.v31-servers {
  max-width: 1320px;
  margin: 0 auto;
  padding: 8px 18px 40px;
  direction: rtl;
}
.v31-servers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
}
.v31-server-card {
  background: var(--v31-card);
  border: 1px solid var(--v31-border);
  border-radius: 12px;
  padding: 18px;
  position: relative;
}
.v31-server-card.future {
  background: repeating-linear-gradient(
    -45deg,
    var(--v31-card),
    var(--v31-card) 10px,
    var(--v31-card-2) 10px,
    var(--v31-card-2) 20px
  );
  border-style: dashed;
}
.v31-server-card .v31-sc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.v31-server-card .v31-sc-name {
  font-size: 16px;
  font-weight: 700;
}
.v31-server-card .v31-sc-domain {
  font-size: 12px;
  color: var(--v31-text-muted);
  font-family: 'IBM Plex Mono', monospace;
}
.v31-server-card .v31-sc-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.v31-server-card .v31-sc-stat {
  background: var(--v31-bg-alt);
  border: 1px solid var(--v31-border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
}
.v31-server-card .v31-sc-stat .label {
  color: var(--v31-text-faint);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .04em;
  display: block;
  margin-bottom: 2px;
}
.v31-server-card .v31-sc-stat .value {
  color: var(--v31-text);
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
}

/* ── Generic page wrapper ──────────────────────────────────────────── */
.v31-page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 8px 18px 40px;
  direction: rtl;
}
.v31-page-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.v31-page-head h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
}
.v31-page-head .v31-page-sub {
  color: var(--v31-text-muted);
  font-size: 14px;
}

/* ── Stage progress (builderp-modular) ──────────────────────────────── */
.v31-stages { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 12px 0 14px; }
@media (max-width: 800px) { .v31-stages { grid-template-columns: 1fr 1fr; } }
.v31-stage {
  background: var(--v31-bg-alt);
  border: 1px solid var(--v31-border);
  border-radius: 10px;
  padding: 12px 14px;
  position: relative;
}
.v31-stage.ok { border-color: rgba(78,194,122,.4); }
.v31-stage.partial { border-color: rgba(224,168,58,.4); }
.v31-stage .v31-stage-num {
  font-size: 11px;
  color: var(--v31-text-faint);
  font-weight: 600;
}
.v31-stage .v31-stage-label {
  font-size: 14px;
  font-weight: 700;
  margin: 4px 0 6px;
}
.v31-stage .v31-stage-status {
  font-size: 11.5px;
  color: var(--v31-text-muted);
}
.v31-stage.ok .v31-stage-status { color: var(--v31-ok); }
.v31-stage.partial .v31-stage-status { color: var(--v31-warn); }

/* ── Workspace tabs (unified) ──────────────────────────────────────── */
body.v31-shell .tab-bar,
body.v31-shell .v30-tabs,
body.v31-shell [role="tablist"] {
  flex-wrap: wrap !important;
  gap: 4px !important;
  padding: 8px 0 !important;
  border-bottom: 1px solid var(--v31-border) !important;
  margin-bottom: 14px !important;
}
body.v31-shell .tab-bar button,
body.v31-shell .v30-tabs button,
body.v31-shell [role="tablist"] button {
  font-size: 13px !important;
  padding: 7px 12px !important;
  border-radius: 7px !important;
}

/* ── Spacing/overlap fixes ──────────────────────────────────────────── */
body.v31-shell .btn,
body.v31-shell button {
  font-family: inherit;
}
body.v31-shell .flex { gap: 10px; }
body.v31-shell header.top { display: none !important; }

/* App cards */
body.v31-shell .app-card,
body.v31-shell .v30-app-card {
  background: var(--v31-card);
  border: 1px solid var(--v31-border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
body.v31-shell .app-card .name { font-size: 15px; font-weight: 700; }

/* Empty states */
.v31-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--v31-text-muted);
  background: var(--v31-bg-alt);
  border: 1px dashed var(--v31-border);
  border-radius: 10px;
}
.v31-empty .icon { font-size: 36px; margin-bottom: 8px; }

/* Sidebar override: make sure left padding (RTL: right padding for content) is right */
body.v31-shell .v30-main { padding-right: 240px !important; padding-left: 0 !important; }
@media (max-width: 900px) {
  body.v31-shell .v30-main { padding-right: 0 !important; }
}

/* Hide things we duplicate at top */
body.v31-shell .v30-progress-mini { bottom: 16px !important; }
