* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: system-ui, sans-serif; }
body { display: flex; }

.login-page { justify-content: center; align-items: center; background: #f5f5f5; }
.login-box {
  background: white; padding: 2rem; border-radius: 8px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.1); display: flex; flex-direction: column; gap: 1rem;
  min-width: 320px;
}
.login-box h1 { margin: 0; font-size: 1.4rem; }
.login-box label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.9rem; }
.login-box input { padding: 0.5rem; font-size: 1rem; border: 1px solid #ccc; border-radius: 4px; }
.login-box button { padding: 0.6rem; font-size: 1rem; background: #2962ff; color: white; border: none; border-radius: 4px; cursor: pointer; }
.login-box button:hover { background: #1e4dd0; }
.error { color: #c00; margin: 0; font-size: 0.9rem; }

#sidebar { width: 260px; background: #fafafa; border-right: 1px solid #e0e0e0; display: flex; flex-direction: column; padding: 0.75rem; }
.sidebar-header { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.75rem; }
.sidebar-header button { padding: 0.5rem; cursor: pointer; }
#conversation-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
#conversation-list li { padding: 0.5rem; border-radius: 4px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
#conversation-list li:hover { background: #eee; }
#conversation-list li.active { background: #e3f2fd; }
#conversation-list li .delete-btn { display: none; color: #c00; background: none; border: none; cursor: pointer; }
#conversation-list li:hover .delete-btn { display: inline; }
#logout-btn { padding: 0.5rem; cursor: pointer; }

#chat-pane { flex: 1; display: flex; flex-direction: column; }
#chat-header { padding: 0.75rem 1rem; border-bottom: 1px solid #e0e0e0; }
#chat-header h2 { margin: 0; font-size: 1.1rem; }
#messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.8rem; }
.msg { padding: 0.6rem 0.8rem; border-radius: 8px; max-width: 720px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { background: #e3f2fd; align-self: flex-end; }
.msg.assistant { background: #f5f5f5; align-self: flex-start; }
#chat-form { padding: 0.75rem; border-top: 1px solid #e0e0e0; display: flex; gap: 0.5rem; }
#chat-input { flex: 1; resize: vertical; min-height: 44px; padding: 0.5rem; font-family: inherit; font-size: 1rem; border: 1px solid #ccc; border-radius: 4px; }
#send-btn { padding: 0.5rem 1rem; cursor: pointer; }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.metrics-page { display: flex; flex-direction: column; height: 100vh; }
.metrics-header {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.75rem 1rem; border-bottom: 1px solid #e0e0e0; background: #fafafa;
}
.metrics-header h1 { margin: 0; font-size: 1.2rem; }
.metrics-header #m-uptime { color: #666; font-size: 0.9rem; flex: 1; }
.metrics-header .live-indicator { color: #ccc; font-size: 1.5rem; transition: color 0.2s; }
.metrics-header .live-indicator.active { color: #4caf50; }
.metrics-header #m-close { background: none; border: 1px solid #ccc; padding: 0.3rem 0.6rem; cursor: pointer; border-radius: 4px; }

#metrics-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem; padding: 1rem; flex: 1; overflow-y: auto;
}
.card {
  background: white; border: 1px solid #e0e0e0; border-radius: 8px;
  padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem;
}
.card h2 { margin: 0 0 0.3rem; font-size: 1rem; color: #555; }
.big-value { font-size: 2rem; font-weight: 600; }
.bar { background: #eee; height: 8px; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; transition: width 0.3s, background 0.3s; }
.bar-fill.ok { background: #4caf50; }
.bar-fill.warn { background: #ff9800; }
.bar-fill.crit { background: #f44336; }
.small { font-size: 0.85rem; color: #666; }

.disk-list, .net-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.disk-list li { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.3rem; border-radius: 4px; font-size: 0.9rem; }
.disk-list li.warn { background: #fff3e0; }
.disk-list li.crit { background: #ffebee; }
.disk-mount { font-family: monospace; }
.net-list li { display: flex; gap: 1rem; font-size: 0.9rem; }
.net-iface { font-family: monospace; min-width: 60px; }

.metrics-footer {
  display: flex; justify-content: space-between; padding: 0.5rem 1rem;
  border-top: 1px solid #e0e0e0; background: #fafafa; font-size: 0.85rem; color: #666;
}

.tool-card {
  margin: 0.4rem 1rem; padding: 0.5rem 0.75rem;
  background: #f0f8ff; border: 1px solid #b6d4fe; border-radius: 6px;
  font-size: 0.9rem;
}
.tool-card.running .tool-status { animation: blink 1s linear infinite; }
.tool-card.error { background: #fff1f0; border-color: #ffa39e; }
.tool-card.done .tool-status { color: #389e0d; }
.tool-card-header { cursor: pointer; display: flex; gap: 0.5rem; align-items: center; }
.tool-card .tool-name { font-family: monospace; font-weight: 500; }
.tool-card .tool-status { margin-left: auto; }
.tool-card pre {
  font-size: 0.8rem; margin: 0.3rem 0 0; padding: 0.4rem; background: rgba(0,0,0,0.04);
  border-radius: 4px; overflow-x: auto; max-height: 0; transition: max-height 0.2s;
  white-space: pre-wrap; word-break: break-word;
}
.tool-card.expanded pre { max-height: 400px; }
.tool-card .tool-output { display: none; }
.tool-card.done .tool-output, .tool-card.error .tool-output { display: block; max-height: 80px; }
.tool-card.expanded.done .tool-output, .tool-card.expanded.error .tool-output { max-height: 400px; }
@keyframes blink { 50% { opacity: 0.3; } }

.confirm-card {
  margin: 0.6rem 1rem; padding: 0.75rem 1rem;
  background: #fff7e6; border: 2px solid #ffa940; border-radius: 8px;
}
.confirm-header { font-weight: 600; color: #d46b08; margin-bottom: 0.4rem; }
.confirm-body code { background: rgba(0,0,0,0.05); padding: 0.1rem 0.3rem; border-radius: 3px; font-family: monospace; }
.confirm-body pre { font-size: 0.8rem; padding: 0.5rem; background: rgba(0,0,0,0.05); border-radius: 4px; max-height: 200px; overflow-y: auto; }
.confirm-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.5rem; }
.confirm-actions button { padding: 0.4rem 1rem; border-radius: 4px; cursor: pointer; border: 1px solid #ccc; background: white; }
.confirm-actions .btn-approve { background: #1890ff; color: white; border-color: #1890ff; }
.confirm-actions .btn-cancel { background: #f5f5f5; }
.confirm-card.locked button { opacity: 0.5; cursor: not-allowed; }

.tool-card {
  margin: 0.4rem 1rem; padding: 0.5rem 0.75rem;
  background: #f0f8ff; border: 1px solid #b6d4fe; border-radius: 6px;
  font-size: 0.9rem;
}
.tool-card.running .tool-status { animation: blink 1s linear infinite; }
.tool-card.error { background: #fff1f0; border-color: #ffa39e; }
.tool-card.done .tool-status { color: #389e0d; }
.tool-card-header { cursor: pointer; display: flex; gap: 0.5rem; align-items: center; }
.tool-card .tool-name { font-family: monospace; font-weight: 500; }
.tool-card .tool-status { margin-left: auto; }
.tool-card pre {
  font-size: 0.8rem; margin: 0.3rem 0 0; padding: 0.4rem; background: rgba(0,0,0,0.04);
  border-radius: 4px; overflow-x: auto; max-height: 0; transition: max-height 0.2s;
  white-space: pre-wrap; word-break: break-word;
}
.tool-card.expanded pre { max-height: 400px; }
.tool-card .tool-output { display: none; }
.tool-card.done .tool-output, .tool-card.error .tool-output { display: block; max-height: 80px; }
.tool-card.expanded.done .tool-output, .tool-card.expanded.error .tool-output { max-height: 400px; }
@keyframes blink { 50% { opacity: 0.3; } }

.confirm-card {
  margin: 0.6rem 1rem; padding: 0.75rem 1rem;
  background: #fff7e6; border: 2px solid #ffa940; border-radius: 8px;
}
.confirm-header { font-weight: 600; color: #d46b08; margin-bottom: 0.4rem; }
.confirm-body code { background: rgba(0,0,0,0.05); padding: 0.1rem 0.3rem; border-radius: 3px; font-family: monospace; }
.confirm-body pre { font-size: 0.8rem; padding: 0.5rem; background: rgba(0,0,0,0.05); border-radius: 4px; max-height: 200px; overflow-y: auto; }
.confirm-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.5rem; }
.confirm-actions button { padding: 0.4rem 1rem; border-radius: 4px; cursor: pointer; border: 1px solid #ccc; background: white; }
.confirm-actions .btn-approve { background: #1890ff; color: white; border-color: #1890ff; }
.confirm-actions .btn-cancel { background: #f5f5f5; }
.confirm-card.locked button { opacity: 0.5; cursor: not-allowed; }

#send-btn.stop { background: #ff4d4f; color: white; border-color: #ff4d4f; }
#send-btn.stop:hover { background: #d9363e; }
