:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.15);
  --secondary: #10b981;
  --secondary-hover: #059669;
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --info: #0ea5e9;

  --bg-main: #0b0f19;
  --bg-surface: #111827;
  --bg-card: #1f2937;
  --bg-card-hover: #263346;
  --bg-input: #374151;
  --bg-input-focus: #4b5563;
  --border-color: #374151;
  --border-light: rgba(255, 255, 255, 0.08);

  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, Menlo, Consolas, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 9999px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 24px -4px rgba(0,0,0,0.5);

  --sidebar-width: 280px;
  --topbar-height: 64px;
  --savebar-height: 68px;
}

[data-theme="light"] {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: rgba(79, 70, 229, 0.1);
  --secondary: #059669;
  --secondary-hover: #047857;
  --warning: #d97706;
  --warning-bg: rgba(217, 119, 6, 0.1);
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.1);

  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input: #f1f5f9;
  --bg-input-focus: #e2e8f0;
  --border-color: #e2e8f0;
  --border-light: rgba(0, 0, 0, 0.06);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 24px -4px rgba(0,0,0,0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-pill);
}

/* Header / Topbar */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.35);
}

.brand-title {
  display: flex;
  flex-direction: column;
}

.brand-title h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 10px;
  padding: 2px 6px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: var(--radius-pill);
  font-weight: 600;
  text-transform: uppercase;
}

.brand-title span {
  font-size: 11px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.device-status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.connected {
  background: var(--secondary);
  box-shadow: 0 0 10px var(--secondary);
}

.status-dot.busy {
  background: var(--warning);
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.btn-secondary {
  background: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card-hover);
}

.btn-danger {
  background: var(--danger-bg);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}
.btn-icon:hover {
  background: var(--bg-card-hover);
}

/* Form Controls */
select, input {
  font-family: inherit;
  font-size: 13.5px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s ease;
}

select:focus, input:focus {
  border-color: var(--primary);
  background: var(--bg-input-focus);
}

input[type="text"].mono, input.mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* Layout Core */
.app-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.nav-section-title {
  padding: 16px 20px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-menu {
  list-style: none;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 2px 7px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
}

.nav-item.active .nav-badge {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

/* Main Content Area */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 36px 120px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Hardware Info Banner */
.hardware-banner {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.hw-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hw-label {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hw-val {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hw-val.empty {
  color: var(--text-muted);
  font-weight: 400;
}

/* Cards Section */
.config-group-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.warn-banner {
  background: var(--warning-bg);
  border-left: 4px solid var(--warning);
  padding: 12px 20px;
  color: var(--warning);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Parameters Table */
.params-table {
  width: 100%;
  border-collapse: collapse;
}

.params-table th {
  text-align: left;
  padding: 12px 24px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface);
}

.params-table td {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.param-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.param-name-label {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-primary);
}

.param-unit {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
}

.param-cmd-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.param-desc {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.param-current-val {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.param-current-val.unloaded {
  color: var(--text-muted);
  font-style: italic;
}

.param-input-cell {
  position: relative;
  min-width: 220px;
}

.param-input-cell input, .param-input-cell select {
  width: 100%;
}

.param-row.modified {
  background: var(--primary-light);
}

.param-row.modified input, .param-row.modified select {
  border-color: var(--primary);
  font-weight: 600;
  color: var(--primary);
}

.param-row.has-error {
  background: var(--danger-bg);
}

.param-row.has-error input {
  border-color: var(--danger);
}

.param-error-hint {
  font-size: 11px;
  color: var(--danger);
  margin-top: 4px;
}

.param-verify-status {
  text-align: center;
  width: 48px;
}

.verify-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 12px;
}

.verify-badge.success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--secondary);
}

.verify-badge.failed {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Sticky Save Bar */
.savebar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--savebar-height);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 36px;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.2);
}

.savebar-status {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.savebar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.hidden {
  display: none !important;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 650px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.diff-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diff-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  font-size: 13px;
}

.diff-keys {
  display: flex;
  flex-direction: column;
}

.diff-keys span {
  font-weight: 600;
}

.diff-keys code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.diff-values {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
}

.diff-old {
  color: var(--text-muted);
  text-decoration: line-through;
}

.diff-new {
  color: var(--primary);
  font-weight: 600;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Console Terminal View */
.terminal-card {
  background: #000;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 520px;
}

#panelTerminal {
  display: flex !important;
  flex-direction: column !important;
  width: 100%;
}

#panelTerminal .card-header {
  width: 100%;
}

#panelTerminal .terminal-card {
  width: 100%;
}

.terminal-header {
  padding: 12px 18px;
  background: #111;
  border-bottom: 1px solid #222;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: #888;
}

.terminal-logs {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-entry.tx {
  color: #60a5fa;
}

.log-entry.rx {
  color: #34d399;
}

.log-entry.er {
  color: #f87171;
}

.terminal-input-bar {
  display: flex;
  padding: 10px 14px;
  background: #111;
  border-top: 1px solid #222;
  gap: 10px;
}

.terminal-input-bar input {
  flex: 1;
  background: #000;
  border-color: #333;
  color: #fff;
  font-family: var(--font-mono);
}

/* Presets Bar */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.preset-chip {
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.15s ease;
}

.preset-chip:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
}

.preset-chip-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.preset-chip-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Responsiveness */
@media (max-width: 900px) {
  .sidebar {
    display: none; /* Poderá ser aberto via toggle mobile */
  }
  .main-content {
    padding: 18px 18px 120px;
  }
  .topbar {
    padding: 0 16px;
  }
}
