/* ROOT VARIABLES */
:root {
  --accent: #4a5568;
  --accent-light: #718096;
  --background: #f2f2f7;
  --card: #ffffff;
  --text: #222222;
  --muted: #777777;
  --border: #dddddd;
  --green: #31b64b;
  --red: #d94444;
  --log-bg: #252525;
  --log-border: #3a3a3a;
}

/* RESET + BASE */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* SIDEBAR */
aside {
  position: fixed;
  inset: 0 auto 0 0;
  width: 80px;
  background: var(--accent);
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 0;
  gap: 20px;
}

aside button {
  min-width: 52px;
  min-height: 46px;
  width: 52px;
  height: 46px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

aside button:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #e2e8f0;
}

aside button.active {
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
}

aside svg,
.hap-icon svg,
.pairing-state svg,
.page-actions svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

aside svg {
  width: 30px;
  height: 30px;
}

.icon-dot {
  width: 8px;
  height: 8px;
  background: currentColor;
  border-radius: 50%;
  display: inline-block;
}

aside button .icon-dot {
  margin: auto;
}

/* PAGE HEADER */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-header h1 {
  margin-bottom: 0;
}

.page-meta {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.page-actions {
  display: flex;
  gap: 12px;
}

.page-actions button,
.page-actions a {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.page-actions button:hover,
.page-actions a:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.page-actions svg {
  width: 20px;
  height: 20px;
}

/* MAIN LAYOUT */
main {
  margin-left: 80px;
  padding: 28px 40px;
}

h1 {
  color: var(--accent-light);
  font-size: 28px;
  font-weight: 300;
  letter-spacing: -0.2px;
  margin: 0 0 20px;
}

/* GRID LAYOUT */
.status-layout {
  display: grid;
  grid-template-columns: repeat(auto-fill, 300px);
  gap: 16px;
  align-items: start;
}


/* GENERIC CARDS */
.card,
.pairing-card {
  background: var(--card);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.045);
}

.pairing-card {
  border-color: var(--border);
  width: 300px;
}

/* PAIRING TITLE */
.pairing-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 14px;
  text-align: center;
  line-height: 1.3;
}

/* PAIRING LAYOUT */
.pairing-content {
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}

/* PAIRING LEFT COLUMN */
.pairing-left {
  width: auto;
}

.qr,
.qr-missing {
  width: 150px;
  height: 150px;
}

.qr {
  image-rendering: pixelated;
}

.qr-missing {
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.pin {
  margin-top: 10px;
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  cursor: default;
  user-select: none;
}

.pairing-status {
  margin-top: 6px;
  font-size: 15px;
  color: var(--muted);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

.hap-icon svg,
.pairing-state svg {
  width: 18px;
  height: 18px;
}

.pairing-state {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.pairing-state.paired {
  color: var(--green);
}

.pairing-state.unpaired {
  color: var(--red);
  cursor: default;
}

.meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* LOG CARD */
.card.logs-card {
  margin-top: 18px;
  width: 100%;
  max-width: calc(100vw - 130px);
  background: var(--log-bg);
  color: #dddddd;
  padding: 0;
  overflow: hidden;
}

/* LOG HEADER */
.logs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--log-border);
  background: rgba(255, 255, 255, 0.02);
}

.logs-title {
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* LOG CONTROLS */
.logs-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logs-controls button {
  border: 0;
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  font-size: 12px;
  opacity: 0.7;
}

.logs-controls button:hover {
  color: #e5e7eb;
  opacity: 1;
}

/* LOG OUTPUT */
.log-output {
  height: 360px;
  max-height: 360px;
  overflow: auto;
  padding: 14px 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre;
  scrollbar-width: thin;
  scrollbar-color: #6b7280 #1f2933;
}

.log-output::-webkit-scrollbar {
  width: 10px;
}

.log-output::-webkit-scrollbar-track {
  background: #1f2933;
  border-radius: 10px;
}

.log-output::-webkit-scrollbar-thumb {
  background: #6b7280;
  border-radius: 10px;
  border: 2px solid #1f2933;
}

.log-output::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

.log-line {
  margin-bottom: 3px;
  opacity: 0.95;
  background: transparent;
  border: 0;
  padding: 0;
}

.log-line:hover {
  background: transparent;
}

.log-line.log-error {
  color: #ff6b6b;
  background: transparent;
  border: 0;
  padding: 0;
}

.log-line.log-error + .log-line {
  opacity: 0.85;
}

.log-line.log-warn {
  color: #f7b731;
}

.log-line.log-info {
  color: #cbd5e1;
}

.log-line.log-debug {
  color: #888888;
}

/* GENERIC LIST (FOR FUTURE PAGES) */
.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.list-row {
  padding: 12px 14px;
  border-radius: 8px;
  background: #f8f9fb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.list-title {
  font-weight: 600;
}

.list-sub {
  font-size: 12px;
  color: var(--muted);
}

.list-value {
  font-weight: 600;
}

/* CONFIG FORM */
.card-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
}

.card-description {
  color: var(--muted);
  margin-bottom: 14px;
}

/* Config header (Save + Add layout) */
.config-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.config-page-header .card-description {
  margin-bottom: 0;
}

.config-page-header .actions {
  margin-bottom: 0;
  flex-shrink: 0;
}

.actions {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

button.primary,
button.secondary {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: #ffffff;
  padding: 9px 13px;
}

button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 7px 10px;
}

button.secondary:hover:not(:disabled) {
  background: #f1f3f5;
  color: var(--text);
}

/* ARRAY LIST */
.config-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Fix + Add button width */
.config-list > button.primary {
  align-self: flex-start;
  margin-bottom: 4px;
}

/* CARD PER ITEM */
.config-card {
  background: #ffffff;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid rgba(0,0,0,0.06);
}

.config-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  padding-bottom: 8px;
}

.config-card-header button {
  opacity: 0.7;
}

.config-card-header button:hover {
  opacity: 1;
}

.config-card-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

/* FORM ROWS */
.config-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 220px;
  gap: 16px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 8px;
  background: #f7f8fa;
  border: 1px solid rgba(0, 0, 0, 0.04);
}

.config-row:first-of-type {
  background: #eef2f7;
}

.config-row .list-title {
  font-weight: 600;
}

/* INPUTS */
.config-row input,
.config-row select {
  width: 100%;
  min-height: 36px;
  border: 1px solid #d6d6db;
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 5px 8px;
  font-size: 13px;
}

.config-row:hover {
  background: #eef2f7;
}

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

.config-row input[type="checkbox"] {
  transform: scale(0.9);
}

/* ERROR BLOCK */
main > .error {
  margin-bottom: 20px;
  padding: 14px;
  background: #fff1f1;
  border-left: 4px solid var(--red);
  color: #9f2424;
  border-radius: 6px;
}

code {
  background: #f1f1f1;
  padding: 2px 5px;
  border-radius: 4px;
}

/* MOBILE RESPONSIVE */
@media (max-width: 800px) {
  aside {
    width: 64px;
  }

  aside button {
    width: 48px;
    height: 44px;
  }

  aside svg {
    width: 24px;
    height: 24px;
  }

  main {
    margin-left: 64px;
    padding: 20px;
  }

  h1 {
    font-size: 24px;
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-layout {
    grid-template-columns: 1fr;
  }

  .pairing-content {
    justify-content: center;
    text-align: center;
  }

  .qr,
  .qr-missing {
    width: 180px;
    height: 180px;
  }

  .pairing-card {
    width: 100%;
  }

  .card.logs-card {
    max-width: calc(100vw - 84px);
  }

  .config-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .config-card-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .config-page-header {
    flex-direction: column;
  }
}