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

:root {
  --sidebar-bg:    #201F1E;
  --sidebar-hover: #3B3A39;
  --sidebar-active:#0078D4;
  --accent:        #0078D4;
  --accent-hover:  #106EBE;
  --success:       #107C10;
  --warning:       #CA5010;
  --danger:        #D13438;
  --text-primary:  #323130;
  --text-secondary:#605E5C;
  --text-muted:    #A19F9D;
  --surface:       #FAF9F8;
  --surface-alt:   #F3F2F1;
  --border:        #EDEBE9;
  --border-mid:    #C8C6C4;
  --white:         #FFFFFF;
  --sidebar-width: 220px;
  --radius:        6px;
  --radius-lg:     10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface);
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.logo-knx {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: 1px;
}
.logo-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 20px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border-radius: 0;
}
.nav-item svg {
  width: 16px; height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.nav-item:hover {
  background: var(--sidebar-hover);
  color: #FFFFFF;
}
.nav-item.active {
  background: var(--sidebar-active);
  color: #FFFFFF;
}

.sidebar-status {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #6FCF97;
  flex-shrink: 0;
}
.status-dot.error { background: var(--danger); }
.status-dot.warning { background: #F2C94C; }
#statusText {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Main Content ── */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  overflow-y: auto;
}

.tab { display: none; padding: 36px 40px; max-width: 800px; }
.tab.active { display: block; }

.tab-header { margin-bottom: 28px; }
.tab-header h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.tab-header p {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Cards ── */
.card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 24px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}
.card-sub {
  font-size: 12px;
  color: var(--text-secondary);
}
.card.success { background: #DFF6DD; border-color: #A5D6A7; }
.card.warning { background: #FFF4CE; border-color: #F9D849; }

/* ── Section titles ── */
.section-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}
.section-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.6;
}

/* ── Drop Zone ── */
.dropzone {
  border: 2px dashed var(--border-mid);
  border-radius: var(--radius-lg);
  background: var(--white);
  height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 14px;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: #EFF6FF;
}
.dropzone-icon { font-size: 28px; }
.dropzone-text {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Upload Progress ── */
.upload-progress {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
}
.progress-bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s;
  width: 0%;
}
.progress-status {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}
.progress-status.success { color: var(--success); }
.progress-status.error   { color: var(--danger); }

/* ── Log Box ── */
.log-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  height: 160px;
  overflow-y: auto;
  font-family: "Consolas", "SF Mono", monospace;
  font-size: 12px;
  color: var(--text-secondary);
}
.log-entry { margin-bottom: 3px; }
.log-entry.ok    { color: var(--success); }
.log-entry.error { color: var(--danger); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-secondary:hover:not(:disabled) { background: #EFF6FF; }
.btn-icon {
  padding: 8px 10px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

/* ── Tables ── */
.table-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: var(--surface-alt);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
tbody tr {
  background: var(--white);
  cursor: pointer;
  transition: background 0.1s;
}
tbody tr:hover { background: var(--surface-alt); }
tbody tr.selected { background: #EFF6FF; }
tbody tr + tr { border-top: 1px solid var(--border); }
tbody td {
  padding: 10px 14px;
  color: var(--text-primary);
}
.table-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 28px !important;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-active  { background: #DFF6DD; color: var(--success); }
.badge-expired { background: #FAF9F8; color: var(--text-muted); }
.badge-pending { background: #FFF4CE; color: #795D1A; }

/* ── Loading ── */
.loading-overlay {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 16px 0;
  color: var(--text-secondary);
  font-size: 13px;
}
.loading-overlay.visible { display: flex; }
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Forms ── */
.form-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 520px;
}
.form-row { margin-bottom: 16px; }
.form-row label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}
.form-row input,
.form-row select,
.form-row textarea {
  padding: 8px 10px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--white);
  font-family: inherit;
  transition: border-color 0.15s;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-row textarea { resize: vertical; }
.input-group {
  display: flex;
  gap: 6px;
}
.input-group select { flex: 1; }

/* ── Banners ── */
.banner {
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.5;
}
.banner-success { background: #DFF6DD; color: #1B5E20; }
.banner-warning { background: #FFF4CE; color: #795D1A; }
.banner-error   { background: #FDEDED; color: #B71C1C; }
.banner-info    { background: #EFF6FF; color: #0D47A1; }

/* ── Settings ── */
.settings-section {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-primary);
}
.settings-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}
.connection-test-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px !important;
}
.connection-test-row label { display: none; }

/* ── Responsive ── */
@media (max-width: 680px) {
  .sidebar { width: 60px; }
  .logo-sub, .nav-item span, #statusText { display: none; }
  .logo-knx { font-size: 16px; }
  .nav-item { justify-content: center; padding: 14px; }
  .main { margin-left: 60px; }
  .tab { padding: 20px 16px; }
  .form-card { padding: 16px; }
}

/* ── Agent Status ── */
.sidebar-agent {
  padding: 10px 20px;
  border-top: 1px solid rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: default;
}
.agent-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #888;
  flex-shrink: 0;
}
.agent-dot.active  { background: #6FCF97; }
.agent-dot.inactive{ background: #F2C94C; }
.agent-dot.missing { background: var(--danger); }
#agentText {
  font-size: 11px;
  color: var(--text-muted);
}

.agent-status-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface-alt);
  border: 1px solid var(--border);
}
.agent-status-icon { font-size: 22px; }
.agent-status-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 3px;
}
.agent-status-sub {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ── Login Gate ── */
.login-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-gate.hidden { display: none; }

.login-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.login-logo {
  text-align: center;
  margin-bottom: 8px;
}
.login-logo .logo-knx {
  color: var(--text-primary);
  font-size: 28px;
}
.login-logo .logo-sub {
  color: var(--text-secondary);
  display: block;
  font-size: 14px;
}
.login-intro {
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}
.login-field { margin-bottom: 16px; }
.login-field label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 6px;
}
.login-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
}
.login-field input:focus {
  outline: none;
  border-color: var(--accent);
}
.login-btn {
  width: 100%;
  justify-content: center;
  padding: 11px;
  margin-top: 8px;
  font-size: 14px;
}
.login-banner {
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  margin-bottom: 16px;
  line-height: 1.5;
  background: #FDEDED;
  color: #B71C1C;
}
