:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-subtle: #edf0f4;
  --border: #d8dee6;
  --ink: #111827;
  --muted: #4b5563;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --danger: #b91c1c;
  --ok: #15803d;
  --text-heading: 1.0625rem;
  --text-body: 0.9375rem;
  --text-sm: 0.8125rem;
  --font-sans: "Inter", "Noto Sans JP", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* Top navigation bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.25rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
  text-decoration: none;
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--surface-subtle);
  padding: 3px;
  border-radius: 8px;
  overflow-x: auto;
}

.nav-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 0.375rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 160ms cubic-bezier(0.22, 1, 0.36, 1), color 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.nav-tab:hover {
  color: var(--ink);
}

.nav-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.08);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  white-space: nowrap;
}

.nav-link {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
}

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

/* Main workspace */
.workspace {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

h1, h2 {
  margin: 0;
  letter-spacing: -0.02em;
}

.page-h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.section-h2 {
  font-size: var(--text-heading);
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.muted {
  color: var(--muted);
  font-size: var(--text-sm);
}

/* Surface sections separated by 1px borders (no nested cards) */
.surface-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.25rem;
}

@media (max-width: 820px) {
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
  .topbar {
    height: auto;
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
  }
}

/* Meters */
.meter-row {
  margin-bottom: 1rem;
}

.meter-row:last-child {
  margin-bottom: 0;
}

.meter-head {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  margin-bottom: 0.35rem;
}

.meter-track {
  height: 8px;
  background: var(--surface-subtle);
  border-radius: 999px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

th, td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-weight: 600;
  color: var(--muted);
}

tr:last-child td {
  border-bottom: 0;
}

.status-text-ok {
  color: var(--ok);
  font-weight: 600;
}

.status-text-off {
  color: var(--muted);
}

/* Forms & controls */
label.field {
  display: block;
  margin-bottom: 0.85rem;
}

.field-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-family: inherit;
  font-size: var(--text-body);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  transition: border-color 150ms cubic-bezier(0.22, 1, 0.36, 1);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 96px;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background-color 160ms cubic-bezier(0.22, 1, 0.36, 1), border-color 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.btn:hover:not(:disabled) {
  background: var(--surface-subtle);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  color: var(--danger);
  border-color: #fecaca;
}

.btn-danger:hover:not(:disabled) {
  background: #fef2f2;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

/* Segmented control */
.segmented {
  display: inline-flex;
  background: var(--surface-subtle);
  padding: 3px;
  border-radius: 7px;
  gap: 2px;
}

.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0.35rem 0.7rem;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--muted);
  border-radius: 5px;
  cursor: pointer;
}

.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.08);
}

.chat-log {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  padding: 1rem;
  height: 360px;
  overflow-y: auto;
  margin-bottom: 0.85rem;
}

.chat-msg {
  margin-bottom: 0.85rem;
  max-width: 65ch;
  white-space: pre-wrap;
}

.chat-msg strong {
  display: block;
  font-size: var(--text-sm);
  color: var(--muted);
}

.vnc-frame {
  width: 100%;
  height: 540px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
}

.ocr-lines {
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.ocr-line {
  padding: 0.35rem 0.5rem;
  border-radius: 5px;
  cursor: pointer;
}

.ocr-line.active {
  background: #dbeafe;
}

.output-image {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.alert-box {
  padding: 0.75rem 1rem;
  border-radius: 7px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  font-size: var(--text-sm);
  margin-top: 0.75rem;
}

.alert-error {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}

.hidden {
  display: none !important;
}

/* Blender 3D Studio */
.code-editor {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  tab-size: 4;
}

.blender-viewer-wrap {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.blender-viewer {
  width: 100%;
  height: 420px;
  display: block;
  background: radial-gradient(circle at 50% 35%, #1e293b 0%, #0f172a 100%);
}

/* Login sheet */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-sheet {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
  }
}
