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

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #22263a;
  --bg-input: #13151d;
  --border: #2a2d3a;
  --text: #e4e4e7;
  --text-dim: #9ca3af;
  --accent: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --gray: #6b7280;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  gap: 6px;
}
.btn:hover { background: var(--bg-card-hover); }
.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn-xs { padding: 2px 6px; font-size: 11px; }
.btn-full { width: 100%; }
.btn-green { background: var(--green); color: #fff; border-color: var(--green); }
.btn-green:hover { background: #1ea34e; }
.btn-red { background: var(--red); color: #fff; border-color: var(--red); }
.btn-red:hover { background: #dc2626; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.btn-outline { background: transparent; }
.btn-outline:hover { background: rgba(255,255,255,0.05); }

/* Inputs */
.input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--accent); }
.input-sm { padding: 4px 8px; font-size: 12px; width: auto; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-yellow { background: rgba(245,158,11,0.2); color: var(--amber); }

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}
.topbar-stats { display: flex; gap: 16px; }
.topbar-actions { display: flex; gap: 8px; }

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 16px;
  background: var(--bg-card);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.stat-value { font-size: 20px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; }

/* Account grid */
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.account-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.account-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.account-card.status-running { border-left: 3px solid var(--green); }
.account-card.status-error { border-left: 3px solid var(--red); }
.account-card.status-starting { border-left: 3px solid var(--amber); }
.account-card-empty {
  border-style: dashed;
  cursor: default;
}
.account-card-empty:hover { transform: none; box-shadow: none; }

.card-header { margin-bottom: 12px; }
.card-title-row { display: flex; align-items: center; gap: 8px; }
.card-name { font-weight: 600; font-size: 15px; }
.card-slot { color: var(--text-dim); font-size: 13px; }
.card-status-text { font-size: 12px; color: var(--text-dim); }

.card-stats {
  display: flex;
  gap: 20px;
  margin: 12px 0;
}
.card-stat { display: flex; flex-direction: column; }
.card-stat-value { font-size: 18px; font-weight: 700; }
.card-stat-label { font-size: 11px; color: var(--text-dim); }

.card-actions { display: flex; justify-content: flex-end; }

.card-body-empty {
  display: flex;
  justify-content: center;
  padding: 20px 0;
}

/* Status dots */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.status-running { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.status-error { background: var(--red); }
.status-dot.status-starting { background: var(--amber); animation: pulse 1.5s infinite; }
.status-dot.status-stopped { background: var(--gray); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Add account form (inline in card) */
.add-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}
.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

/* Detail view */
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.detail-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
}
.detail-actions { display: flex; gap: 8px; }

/* Tabs */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Log viewer */
.log-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}
.log-toolbar .input { max-width: 300px; }
.log-autoscroll {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  cursor: pointer;
}

.log-viewer {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  height: calc(100vh - 280px);
  min-height: 300px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
}

.log-line { white-space: pre-wrap; word-break: break-all; }
.log-ts { color: var(--gray); margin-right: 6px; }
.log-lvl { margin-right: 6px; }
.log-info .log-lvl { color: var(--text-dim); }
.log-warn { color: var(--amber); }
.log-warn .log-lvl { color: var(--amber); font-weight: 600; }
.log-error { color: var(--red); }
.log-error .log-lvl { color: var(--red); font-weight: 700; }
.log-fatal { color: var(--red); font-weight: 700; background: rgba(239,68,68,0.08); border-radius: 3px; padding: 1px 4px; }
.log-fatal .log-lvl { color: var(--red); }
.log-success { color: var(--green); }
.log-success .log-lvl { color: var(--green); font-weight: 700; }
.log-sent { color: var(--green); font-weight: 600; }
.log-sent .log-lvl { color: var(--green); font-weight: 700; }
.log-notes-ok { color: var(--green); }
.log-notes-ok .log-lvl { color: var(--green); }

/* Clickable log entries */
.log-clickable { cursor: pointer; border-radius: 3px; transition: background 0.15s; }
.log-clickable:hover { background: rgba(255,255,255,0.04); }
.log-chat-icon { font-size: 11px; opacity: 0.6; margin-right: 2px; }
.log-clickable:hover .log-chat-icon { opacity: 1; }

/* Live Chat tab */
.chat-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.chat-header-label { font-size: 13px; color: var(--text); }
.chat-header-hint { font-size: 12px; color: var(--text-dim); }

.chat-viewer {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  height: calc(100vh - 300px);
  min-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  font-size: 13px;
}

.chat-bubble-row {
  display: flex;
  width: 100%;
}
.chat-bubble-row.chat-op { justify-content: flex-end; }
.chat-bubble-row.chat-cust { justify-content: flex-start; }

.chat-bubble {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}
.chat-op .chat-bubble {
  background: rgba(59,130,246,0.2);
  border: 1px solid rgba(59,130,246,0.3);
  border-bottom-right-radius: 4px;
}
.chat-cust .chat-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-bubble-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.chat-op .chat-bubble-label { color: var(--accent); }
.chat-bubble-text { color: var(--text); }

/* Live Screen tab */
.screen-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.screen-status {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 10px;
}
.screen-live { color: var(--green); background: rgba(34,197,94,0.15); }
.screen-offline { color: var(--red); background: rgba(239,68,68,0.15); }

.screen-viewer {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  min-height: 300px;
}
.screen-img {
  width: 100%;
  display: block;
  image-rendering: auto;
}
.screen-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 14px;
  background: rgba(0,0,0,0.7);
}

/* Chat modal overlay */
.chat-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  backdrop-filter: blur(2px);
}
.chat-modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.chat-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.chat-modal-title { font-size: 14px; font-weight: 600; }
.chat-modal-ts { font-size: 11px; color: var(--text-dim); margin-left: 10px; }
.chat-modal-close { font-size: 18px; line-height: 1; }
.chat-sent-highlight {
  padding: 10px 16px;
  background: rgba(34,197,94,0.08);
  border-bottom: 1px solid var(--border);
}
.chat-sent-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--green);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.chat-sent-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}
.chat-modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
}
.stat-card-value { font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-card-label { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.stat-meta { color: var(--text-dim); font-size: 13px; }

/* Settings */
.settings-sections {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
.settings-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}
.section-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.section-loading, .section-error {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
}
.section-error { color: var(--red); }

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 500px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-group label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}
.form-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}
.form-row .input { flex: 1; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

/* Rules list */
.rule-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.rule-row:last-child { border-bottom: none; }
.rule-text {
  flex: 1;
  font-size: 13px;
  line-height: 1.4;
}

/* Banned word tags */
.banned-words-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}
.banned-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: rgba(239,68,68,0.15);
  color: var(--red);
  border-radius: 12px;
  font-size: 12px;
}
.tag-remove {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.7;
}
.tag-remove:hover { opacity: 1; }

/* Login */
.login-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 80vh;
}
.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-box h2 {
  text-align: center;
  font-size: 18px;
  font-weight: 600;
}
.login-error {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  min-height: 20px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transform: translateY(80px);
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  z-index: 9999;
}
.toast-visible {
  transform: translateY(0);
  opacity: 1;
}
.toast-success { background: var(--green); color: #fff; }
.toast-error { background: var(--red); color: #fff; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray); }

/* Responsive */
@media (max-width: 640px) {
  .account-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-stats { justify-content: center; }
  .topbar-actions { justify-content: center; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .detail-header { flex-wrap: wrap; }
  .log-toolbar { flex-direction: column; align-items: stretch; }
  .log-toolbar .input { max-width: none; }
}
