/* Workspace page styles — inherits global styles.css, adds workspace-specific styles */

/* Override styles.css nav/topbar defaults for workspace's border-bottom nav style */
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.nav-item {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 550;
  letter-spacing: 0;
  text-decoration: none;
  white-space: nowrap;
  border: 0;
}
.nav-item:hover {
  background: transparent;
  color: rgba(236, 239, 244, 0.86);
}
.nav-item.active {
  color: var(--fg);
  border-bottom: 2px solid var(--accent);
  border-color: var(--accent);
  background: transparent;
}
.workspace-title {
  color: var(--fg);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.workspace-subtitle {
  font-size: 11px;
  white-space: nowrap;
  color: var(--muted);
}

/* CSS vars for workspace-specific tokens (global vars come from styles.css) */
:root {
  --panel-bg:     rgba(255, 255, 255, 0.03);
  --panel-hover:  rgba(255, 107, 53, 0.05);
  --surface:      rgba(0, 0, 0, 0.6);
  --line-soft:    rgba(245, 240, 232, 0.06);
  --text:         #e8ebf3;
  --weak:         #687084;
  --cyan:         #66d9ef;
  --green:        #3ecf8e;
  --violet:       #b79cff;
  --gold:         #e6c15c;
  --red:          #ff7b7b;
}

/* Main layout — account for fixed topbar (topbar-h = 56px from styles.css) */
.app {
  height: 100vh;
  min-height: 820px;
  display: grid;
  grid-template-rows: 50px minmax(0, 1fr) 252px;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 8px;
  padding-top: calc(var(--topbar-h) + 8px);
  box-sizing: border-box;
  transition: grid-template-columns 0.3s ease, grid-template-rows 0.3s ease;
}

/* Layout Variations */
.app.term-collapsed {
  grid-template-rows: 50px 1fr 36px !important;
}

.app.term-left {
  grid-template-columns: 420px 1fr;
  grid-template-rows: 50px 1fr;
}
.app.term-left .workspace-toolbar { grid-column: 1 / span 2; }
.app.term-left .terminal-shell { grid-row: 2; grid-column: 1; }
.app.term-left .materials { grid-row: 2; grid-column: 2; }

.app.term-right {
  grid-template-columns: 1fr 420px;
  grid-template-rows: 50px 1fr;
}
.app.term-right .workspace-toolbar { grid-column: 1 / span 2; }
.app.term-right .terminal-shell { grid-row: 2; grid-column: 2; }
.app.term-right .materials { grid-row: 2; grid-column: 1; }

.app.term-floating {
  grid-template-rows: 50px 1fr;
  grid-template-columns: 1fr;
}

.app.term-left.term-collapsed { grid-template-columns: 42px 1fr !important; }
.app.term-right.term-collapsed { grid-template-columns: 1fr 42px !important; }

/* Terminal Shell States */
.terminal-shell { 
  display: grid; 
  grid-template-rows: 34px minmax(0, 1fr); 
  background: var(--bg); 
  z-index: 10;
  transition: all 0.2s ease;
}

.terminal-shell.collapsed {
  grid-template-rows: 34px 0px;
}
.terminal-shell.collapsed #terminal { display: none; }

.terminal-shell.floating {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 600px;
  height: 400px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  border-color: var(--cyan);
  resize: both;
}

.terminal-head {
  cursor: default;
  user-select: none;
}
.terminal-shell.floating .terminal-head {
  cursor: move;
}

.workspace-toolbar {
  position: relative;
  z-index: 1;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-bg);
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-sizing: border-box;
}
.panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-bg);
  overflow: hidden;
}
.search {
  height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  flex-shrink: 0;
}
.status { display: flex; justify-content: flex-end; gap: 7px; min-width: 0; }
.project-picker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.project-picker select {
  max-width: 220px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
}
.pill {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.pill.ok { color: var(--safe); border-color: rgba(62, 207, 142, .4); background: rgba(62, 207, 142, .1); }
.project-stats {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.materials {
  min-height: 0;
  display: grid;
  grid-template-rows: 46px minmax(0, 1fr);
  gap: 8px;
  margin-top: 4px;
}

.phase-tabs {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 8px;
}
.phase-tab {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--muted);
  padding: 0 12px;
  font-family: inherit;
  cursor: pointer;
}
.phase-tab strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--dim);
  font-size: 13px;
}
.phase-tab span {
  min-width: 28px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--bg);
  color: var(--weak);
  font-size: 12px;
}
.phase-tab.active {
  border-color: rgba(102, 217, 239, .5);
  background: rgba(102, 217, 239, .13);
}
.phase-tab.active strong { color: var(--cyan); }
.phase-tab.active span { color: var(--cyan); background: rgba(102, 217, 239, .14); }

.workspace-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 92px minmax(620px, 1fr) minmax(360px, .58fr);
  gap: 8px;
}

.rail {
  min-height: 0;
  display: grid;
  grid-auto-rows: minmax(64px, auto);
  align-content: start;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--panel-bg);
}
.rail-item {
  display: grid;
  place-items: center;
  min-height: 64px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.1;
  text-align: center;
  font-family: inherit;
  cursor: pointer;
}
.rail-item small { display: block; margin-top: 5px; color: var(--weak); font-size: 11px; }
.rail-item.active { border-color: rgba(102, 217, 239, .45); background: rgba(102, 217, 239, .14); color: var(--cyan); }

.panel-head, .terminal-head {
  height: 42px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.panel-head strong, .terminal-head strong { font-size: 13px; }
.panel-head span, .terminal-head span { color: var(--muted); font-size: 12px; white-space: nowrap; }

em, mark {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(102, 217, 239, .14);
  color: var(--cyan);
  font-size: 11px;
  font-style: normal;
  white-space: nowrap;
}
em.green, mark.green { background: rgba(103, 211, 145, .14); color: var(--green); }
em.red, mark.red { background: rgba(255, 123, 123, .14); color: var(--red); }
mark.violet { background: rgba(183, 156, 255, .16); color: var(--violet); }
mark.gold { background: rgba(230, 193, 92, .14); color: var(--gold); }

.main-panel, .table-panel { display: grid; grid-template-rows: 42px minmax(0, 1fr); }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: 13px; }
th { position: sticky; top: 0; z-index: 2; height: 38px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--surface); color: var(--dim); font-weight: 600; text-align: left; white-space: nowrap; }
td { height: 54px; padding: 10px 10px; border-bottom: 1px solid var(--line-soft); background: var(--bg); color: var(--muted); vertical-align: top; overflow: hidden; text-overflow: ellipsis; line-height: 1.5; }
tr:nth-child(2n) td { background: rgba(255,255,255,0.015); }
td:first-child { color: var(--fg); }
th:nth-child(1) { width: 190px; }
th:nth-child(2) { width: 126px; }
th:nth-child(3) { width: 210px; }
th:nth-child(5) { width: 138px; }
.main-row { cursor: pointer; }
.main-row:hover td { background: var(--panel-hover); }
.main-row.selected td { background: rgba(255, 107, 53, .08); }
.main-row td:first-child strong,
.main-row td:first-child span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.main-row td:first-child span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.empty {
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
}

.detail-panel {
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
}
.detail-body {
  min-height: 0;
  overflow: auto;
  padding: 12px;
}
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 9px;
}
.detail-meta span {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.detail-fields {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 1px;
  margin: 0 0 10px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  overflow: hidden;
}
.detail-fields dt,
.detail-fields dd {
  margin: 0;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
.detail-fields dt {
  color: var(--muted);
  background: var(--surface);
}
.detail-fields dd:nth-last-child(1),
.detail-fields dt:nth-last-child(2) { border-bottom: 0; }
.featured-media {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin: 0 0 12px;
}
.featured-card {
  min-height: 150px;
  max-height: 260px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
  cursor: zoom-in;
}
.featured-card img {
  width: 100%;
  height: 100%;
  min-height: 150px;
  object-fit: cover;
  display: block;
}
.featured-card.video {
  gap: 8px;
  padding: 14px;
  color: var(--muted);
  background: linear-gradient(140deg, #30384b, #171b25);
}
.featured-card.video span {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(102, 217, 239, .14);
  color: var(--cyan);
  font-size: 22px;
}
.featured-card.video small {
  max-width: 100%;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}
.markdown-body {
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--bg);
  color: #d6dbe7;
  font-size: 14px;
  line-height: 1.72;
}
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5 {
  margin: 16px 0 8px;
  color: #edf1f8;
  line-height: 1.35;
}
.markdown-body h2 { font-size: 18px; }
.markdown-body h3 { font-size: 16px; }
.markdown-body h4,
.markdown-body h5 { font-size: 15px; }
.markdown-body h2:first-child,
.markdown-body h3:first-child,
.markdown-body h4:first-child,
.markdown-body p:first-child,
.markdown-body pre:first-child { margin-top: 0; }
.markdown-body p {
  margin: 0 0 10px;
}
.markdown-body strong {
  color: #f2f5fb;
}
.markdown-body code {
  padding: 1px 5px;
  border: 1px solid rgba(232, 235, 243, .13);
  border-radius: 5px;
  background: #0b0f16;
  color: #dfe6f3;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .92em;
}
.markdown-body pre {
  margin: 10px 0;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  background: #0b0f16;
  overflow: auto;
}
.markdown-body pre code {
  padding: 0;
  border: 0;
  background: transparent;
  white-space: pre-wrap;
}
.markdown-body blockquote {
  margin: 10px 0;
  padding: 8px 10px;
  border-left: 3px solid rgba(102, 217, 239, .55);
  background: rgba(102, 217, 239, .08);
  color: #cdd6e5;
}
.markdown-body ul {
  margin: 8px 0 12px;
  padding-left: 20px;
}
.markdown-body li {
  margin: 3px 0;
}
.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--line-soft);
  margin: 14px 0;
}
.md-table-wrap {
  max-width: 100%;
  margin: 10px 0 14px;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
}
.md-table {
  min-width: 520px;
  font-size: 13px;
}
.md-table th {
  position: static;
  height: 34px;
  background: var(--panel-hover);
}
.md-table td {
  height: auto;
  padding: 9px 10px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.md-embed-image {
  width: 100%;
  max-height: 260px;
  display: block;
  object-fit: contain;
  margin: 8px 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #080b10;
  cursor: zoom-in;
}
.md-embed-video {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin: 6px 0 10px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(102, 217, 239, .13);
  color: var(--cyan);
  font-family: inherit;
  font-size: 13px;
  cursor: zoom-in;
}
.embed-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.detail-media {
  display: grid;
  place-items: center;
  min-height: 220px;
  margin-bottom: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--bg);
}
.detail-image {
  max-width: 100%;
  max-height: 360px;
  border-radius: 6px;
  object-fit: contain;
  cursor: zoom-in;
}
.detail-video,
.detail-audio {
  width: 120px;
  height: 120px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(140deg, #353b4e, #1b1e29);
  color: var(--muted);
  font-family: inherit;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}
.detail-video {
  cursor: zoom-in;
}
.inline-thumb {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
  margin-right: 4px;
  vertical-align: middle;
  background: var(--bg);
  cursor: zoom-in;
}
.media-token {
  display: inline-flex;
  align-items: center;
  height: 22px;
  margin-right: 4px;
  padding: 0 6px;
  border-radius: 5px;
  background: #222838;
  color: var(--muted);
  font-size: 10px;
  border: 0;
  font-family: inherit;
  cursor: default;
}
button.media-token { cursor: zoom-in; }

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}
.preview-modal.open { display: block; }
.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 11, .78);
  backdrop-filter: blur(10px);
}
.preview-window {
  position: absolute;
  inset: 6vh 5vw;
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr);
  border: 1px solid rgba(232, 235, 243, .18);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: 0 28px 80px rgba(0, 0, 0, .62);
  overflow: hidden;
}
.preview-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  align-items: center;
  gap: 10px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
}
.preview-head strong,
.preview-head span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-head strong { font-size: 13px; }
.preview-head span { color: var(--muted); font-size: 11px; margin-top: 2px; }
.preview-close {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.preview-body {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  background: #090c12;
}
.preview-body img,
.preview-body video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  background: #05070a;
  box-shadow: 0 16px 50px rgba(0, 0, 0, .44);
}
.preview-body video {
  width: min(100%, 1280px);
  height: auto;
}

.terminal-shell { display: grid; grid-template-rows: 34px minmax(0, 1fr); background: var(--bg); }
.terminal-head {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}
.terminal-head strong { font-size: 13px; flex-shrink: 0; }
.terminal-head span { 
  color: var(--muted); 
  font-size: 11px; 
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis;
  min-width: 0;
}
.terminal-controls { 
  display: flex; 
  align-items: center; 
  gap: 4px; 
  flex-shrink: 0;
}

/* Hide subtitle and simplify status when docked to side and narrow */
.app.term-left .terminal-head span,
.app.term-right .terminal-head span {
  display: none;
}
.app.term-left .term-status,
.app.term-right .term-status {
  width: 8px;
  height: 8px;
  padding: 0;
  font-size: 0;
  border-radius: 50%;
  min-width: 0;
}
.term-status {
  height: 22px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid rgba(104, 112, 132, .30);
  background: rgba(104, 112, 132, .15);
  color: var(--weak);
  font-size: 11px;
  white-space: nowrap;
  transition: color .15s, background .15s, border-color .15s;
}
.term-status.ok {
  color: var(--green);
  border-color: rgba(103, 211, 145, .40);
  background: rgba(103, 211, 145, .12);
}
.term-status.err {
  color: var(--red);
  border-color: rgba(255, 123, 123, .40);
  background: rgba(255, 123, 123, .12);
}
.term-btn {
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .1s, background .1s, border-color .1s;
}
.term-btn:hover { background: rgba(102, 217, 239, .10); color: var(--cyan); border-color: rgba(102, 217, 239, .45); }
.term-btn:active { background: rgba(102, 217, 239, .18); }
#terminal { min-height: 0; height: 100%; padding: 4px; }
#terminal .xterm { height: 100%; }
#terminal:focus { outline: 1px solid rgba(103, 211, 145, .36); outline-offset: -1px; }
#terminal .xterm-helper-textarea { opacity: 0; }

@media (max-width: 1280px) {
  .topbar { height: auto; padding: 8px 10px; }
  .workspace-toolbar { grid-template-columns: 1fr; height: auto; padding: 8px 10px; }
  .phase-tabs { grid-template-columns: repeat(3, minmax(100px, 1fr)); }
  .workspace-grid { grid-template-columns: 76px minmax(500px, 1fr); }
  .detail-panel { display: none; }
}
