:root {
  --bg: #141725;
  --bg-elevated: #1a1a2e;
  --bg-soft: #21263c;
  --bg-muted: #101321;
  --border: #2c324f;
  --text: #eef2ff;
  --muted: #95a0c1;
  --accent: #ff7b3a;
  --danger: #ff5c70;
  --success: #57d48d;
  --offline: #67718d;
  --radius: 18px;
  --mono: "JetBrains Mono", "Fira Code", monospace;
  --sans: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
}
button, input, textarea, select {
  font: inherit;
}
button { cursor: pointer; }
img { max-width: 100%; display: block; }

.screen {
  display: none;
  min-height: 100vh;
}
.screen.active {
  display: block;
}

#login-screen {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top right, rgba(255, 123, 58, 0.12), transparent 20%),
    var(--bg);
}
#login-screen.active {
  display: flex;
}

.panel-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login-card {
  width: min(100%, 420px);
  padding: 28px;
}
.brand {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 28px;
}
.brand-mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(255, 123, 58, 0.14);
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
}
.brand h1,
.topbar h2,
.card-header h3 {
  margin: 0;
}
.brand p,
.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}
.login-form {
  display: grid;
  gap: 16px;
}
.login-form label {
  display: grid;
  gap: 8px;
}
.login-form span {
  color: var(--muted);
  font-size: 14px;
}
input, textarea, select {
  width: 100%;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}
.primary-button,
.ghost-button,
.icon-button,
.tab-button {
  border: 1px solid transparent;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.primary-button {
  background: var(--accent);
  color: #181818;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
}
.primary-button:hover { filter: brightness(1.06); }
.ghost-button,
.icon-button,
.tab-button {
  background: var(--bg-soft);
  color: var(--text);
  border-color: var(--border);
}
.ghost-button {
  padding: 10px 14px;
  border-radius: 12px;
}
.icon-button {
  min-width: 40px;
  min-height: 40px;
  border-radius: 12px;
}
.tab-button {
  border-radius: 999px;
  padding: 10px 14px;
}
.tab-button.active {
  background: rgba(255, 123, 58, 0.14);
  color: var(--accent);
  border-color: rgba(255, 123, 58, 0.3);
}
.ghost-button.danger {
  color: #ffc3cb;
}
.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

#dashboard-screen {
  padding: 18px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.topbar-actions,
.inline-actions,
.card-header,
.log-controls,
.bot-log-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
}
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 18px;
}
.status-card { grid-column: span 3; padding: 18px; }
.camera-card { grid-column: span 4; padding: 18px; }
.logs-card { grid-column: span 5; padding: 18px; }
.logs-card-wide { min-height: 560px; }
.chat-card { grid-column: span 7; padding: 18px; min-height: 420px; }
.diary-card { grid-column: span 5; padding: 18px; min-height: 420px; }

.card-header {
  justify-content: space-between;
  margin-bottom: 16px;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
}
.badge.neutral { color: var(--muted); }
.badge.ok { color: var(--success); }
.badge.error { color: var(--danger); }

.status-main {
  display: grid;
  gap: 18px;
}
.status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}
.status-led {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--offline);
}
.status-led.online { background: var(--success); }
.status-led.offline { background: var(--offline); }
.status-list {
  display: grid;
  gap: 14px;
  margin: 0;
}
.status-list div {
  padding: 12px;
  background: var(--bg-soft);
  border-radius: 14px;
}
.status-list dt {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 6px;
}
.status-list dd {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.muted-panel {
  background: var(--bg-soft);
  border: 1px dashed var(--border);
}
.camera-frame {
  min-height: 280px;
  border-radius: 16px;
  overflow: hidden;
  display: grid;
  place-items: center;
}
#camera-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.placeholder-state {
  color: var(--muted);
  padding: 24px;
  text-align: center;
}
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}
.checkbox-label input {
  width: auto;
  accent-color: var(--accent);
}

.logs-header {
  align-items: flex-start;
}
.log-controls {
  flex-wrap: wrap;
  justify-content: flex-end;
}
.tab-group {
  display: inline-flex;
  gap: 8px;
  padding: 4px;
  border-radius: 999px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
}
.log-tab { display: none; }
.log-tab.active { display: block; }
.session-list {
  display: grid;
  gap: 12px;
  max-height: 430px;
  overflow: auto;
  padding-right: 4px;
}
.session-item {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.session-item summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
}
.session-item summary::-webkit-details-marker { display: none; }
.session-summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.session-title {
  font-size: 14px;
  font-family: var(--mono);
}
.session-json,
.log-output {
  margin: 0;
  padding: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  background: #0f1322;
  user-select: text;
}
.log-output {
  min-height: 410px;
  max-height: 410px;
  overflow: auto;
  border-radius: 14px;
  border: 1px solid var(--border);
}
.log-line-error { color: #ff7f8f; }
.log-line-initiative { color: #70e0a0; }
.bot-log-toolbar {
  margin-bottom: 12px;
  justify-content: space-between;
}

.chat-history {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 260px;
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
  margin-bottom: 16px;
}
.chat-message {
  display: grid;
  gap: 6px;
}
.chat-meta {
  color: var(--muted);
  font-size: 12px;
}
.chat-bubble {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  white-space: pre-wrap;
  line-height: 1.5;
}
.chat-message.user .chat-bubble {
  border-color: rgba(255, 123, 58, 0.45);
}
.chat-form {
  display: grid;
  gap: 12px;
}
.chat-form textarea {
  resize: vertical;
  min-height: 100px;
}

.diary-content {
  max-height: 330px;
  overflow: auto;
  padding-right: 4px;
  line-height: 1.7;
}
.diary-content h1,
.diary-content h2,
.diary-content h3 {
  margin-top: 1.2em;
}
.diary-content code,
.diary-content pre {
  font-family: var(--mono);
}
.diary-content pre {
  background: #0f1322;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  overflow: auto;
}

@media (max-width: 1200px) {
  .status-card,
  .camera-card,
  .logs-card,
  .chat-card,
  .diary-card {
    grid-column: span 12;
  }
}

@media (max-width: 720px) {
  #dashboard-screen { padding: 12px; }
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .topbar-actions,
  .log-controls,
  .bot-log-toolbar,
  .card-header {
    flex-wrap: wrap;
  }
  .session-summary {
    flex-direction: column;
  }
}
