:root {
  --bg-primary:    #0f0f0f;
  --bg-secondary:  #1a1a1a;
  --bg-tertiary:   #242424;
  --bg-hover:      #2a2a2a;
  --accent-primary: #8B1A2B;
  --accent-hover:   #A52238;
  --text-primary:   #E8E8E8;
  --text-secondary: #9a9a9a;
  --text-muted:     #666;
  --border:         #2a2a2a;
  --success:        #2ECC71;
  --danger:         #E74C3C;
  --warning:        #F39C12;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* ── App Layout ─────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 1rem; font-weight: 600; }

.sidebar-status {
  padding: 8px 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.device-list {
  flex: 1;
  overflow-y: auto;
}

.device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.device-item:hover { background: var(--bg-hover); }
.device-item.active { background: var(--bg-tertiary); border-left: 3px solid var(--accent-primary); }

.device-item-info {
  flex: 1;
  min-width: 0;
}
.device-item-name {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device-item-ip {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Main Panel ─────────────────────────────────────────── */
.main-panel {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.empty-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ── Device Detail ──────────────────────────────────────── */
.device-detail {
  padding: 20px;
  display: flex;
  flex-direction: column;
  flex: 1;
}
.device-detail.hidden { display: none; }

.detail-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.detail-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.detail-title-row h2 { font-size: 1.1rem; font-weight: 600; }
.detail-model { font-size: 0.8rem; color: var(--text-muted); }
.detail-actions { display: flex; gap: 6px; }

/* ── Info Grid ──────────────────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.info-cell label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.info-cell span {
  font-size: 0.85rem;
  color: var(--text-primary);
}

/* ── Info Row (Interfaces + Alarms) ─────────────────────── */
.info-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.info-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  flex: 1;
}
.info-card h4 {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}

.iface-table { width: 100%; font-size: 0.8rem; border-collapse: collapse; }
.iface-table th { text-align: left; padding: 3px 6px; color: var(--text-muted); font-weight: 500; font-size: 0.75rem; }
.iface-table td { padding: 3px 6px; }
.status-up { color: var(--success); font-weight: 500; }
.status-down { color: var(--text-muted); }

.alarm-item { padding: 3px 0; font-size: 0.8rem; color: var(--danger); }
.alarm-badge { background: var(--danger); color: white; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 600; }

/* ── Config Section ─────────────────────────────────────── */
.config-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 300px;
}
.config-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.config-header h3 { font-size: 0.9rem; font-weight: 500; }
.config-actions { display: flex; gap: 6px; }

.config-editor {
  flex: 1;
  min-height: 300px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

/* ── Status Dot ─────────────────────────────────────────── */
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  transition: all 0.3s;
}
.status-dot.online {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}
.status-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 6px var(--danger);
}
.status-dot.disabled { background: var(--text-muted); }
.status-dot.probing {
  background: var(--warning);
  box-shadow: 0 0 6px var(--warning);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-add { background: var(--accent-primary); color: white; }
.btn-add:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: white; font-size: 0.8rem; padding: 4px 10px; }
.btn-danger:hover { opacity: 0.8; }
.btn-sm { font-size: 0.8rem; padding: 4px 10px; }
.btn-edit { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-edit:hover { background: var(--bg-hover); border-color: var(--text-muted); }
.btn-probe { background: var(--bg-tertiary); color: var(--warning); border: 1px solid var(--border); }
.btn-probe:hover { background: var(--bg-hover); border-color: var(--warning); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* ── Modal ──────────────────────────────────────────────── */
.modal {
  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: 1000;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  min-width: 360px;
  max-width: 480px;
}
.modal-content h3 { margin-bottom: 16px; font-size: 1rem; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; margin-bottom: 4px; font-size: 0.8rem; color: var(--text-secondary); }
.form-row input, .form-row select {
  width: 100%;
  padding: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.85rem;
}
.form-row input:focus, .form-row select:focus { outline: none; border-color: var(--accent-primary); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ── Flash notification ─────────────────────────────────── */
.flash {
  position: fixed;
  bottom: 16px;
  right: 16px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.85rem;
  z-index: 1000;
  animation: fadeInOut 3s forwards;
  color: white;
}
.flash.success { background: var(--success); }
.flash.error { background: var(--danger); }
.flash.info { background: var(--accent-primary); }

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateY(10px); }
  10% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* ── Diff Panel ──────────────────────────────────────────── */
.diff-panel {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-secondary);
  max-height: 250px;
  overflow-y: auto;
}
.diff-panel.hidden { display: none; }
.diff-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.diff-header h4 { font-size: 0.8rem; color: var(--text-secondary); font-weight: 500; }
.diff-content {
  padding: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text-primary);
}

/* ── Wide Modal (for commit confirm) ─────────────────────── */
.modal-wide { min-width: 500px; max-width: 700px; }

.text-muted { color: var(--text-muted); }
.ip-link { color: var(--text-secondary); text-decoration: none; font-size: 0.85rem; }
.ip-link:hover { color: var(--accent-hover); text-decoration: underline; }
