/* === Design Tokens === */
:root {
  --color-bg: #0f1117;
  --color-surface: #1a1d27;
  --color-surface-hover: #242836;
  --color-border: #2e3345;
  --color-text: #e4e6ef;
  --color-text-muted: #8b8fa3;
  --color-primary: #4f8cff;
  --color-primary-hover: #3a7bff;
  --color-accent: #34d399;
  --color-accent-hover: #2bc48a;
  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --color-warning: #f59e0b;

  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
}

/* === Header === */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.header__left { display: flex; align-items: center; gap: 16px; }
.header__title { font-size: 20px; font-weight: 600; }

.header__status {
  font-size: 13px;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--color-danger);
  color: white;
  font-weight: 500;
}

.header__status--connected {
  background: var(--color-accent);
  color: #0f1117;
}

.header__status--connecting {
  background: var(--color-warning);
  color: #0f1117;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  gap: 6px;
}

.btn:hover { background: var(--color-surface-hover); border-color: var(--color-text-muted); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--color-surface); border-color: var(--color-border); }

.btn--primary { background: var(--color-primary); border-color: var(--color-primary); color: white; }
.btn--primary:hover { background: var(--color-primary-hover); }
.btn--accent { background: var(--color-accent); border-color: var(--color-accent); color: #0f1117; }
.btn--accent:hover { background: var(--color-accent-hover); }
.btn--danger { background: var(--color-danger); border-color: var(--color-danger); color: white; }
.btn--danger:hover { background: var(--color-danger-hover); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--color-surface-hover); }
.btn--connect { background: var(--color-primary); border-color: var(--color-primary); color: white; }
.btn--sm { padding: 4px 10px; font-size: 13px; }
.btn--lg { padding: 10px 24px; font-size: 15px; }

/* === Tabs === */
.tabs {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.tabs__btn {
  padding: 12px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.tabs__btn:hover { color: var(--color-text); }
.tabs__btn--active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* === Tab Panels === */
.tab-panel { display: none; padding: 24px; }
.tab-panel--active { display: block; }

/* === Forms === */
.form__label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.form__input, .form__select, .form__textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 14px;
  font-family: var(--font-family);
  transition: border-color 0.15s;
}

.form__input:focus, .form__select:focus, .form__textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.form__textarea { resize: vertical; font-family: var(--font-mono); }
.form__group { margin-bottom: 12px; }

/* === Write Panel === */
.write-panel__options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.write-panel__actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

/* === Preview Panel === */
.preview-panel { display: flex; flex-direction: column; height: calc(100vh - 140px); }

.preview-panel__toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
}

.preview-panel__info { margin-left: auto; font-size: 13px; color: var(--color-text-muted); }

.preview-panel__canvas {
  flex: 1;
  background: #ffffff;
  border-radius: var(--radius);
  cursor: crosshair;
}

/* === Control Panel === */
.control-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.control-panel__section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
}

.control-panel__heading {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.control-panel__buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* === Jog Pad === */
.jog-pad { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.jog-pad__row { display: flex; gap: 4px; }
.jog-pad__btn { width: 60px; height: 44px; font-weight: 600; }
.jog-pad__btn--center { background: var(--color-primary); border-color: var(--color-primary); color: white; }
.jog-pad__spacer { width: 60px; height: 44px; }

.jog-steps { display: flex; gap: 4px; }
.jog-steps__btn--active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}

/* === Position Display === */
.position-display { display: flex; gap: 24px; }

.position-display__axis {
  display: flex;
  align-items: center;
  gap: 8px;
}

.position-display__label {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-primary);
}

.position-display__value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
}

/* === Progress === */
.progress {
  margin-top: 12px;
  height: 24px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}

.progress__bar {
  height: 100%;
  background: var(--color-accent);
  width: 0%;
  transition: width 0.3s;
}

.progress__text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
}

/* === Console === */
.console {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  height: 150px;
  overflow-y: auto;
  padding: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  margin-bottom: 8px;
}

.console__line { white-space: pre-wrap; word-break: break-all; }
.console__line--sent { color: var(--color-primary); }
.console__line--ok { color: var(--color-accent); }
.console__line--error { color: var(--color-danger); }
.console__line--info { color: var(--color-text-muted); }

.console__input-row { display: flex; gap: 8px; }
.console__input-row .form__input { flex: 1; font-family: var(--font-mono); }

/* === Settings Panel === */
.settings-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.settings-panel__section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
}

.settings-panel__note {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 12px;
}

/* === Modal === */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal--open { display: flex; align-items: center; justify-content: center; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal__content {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  min-width: 360px;
  box-shadow: var(--shadow);
}

.modal__title { font-size: 18px; font-weight: 600; margin-bottom: 16px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* === Responsive === */
@media (max-width: 768px) {
  .header { padding: 10px 16px; }
  .tab-panel { padding: 16px; }
  .control-panel { grid-template-columns: 1fr; }
  .settings-panel { grid-template-columns: 1fr; }
  .write-panel__options { grid-template-columns: 1fr 1fr; }
}
