/* ---- Reset & Base ---- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --paper: #FAFAF7;
  --ink: #1A1A1A;
  --ember: #D4580A;
  --dust: #7A6E5E;
  --sand: #C4B9A8;
  --chalk: #E8E4DD;
  --sans: 'Space Grotesk', system-ui, sans-serif;
  --mono: 'Space Mono', 'Courier New', monospace;

  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
}

html {
  font-size: 18px;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.78rem;
  line-height: 1.5;
  min-height: 100vh;
}


/* ---- Layout ---- */
#layout {
  display: flex;
  min-height: 100vh;
}


/* ---- Sidebar ---- */
#sidebar {
  width: 168px;
  flex-shrink: 0;
  background: #f0ede7;
  border-right: 1px solid var(--chalk);
  padding: 14px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
}

.sidebar-brand {
  font-family: var(--mono);
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ember);
  padding: 0 12px 10px;
}

.sidebar-sep {
  height: 1px;
  background: var(--chalk);
  margin: 6px 0;
}

.sidebar-section {
  font-family: var(--mono);
  font-size: 0.4rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sand);
  padding: 6px 12px 2px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  font-size: 0.7rem;
  color: var(--dust);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s;
}

.sidebar-item:hover {
  background: rgba(212,88,10,0.04);
}

.sidebar-item.active {
  background: rgba(212,88,10,0.08);
  color: var(--ink);
  font-weight: 600;
}

.s-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.s-dot-running {
  background: var(--green);
  box-shadow: 0 0 5px rgba(22,163,74,0.4);
}

.s-dot-idle {
  background: transparent;
  border: 1.5px solid var(--ember);
  width: 6px;
  height: 6px;
}

.s-dot-off {
  background: var(--sand);
}

.s-dot-error {
  background: var(--red);
}

.s-icon {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--sand);
  width: 6px;
  text-align: center;
}

.sidebar-bot-model {
  font-family: var(--mono);
  font-size: 0.45rem;
  color: var(--sand);
  margin-left: auto;
  letter-spacing: 0.04em;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(22,163,74,0.4); }
  50%       { box-shadow: 0 0 0 5px transparent; }
}

.s-dot-running {
  animation: pulse-dot 2s infinite;
}


/* ---- Main content ---- */
#main {
  flex: 1;
  margin-left: 168px;
  padding: 18px 20px;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.page-title {
  font-family: var(--sans);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.page-meta {
  font-family: var(--mono);
  font-size: 0.5rem;
  color: var(--sand);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.section-label {
  font-family: var(--mono);
  font-size: 0.48rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sand);
  margin: 20px 0 8px;
}


/* ---- Bot Card Grid ---- */
.bot-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.bot-card {
  background: white;
  border: 1px solid var(--chalk);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.1s;
}

.bot-card:hover {
  background: #fafaf7;
}

.bot-card-running {
  border-color: rgba(22,163,74,0.3);
  background: #fafffe;
}

.bot-card-error {
  border-color: rgba(220,38,38,0.3);
}

.bc-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.bc-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bc-name {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink);
}

.bc-model {
  font-family: var(--mono);
  font-size: 0.42rem;
  color: var(--sand);
  margin-left: auto;
  letter-spacing: 0.04em;
}

.bc-stat {
  font-family: var(--mono);
  font-size: 0.48rem;
  color: var(--dust);
  margin-bottom: 2px;
}

.bc-cost {
  font-family: var(--mono);
  font-size: 0.48rem;
  color: var(--sand);
}

.bc-actions {
  margin-top: 6px;
  display: flex;
  gap: 4px;
}


/* ---- Session Table ---- */
.session-table {
  background: white;
  border: 1px solid var(--chalk);
  border-radius: 6px;
  overflow: hidden;
}

.session-head {
  display: grid;
  grid-template-columns: 100px 60px 70px 60px 80px;
  gap: 0;
  padding: 6px 12px;
  background: #f7f4ef;
  border-bottom: 1px solid var(--chalk);
}

.session-head span {
  font-family: var(--mono);
  font-size: 0.42rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sand);
}

.session-row {
  display: grid;
  grid-template-columns: 100px 60px 70px 60px 80px;
  gap: 0;
  padding: 7px 12px;
  border-bottom: 1px solid var(--chalk);
  align-items: center;
  cursor: pointer;
  transition: background 0.1s;
  text-decoration: none;
}

.session-row:last-child {
  border-bottom: none;
}

.session-row:hover {
  background: #fafaf7;
}

.session-row-running {
  background: #f7fffe;
}

.sr-bot {
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sr-time,
.sr-dur {
  font-family: var(--mono);
  font-size: 0.55rem;
  color: var(--dust);
}

.sr-cost {
  font-family: var(--mono);
  font-size: 0.55rem;
  color: var(--dust);
}

.sr-stop {
  font-family: var(--mono);
  font-size: 0.48rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 5px;
  border-radius: 3px;
  display: inline-block;
}

.stop-end {
  background: rgba(22,163,74,0.08);
  color: #15803d;
}

.stop-error {
  background: rgba(220,38,38,0.08);
  color: #dc2626;
}

.stop-running {
  background: rgba(22,163,74,0.08);
  color: var(--green);
}

.stop-max-tokens {
  background: rgba(217,119,6,0.08);
  color: var(--amber);
}


/* ---- Bot Detail ---- */
.detail-cols {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  align-items: start;
}

.detail-section-label {
  font-family: var(--mono);
  font-size: 0.45rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sand);
  margin-bottom: 6px;
}

.config-panel {
  background: white;
  border: 1px solid var(--chalk);
  border-radius: 6px;
  overflow: hidden;
}

.config-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid var(--chalk);
  font-size: 0.65rem;
}

.config-row:last-child {
  border-bottom: none;
}

.config-label {
  font-family: var(--mono);
  font-size: 0.45rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sand);
}

.config-value {
  font-family: var(--mono);
  font-size: 0.55rem;
  color: var(--ink);
}

/* Schedule card */
.schedule-card {
  background: white;
  border: 1px solid var(--chalk);
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 8px;
}

.schedule-cron {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 3px;
}

.schedule-desc {
  font-family: var(--sans);
  font-size: 0.65rem;
  color: var(--dust);
  margin-bottom: 6px;
}

.schedule-next {
  font-family: var(--mono);
  font-size: 0.48rem;
  color: var(--sand);
}

/* MCP list */
.mcp-list {
  background: white;
  border: 1px solid var(--chalk);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 8px;
}

.mcp-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  font-family: var(--sans);
  font-size: 0.65rem;
  color: var(--dust);
  border-bottom: 1px solid var(--chalk);
}

.mcp-item:last-child {
  border-bottom: none;
}

.mcp-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

/* Session list (bot detail) */
.session-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: white;
  border: 1px solid var(--chalk);
  border-radius: 6px;
  overflow: hidden;
}

.session-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--chalk);
  cursor: pointer;
  transition: background 0.1s;
  text-decoration: none;
  display: block;
  color: inherit;
}

.session-item:last-child {
  border-bottom: none;
}

.session-item:hover {
  background: #fafaf7;
}

.session-item-live {
  background: #f7fffe;
  border-left: 3px solid var(--green);
}

.session-item-error {
  border-left: 3px solid var(--red);
}

.si-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.si-time {
  font-family: var(--mono);
  font-size: 0.52rem;
  color: var(--dust);
}

.si-stop {
  font-family: var(--mono);
  font-size: 0.45rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 5px;
  border-radius: 3px;
  margin-left: auto;
}

.si-prompt {
  font-family: var(--sans);
  font-size: 0.68rem;
  color: var(--ink);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.si-stats {
  font-family: var(--mono);
  font-size: 0.48rem;
  color: var(--sand);
}


/* ---- Stats Bar ---- */
.stats-bar {
  display: flex;
  gap: 0;
  background: white;
  border: 1px solid var(--chalk);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 16px;
}

.stat-item {
  flex: 1;
  padding: 8px 12px;
  border-right: 1px solid var(--chalk);
  min-width: 0;
}

.stat-item:last-child {
  border-right: none;
}

.stat-label {
  font-family: var(--mono);
  font-size: 0.42rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sand);
  margin-bottom: 3px;
}

.stat-val {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--ink);
}

.stat-cost {
  color: var(--ember);
}

.stat-end {
  color: #15803d;
  font-size: 0.5rem;
}


/* ---- Session Viewer ---- */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

.bc-link {
  font-family: var(--mono);
  font-size: 0.55rem;
  color: var(--ember);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

.bc-link:hover {
  text-decoration: underline;
}

.bc-sep {
  font-size: 0.6rem;
  color: var(--sand);
}

.bc-current {
  font-family: var(--mono);
  font-size: 0.55rem;
  color: var(--dust);
}

/* Conversation thread */
.thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thread-label {
  font-family: var(--mono);
  font-size: 0.45rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sand);
  padding-top: 8px;
}

.msg {
  background: white;
  border: 1px solid var(--chalk);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--ink);
  position: relative;
}

.msg-user {
  background: #f0ede7;
  border-color: var(--chalk);
  font-style: italic;
  color: var(--dust);
}

.msg-label {
  display: block;
  font-family: var(--mono);
  font-size: 0.42rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sand);
  margin-bottom: 6px;
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-text code {
  font-family: var(--mono);
  font-size: 0.65rem;
  background: #f7f4ef;
  padding: 1px 4px;
  border-radius: 3px;
}

.msg-text pre {
  background: #f7f4ef;
  padding: 8px 10px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 6px 0;
  font-family: var(--mono);
  font-size: 0.6rem;
}

/* Tool calls */
.tool-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tool-call {
  background: white;
  border: 1px solid var(--chalk);
  border-left: 3px solid var(--chalk);
  border-radius: 0 6px 6px 0;
  overflow: hidden;
}

.tool-call-expanded {
  border-left-color: var(--ember);
}

.tool-call-error {
  border-left-color: var(--red);
}

.tool-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  user-select: none;
}

.tool-header:hover {
  background: #fafaf7;
}

.tool-name {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--ink);
}

.tool-server {
  font-family: var(--mono);
  font-size: 0.45rem;
  color: var(--sand);
  background: var(--chalk);
  padding: 1px 5px;
  border-radius: 3px;
}

.tool-toggle {
  font-size: 0.55rem;
  color: var(--sand);
  margin-left: auto;
  transition: transform 0.15s;
}

.tool-toggle-open {
  transform: rotate(180deg);
}

.tool-body {
  padding: 0 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  transition: max-height 0.15s ease-out;
}

.tool-body-collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
}

.tool-io-label {
  font-family: var(--mono);
  font-size: 0.42rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sand);
  margin-bottom: 4px;
}

.tool-io-content {
  font-family: var(--mono);
  font-size: 0.52rem;
  color: var(--dust);
  background: #f7f4ef;
  padding: 6px 8px;
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
}

.tool-io-error {
  color: var(--red);
  background: rgba(220,38,38,0.04);
}

.tool-show-more {
  font-family: var(--mono);
  font-size: 0.45rem;
  color: var(--ember);
  cursor: pointer;
  margin-top: 2px;
}

/* Session footer */
.session-footer {
  position: sticky;
  bottom: 0;
  background: var(--paper);
  border-top: 1px solid var(--chalk);
  padding: 8px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}

.token-bar {
  height: 3px;
  background: var(--chalk);
  border-radius: 2px;
  flex: 1;
  max-width: 200px;
  margin-left: 12px;
}

.token-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.token-bar-fill-warn {
  background: var(--amber);
}

.token-bar-fill-crit {
  background: var(--red);
}

.token-label {
  font-family: var(--mono);
  font-size: 0.45rem;
  color: var(--sand);
  margin-left: 8px;
}


/* ---- Cost View ---- */
.cost-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.cost-panel {
  background: white;
  border: 1px solid var(--chalk);
  border-radius: 6px;
  padding: 12px;
}

.cost-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--chalk);
  font-size: 0.65rem;
}

.cost-row:last-child {
  border-bottom: none;
}

.cost-name {
  font-family: var(--sans);
  font-weight: 500;
  color: var(--ink);
}

.cost-value {
  font-family: var(--mono);
  font-size: 0.55rem;
  color: var(--ember);
  font-weight: 700;
}

.cost-bar {
  height: 3px;
  background: var(--chalk);
  border-radius: 2px;
  flex: 1;
  margin: 0 10px;
  max-width: 120px;
}

.cost-bar-fill {
  height: 100%;
  background: var(--ember);
  border-radius: 2px;
}

.period-picker {
  display: flex;
  gap: 0;
  background: rgba(0,0,0,0.04);
  border-radius: 5px;
  padding: 2px;
  margin-bottom: 16px;
}

.period-btn {
  font-family: var(--mono);
  font-size: 0.48rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 3px;
  color: var(--dust);
  border: none;
  background: none;
  cursor: pointer;
}

.period-btn-active {
  background: white;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}


/* ---- Settings View ---- */
.settings-table {
  background: white;
  border: 1px solid var(--chalk);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 16px;
}

.settings-row {
  display: grid;
  grid-template-columns: 100px 140px 1fr 60px;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--chalk);
  align-items: center;
  font-size: 0.65rem;
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-bot {
  font-family: var(--sans);
  font-weight: 600;
  color: var(--ink);
}

.settings-cron {
  font-family: var(--mono);
  font-size: 0.52rem;
  color: var(--dust);
}

.settings-prompt {
  font-family: var(--sans);
  font-size: 0.62rem;
  color: var(--dust);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.key-status {
  font-family: var(--mono);
  font-size: 0.48rem;
  font-weight: 700;
}

.key-set {
  color: var(--green);
}

.key-missing {
  color: var(--red);
}


/* ---- Buttons ---- */
.btn {
  font-family: var(--mono);
  font-size: 0.48rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 5px;
  border: 1px solid;
  cursor: pointer;
  transition: background 0.1s;
}

.btn-primary {
  border-color: var(--ember);
  color: var(--ember);
  background: transparent;
}

.btn-primary:hover {
  background: rgba(212,88,10,0.06);
}

.btn-secondary {
  border-color: var(--chalk);
  color: var(--dust);
  background: transparent;
}

.btn-secondary:hover {
  background: rgba(0,0,0,0.02);
}

.btn-danger {
  border-color: var(--red);
  color: var(--red);
  background: transparent;
}

.btn-danger:hover {
  background: rgba(220,38,38,0.04);
}

.btn-sm {
  padding: 3px 7px;
  font-size: 0.42rem;
}


/* ---- Toggle Switch ---- */
.toggle {
  width: 30px;
  height: 17px;
  border-radius: 9px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
  cursor: pointer;
  border: none;
}

.toggle-on {
  background: var(--ember);
}

.toggle-off {
  background: var(--chalk);
}

.toggle-knob {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: white;
  position: absolute;
  top: 2px;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle-on .toggle-knob {
  left: 15px;
}

.toggle-off .toggle-knob {
  left: 2px;
}


/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.15);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: white;
  border: 1px solid var(--chalk);
  border-radius: 8px;
  padding: 20px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}

.modal-title {
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 16px;
}

.modal-label {
  font-family: var(--mono);
  font-size: 0.45rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sand);
  display: block;
  margin-bottom: 4px;
  margin-top: 10px;
}

.modal-select {
  width: 100%;
  font-family: var(--sans);
  font-size: 0.72rem;
  padding: 6px 10px;
  border: 1px solid var(--chalk);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
}

.modal-select:focus {
  border-color: var(--ember);
}

.modal-textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.6rem;
  padding: 8px 10px;
  border: 1px solid var(--chalk);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  resize: vertical;
  outline: none;
  line-height: 1.5;
}

.modal-textarea:focus {
  border-color: var(--ember);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}


/* ---- Utilities ---- */
.text-muted {
  color: var(--sand);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.text-ember {
  color: var(--ember);
}

.text-green {
  color: var(--green);
}

.text-red {
  color: var(--red);
}

.hidden {
  display: none !important;
}

.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--sand);
  font-family: var(--mono);
  font-size: 0.55rem;
}

.fade-in {
  animation: fadeIn 120ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}


/* ---- Responsive ---- */
@media (max-width: 640px) {
  .bot-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .session-head,
  .session-row {
    grid-template-columns: 80px 50px 60px 50px 70px;
  }

  .detail-cols {
    grid-template-columns: 1fr;
  }

  .cost-cols {
    grid-template-columns: 1fr;
  }

  .stats-bar {
    flex-wrap: wrap;
  }

  .stat-item {
    min-width: 80px;
  }

  #sidebar {
    width: 140px;
  }

  #main {
    margin-left: 140px;
  }
}
