* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0a0e14;
  --card: #131920;
  --border: #1e2832;
  --text: #d4d4d4;
  --text-dim: #6b7280;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
  --blue: #3b82f6;
  --glow-green: 0 0 10px rgba(16,185,129,0.5);
  --glow-red: 0 0 10px rgba(239,68,68,0.3);
}
html, body {
  height: 100%;
  overflow: hidden;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: row;
}
.main-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
header h1 { font-size: 1.2rem; font-weight: 600; color: var(--green); }
.header-actions { display: flex; gap: 0.4rem; }
.btn-icon {
  width: 26px; height: 26px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-icon:not(:disabled):hover { border-color: var(--green); color: var(--green); }
.btn-login {
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
}
.btn-login:hover { border-color: var(--blue); color: var(--blue); }
.btn-login.active { background: var(--green); color: var(--bg); border-color: var(--green); }

/* AI Status Indicator */
.ai-indicator {
  font-size: 1rem;
  margin-right: 0.5rem;
  cursor: help;
  transition: color 0.3s;
}
.ai-indicator.offline { color: var(--red); }
.ai-indicator.online { color: var(--green); }
.ai-indicator.busy { color: var(--yellow); animation: pulse 1s infinite; }
.ai-indicator.checking { color: var(--text-dim); }

main {
  flex: 1;
  display: flex;
  gap: 0.3rem;
  padding: 0.3rem;
  min-height: 0;
  overflow: hidden;
}
.vm {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  min-width: 280px;
  min-height: 0;
  overflow: hidden;
}
.vm-header {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
  flex-shrink: 0;
}
.vm-name { font-weight: 700; font-size: 0.8rem; color: var(--green); letter-spacing: 1px; }
.vm-stats { display: flex; gap: 4px; }
.vm-stats .vm-metric { width: 70px; height: 20px; }
.services {
  flex: 1;
  overflow-y: auto;
  padding: 0.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* TIER Groups */
.tier-group {
  background: rgba(30,30,30,0.5);
  border-radius: 8px;
  padding: 0.4rem;
  border: 1px solid var(--border);
}
.tier-group.collapsed .tier-services,
.tier-group.collapsed .tier-metrics {
  display: none;
}
.tier-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.4rem;
  margin-bottom: 0.3rem;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
}
.tier-header:hover {
  background: rgba(255,255,255,0.05);
}
.tier-chevron {
  font-size: 0.6rem;
  color: var(--text-dim);
  width: 12px;
}
.tier-name {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.tier-desc {
  font-size: 0.65rem;
  color: var(--green);
  font-weight: 400;
}
.tier-count {
  font-size: 0.6rem;
  color: var(--text-dim);
  background: rgba(255,255,255,0.1);
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
  margin-left: auto;
}
.sort-tags {
  display: flex;
  gap: 4px;
  margin-left: 0.5rem;
}
.sort-tag {
  font-size: 0.55rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: rgba(255,255,255,0.08);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.sort-tag:hover {
  background: rgba(255,255,255,0.15);
  color: var(--text);
}
.sort-tag.active {
  background: var(--green);
  color: var(--bg);
  font-weight: 600;
}
.tier-metrics {
  display: flex;
  gap: 4px;
  padding: 0.2rem 0.4rem;
  margin-bottom: 0.3rem;
}
.tier-metrics .tier-metric { width: 70px; height: 20px; }
.tier-services {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

/* Service card - original grid layout */
.service {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 0.4rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  transition: all 0.2s;
  flex-shrink: 0;
}
.service.running { border-color: var(--green); box-shadow: var(--glow-green); }
.service.stopped { border-color: var(--border); opacity: 0.7; }
.service.progress { border-color: var(--yellow); box-shadow: 0 0 8px rgba(245,158,11,0.4); }

/* Top-left: Name */
.service-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}
.service-name {
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

/* Top-right: Buttons */
.service-buttons {
  display: flex;
  gap: 3px;
  justify-content: flex-end;
}

/* Bottom-left: Stats with timeline component */
.service-stats {
  display: flex;
  flex-direction: row;
  gap: 4px;
}

/* Metric Timeline Component - unified for CPU, RAM, SSD */
.metric-timeline {
  flex: 1;
  height: 22px;
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}
.metric-timeline canvas {
  position: absolute;
  left: 0; top: 0;
  width: 100%;
  height: 100%;
  border-radius: 5px;
}
.metric-label {
  position: absolute;
  left: 5px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.5rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  z-index: 2;
  letter-spacing: 0.5px;
}
.metric-val {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.5rem;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  z-index: 2;
}

/* Bottom-right: Status */
.service-status {
  font-size: 0.6rem;
  text-align: right;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.service-status.running { color: var(--green); }
.service-status.stopped { color: var(--red); }
.service-status.progress { color: var(--yellow); }
/* Buttons */
.service-buttons {
  display: flex;
  gap: 3px;
  justify-content: flex-end;
}
.service-buttons button {
  width: 24px; height: 24px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

/* Bottom-right: Status */
.service-status {
  font-size: 0.65rem;
  text-align: right;
  padding: 3px 6px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.service-status.running { color: var(--green); }
.service-status.stopped { color: var(--red); }
.service-status.progress { color: var(--yellow); }
.service-buttons button.play { color: var(--green); border-color: rgba(16,185,129,0.4); }
.service-buttons button.stop { color: var(--red); border-color: rgba(239,68,68,0.4); }
.service-buttons button.restart { color: var(--yellow); border-color: rgba(245,158,11,0.4); }
.service-buttons button.delete { color: var(--red); border-color: rgba(239,68,68,0.4); font-size: 0.65rem; }

.service-buttons button:hover:not(:disabled) { 
  transform: scale(1.1);
}
.service-buttons button.play:hover:not(:disabled) { 
  background: var(--green); 
  border-color: var(--green);
  color: var(--bg);
  box-shadow: 0 0 8px var(--green);
}
.service-buttons button.stop:hover:not(:disabled) { 
  background: var(--red); 
  border-color: var(--red);
  color: white;
  box-shadow: 0 0 8px var(--red);
}
.service-buttons button.restart:hover:not(:disabled) { 
  background: var(--yellow); 
  border-color: var(--yellow);
  color: var(--bg);
  box-shadow: 0 0 8px var(--yellow);
}
.service-buttons button.delete:hover:not(:disabled) { 
  background: var(--red); 
  border-color: var(--red);
  color: white;
  box-shadow: 0 0 8px var(--red);
}
.service-buttons button:disabled { 
  opacity: 0.2; 
  cursor: not-allowed; 
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
  transform: none;
}

/* Modal */
.modal {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 90%;
  max-width: 360px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-content.small { max-width: 260px; }
.modal-content.modal-installer { max-width: 420px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 0.9rem; }
.btn-close { background: none; border: none; color: var(--text-dim); font-size: 1.2rem; cursor: pointer; }
.modal-body {
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.7rem;
  color: var(--text-dim);
}
.modal-body input, .modal-body select {
  padding: 0.35rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 4px;
  font-size: 0.75rem;
}
.radio-group { display: flex; gap: 0.8rem; font-size: 0.7rem; color: var(--text); padding-top: 0.2rem; }
.form-row { display: flex; gap: 0.5rem; }
.form-row label { flex: 1; }
.preview { font-size: 0.7rem; color: var(--green); font-family: monospace; margin: 0.3rem 0; }

/* AI Chat */
.ai-chat {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 0.5rem;
  overflow: hidden;
}
.ai-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background: var(--border);
  font-size: 0.7rem;
}
.btn-validate {
  padding: 0.2rem 0.5rem;
  background: var(--blue);
  border: none;
  border-radius: 3px;
  color: white;
  font-size: 0.65rem;
  cursor: pointer;
}
.btn-validate:hover { opacity: 0.8; }
.ai-chat-messages {
  height: 120px;
  overflow-y: auto;
  padding: 0.4rem;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.ai-msg {
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  font-size: 0.65rem;
  max-width: 85%;
  line-height: 1.3;
}
.ai-msg.ai {
  background: var(--card);
  border: 1px solid var(--border);
  align-self: flex-start;
}
.ai-msg.user {
  background: var(--blue);
  color: white;
  align-self: flex-end;
}
.ai-msg.system {
  background: var(--green);
  color: var(--bg);
  align-self: center;
  font-weight: 600;
}
.ai-msg.error {
  background: var(--red);
  color: white;
  align-self: center;
}
.ai-chat-input {
  display: flex;
  gap: 0.3rem;
  padding: 0.4rem;
  border-top: 1px solid var(--border);
}
.ai-chat-input input {
  flex: 1;
  padding: 0.3rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 3px;
  font-size: 0.7rem;
}
.ai-chat-input button {
  padding: 0.3rem 0.6rem;
  background: var(--green);
  border: none;
  border-radius: 3px;
  color: var(--bg);
  font-size: 0.65rem;
  cursor: pointer;
}
.modal-footer {
  padding: 0.5rem 0.8rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}
.modal-footer button {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
}
.modal-footer button:last-child { background: var(--green); color: var(--bg); border-color: var(--green); }
.modal-footer button:last-child:disabled { background: var(--border); border-color: var(--border); color: var(--text-dim); }

/* Installer form */
.hint { font-size: 0.6rem; color: var(--text-dim); margin-left: 0.3rem; }
.field-status { font-size: 0.65rem; margin-left: 0.3rem; }
.field-status.ok { color: var(--green); }
.field-status.error { color: var(--red); }
.modal-body textarea { 
  width: 100%; 
  padding: 0.35rem; 
  border: 1px solid var(--border); 
  background: var(--bg); 
  color: var(--text); 
  border-radius: 4px; 
  font-size: 0.75rem; 
  resize: vertical;
  font-family: inherit;
}
.install-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  margin-top: 0.5rem;
}
.preview-label { font-size: 0.65rem; color: var(--text-dim); }
.install-preview code { 
  display: block;
  font-size: 0.7rem; 
  color: var(--green); 
  margin-top: 0.2rem;
  word-break: break-all;
}

/* AI Response */
.ai-response {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 0.3rem;
  overflow: hidden;
}
.ai-response-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background: var(--border);
  font-size: 0.7rem;
}
.ai-options {
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 120px;
  overflow-y: auto;
}
.ai-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.15s;
}
.ai-option:hover { border-color: var(--blue); }
.ai-option.selected { border-color: var(--green); background: rgba(16,185,129,0.1); }
.ai-option code { color: var(--blue); }
.ai-option .select-btn { 
  padding: 0.15rem 0.4rem;
  background: var(--green);
  border: none;
  border-radius: 3px;
  color: var(--bg);
  font-size: 0.6rem;
  cursor: pointer;
}
.ai-selected {
  padding: 0.4rem;
  font-size: 0.7rem;
  color: var(--green);
  text-align: center;
}
.ai-loading {
  padding: 0.6rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.7rem;
}

/* Chat Sidebar Tab */
.chat-sidebar {
  display: flex;
  flex-shrink: 0;
  height: 100%;
}
.chat-tab {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 0.5rem 0.3rem;
  cursor: pointer;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.chat-tab:hover {
  background: var(--border);
}
.chat-panel {
  width: 0;
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s ease;
  position: relative;
}
.chat-sidebar.open .chat-panel {
  width: 400px;
}
.chat-sidebar.resizing .chat-panel {
  transition: none;
}
.chat-resize {
  position: absolute;
  left: 0;
  top: 0;
  width: 5px;
  height: 100%;
  cursor: ew-resize;
  background: transparent;
  z-index: 10;
}
.chat-resize:hover {
  background: var(--blue);
}
.chat-sidebar.open .chat-tab {
  display: none;
}
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.8rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  min-height: 36px;
}
.chat-selects {
  display: flex;
  gap: 0.3rem;
  flex: 1;
}
.chat-header select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.2rem 0.3rem;
  font-size: 0.65rem;
  cursor: pointer;
  max-width: 90px;
}
.chat-header select:disabled {
  opacity: 0.5;
  cursor: wait;
}
.chat-voice-controls {
  display: flex;
  gap: 0.3rem;
  padding: 0.4rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}
.voice-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
}
.voice-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.voice-btn:not(:disabled):hover {
  border-color: var(--green);
}
.voice-btn.active {
  background: var(--green);
  border-color: var(--green);
}
.voice-btn.recording {
  background: var(--red);
  border-color: var(--red);
  animation: pulse 1s infinite;
}
.chat-header .btn-close {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.3rem;
}
.chat-header .btn-close:hover {
  color: var(--red);
}
/* Chat messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: #0d0d0d;
}
.chat-msg {
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  max-width: 85%;
  font-size: 0.8rem;
  line-height: 1.4;
  word-wrap: break-word;
}
.chat-user {
  background: var(--green);
  color: #000;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}
.chat-assistant {
  background: var(--surface);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}
.chat-system {
  background: transparent;
  color: var(--text-dim);
  font-size: 0.7rem;
  text-align: center;
  align-self: center;
  font-style: italic;
}
.chat-error {
  background: rgba(239,68,68,0.2);
  color: var(--red);
  align-self: center;
  font-size: 0.7rem;
}
.chat-input-row {
  display: flex;
  gap: 0.3rem;
  padding: 0.4rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.chat-input-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem;
  color: var(--text);
  font-size: 0.8rem;
}
.chat-input-row input:focus {
  outline: none;
  border-color: var(--green);
}
.btn-send {
  background: var(--green);
  border: none;
  border-radius: 4px;
  width: 36px;
  cursor: pointer;
  font-size: 1rem;
}
.btn-send:hover {
  opacity: 0.8;
}
.voice-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}
.voice-chat-btn svg {
  color: var(--text);
}
.voice-chat-btn.active {
  background: var(--green);
}
.voice-chat-btn.active svg {
  color: #000;
}

/* Responsive - stack vertical on small screens */
@media (max-width: 768px) {
  body {
    flex-direction: column;
  }
  main {
    flex-direction: column;
  }
  .vm {
    flex: none;
    height: 33%;
  }
  .chat-sidebar {
    position: fixed;
    bottom: 0;
    right: 0;
    top: auto;
    transform: none;
    height: auto;
  }
  .chat-sidebar.open .chat-panel {
    width: 100vw;
    height: 50vh;
  }
  .chat-tab {
    writing-mode: horizontal-tb;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 8px 8px 0 0;
  }
}
