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

body {
  background: #0f172a;
  color: #f1f5f9;
  font-family: Arial, sans-serif;
  font-size: 14px;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Header ── */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: #1e293b;
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 14px;
}

.app-header h1 {
  font-size: 1.2rem;
  color: #f8fafc;
}

.server-version {
  font-size: 0.7rem;
  color: #475569;
  background: #0f172a;
  padding: 2px 8px;
  border-radius: 10px;
  vertical-align: middle;
  margin-left: 6px;
  font-weight: normal;
  font-family: monospace;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.server-addr {
  font-family: monospace;
  color: #38bdf8;
  font-size: 0.9rem;
}

.badge {
  background: #0f172a;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  color: #94a3b8;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 6px rgba(239,68,68,0.5);
  display: inline-block;
}
.status-dot.online {
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34,197,94,0.6);
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
}

.tab {
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  background: #1e293b;
  color: #94a3b8;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
}
.tab:hover { background: #334155; color: #f1f5f9; }
.tab.active { background: #2563eb; color: white; }

/* ── Card ── */
.card {
  background: #1e293b;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
}

/* ── Auth overlay ── */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.auth-box {
  background: #1e293b;
  border-radius: 12px;
  padding: 28px 26px;
  width: 100%;
  max-width: 340px;
}
.auth-box h2 {
  font-size: 1.15rem;
  margin-bottom: 18px;
  color: #f8fafc;
  text-align: center;
}
.auth-box button { width: 100%; margin-top: 4px; }
.auth-error {
  background: #7f1d1d;
  color: #fecaca;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.82rem;
  margin-bottom: 14px;
}
.auth-hint {
  background: #0f172a;
  color: #94a3b8;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.8rem;
  margin-bottom: 14px;
}
.text-input {
  width: 100%;
  background: #0f172a;
  color: #f1f5f9;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.85rem;
}

/* ── Log ── */
.logbox-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.logbox-header span {
  font-weight: bold;
  color: #94a3b8;
  font-size: 0.85rem;
}
.logbox {
  max-height: 420px;
  overflow-y: auto;
}
.logitem {
  background: #0f172a;
  padding: 7px 10px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 0.78rem;
  color: #cbd5e1;
  margin-bottom: 3px;
}
.log-empty {
  color: #475569;
  font-size: 0.85rem;
  padding: 8px 0;
}

/* ── Buttons ── */
button {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: #2563eb;
  color: white;
  font-size: 0.85rem;
}
button:hover:not(:disabled) { background: #1d4ed8; }
button:disabled { background: #334155; color: #64748b; cursor: not-allowed; }

.btn-clear {
  background: transparent;
  border: 1px solid #475569;
  color: #94a3b8;
  padding: 4px 10px;
  font-size: 0.75rem;
}
.btn-clear:hover { background: #1e293b; }

.btn-action { background: #334155; padding: 6px 12px; font-size: 0.8rem; }
.btn-action:hover:not(:disabled) { background: #2563eb; }
.btn-green { background: #166534; }
.btn-green:hover:not(:disabled) { background: #15803d; }
.btn-red { background: #7f1d1d; }
.btn-red:hover:not(:disabled) { background: #991b1b; }
.btn-sd { background: #164e63; }
.btn-sd:hover:not(:disabled) { background: #0369a1; }
.btn-sd.active { background: #0369a1; }

/* ── SD panel di dalam kartu device ── */
.sd-panel {
  background: #070f1a;
  border-radius: 8px;
  padding: 12px;
  margin-top: 10px;
  border: 1px solid #1e3a4a;
}
.sd-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.85rem;
  font-weight: bold;
  color: #7dd3fc;
}
.sd-close-btn {
  background: transparent;
  border: 1px solid #334155;
  color: #94a3b8;
  padding: 3px 8px;
  font-size: 0.75rem;
}
.sd-close-btn:hover { background: #1e293b; color: #f1f5f9; }
.sd-panel-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.sd-secret-input {
  flex: 1;
  min-width: 140px;
  background: #0f172a;
  color: #f1f5f9;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.82rem;
}
.sd-load-btn { background: #0369a1; padding: 6px 14px; font-size: 0.82rem; }
.sd-load-btn:hover:not(:disabled) { background: #0284c7; }
.sd-panel-status { color: #475569; font-size: 0.82rem; padding: 4px 0; }
.sd-panel-error  { color: #ef4444; font-size: 0.82rem; padding: 4px 0; }

/* ── SD progress bar ── */
.sd-progress-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #1e3a4a;
}
.sd-progress-file {
  font-size: 0.8rem;
  color: #7dd3fc;
  font-family: monospace;
  margin-bottom: 6px;
}
.sd-progress-track {
  width: 100%;
  height: 6px;
  background: #1e293b;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}
.sd-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #0369a1, #38bdf8);
  border-radius: 3px;
  transition: width 0.25s ease;
  min-width: 4px;
}
.sd-progress-info {
  font-size: 0.75rem;
  color: #64748b;
  font-family: monospace;
}

/* ── Device card ── */
.device-card {
  background: #0f172a;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid #1e293b;
}
.device-card.offline { opacity: 0.65; }

.device-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.device-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.device-id { font-weight: bold; font-size: 0.95rem; }
.device-addr { color: #64748b; font-family: monospace; font-size: 0.8rem; }

.device-badge {
  font-size: 0.7rem;
  font-weight: bold;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.05em;
}
.device-badge.online { background: rgba(34,197,94,0.15); color: #22c55e; }
.device-badge.offline { background: rgba(239,68,68,0.12); color: #ef4444; }

/* ── Sensor grid ── */
.sensor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.sensor-item {
  background: #1e293b;
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sensor-item.full { grid-column: 1 / -1; }
.sensor-label { font-size: 0.7rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; }
.sensor-value { font-size: 0.9rem; font-family: monospace; color: #e2e8f0; font-weight: bold; }
.value-on { color: #22c55e; }
.value-off { color: #ef4444; }
.no-data { color: #64748b; font-size: 0.85rem; padding: 8px 0; margin-bottom: 12px; }

/* ── Device actions ── */
.device-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 40px 20px; color: #475569; }
.empty-icon { font-size: 2.5rem; margin-bottom: 10px; }
.empty-sub { font-size: 0.8rem; margin-top: 6px; color: #334155; }

/* ── Commands tab ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 6px; color: #94a3b8; font-size: 0.85rem; }
select {
  background: #0f172a;
  color: #f1f5f9;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.85rem;
  width: 100%;
  max-width: 320px;
}
.command-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.cmd-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 10px;
  border-radius: 10px;
  background: #334155;
  font-size: 0.82rem;
  min-height: 70px;
}
.cmd-btn:hover:not(:disabled) { background: #2563eb; }
.cmd-btn.green { background: #166534; }
.cmd-btn.green:hover:not(:disabled) { background: #15803d; }
.cmd-btn.red { background: #7f1d1d; }
.cmd-btn.red:hover:not(:disabled) { background: #991b1b; }
.cmd-icon { font-size: 1.3rem; }

/* ── Upload tab ── */
.info-box {
  background: #0f172a;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
}
.info-label { color: #64748b; font-size: 0.85rem; }
.info-value { font-family: monospace; font-size: 0.85rem; color: #e2e8f0; }

.upload-area {
  border: 2px dashed #334155;
  border-radius: 10px;
  padding: 30px 20px;
  text-align: center;
  margin-bottom: 14px;
  transition: border-color 0.2s;
}
.upload-area.dragover { border-color: #2563eb; background: rgba(37,99,235,0.05); }
.upload-icon { font-size: 2rem; margin-bottom: 8px; }
.upload-hint { color: #64748b; font-size: 0.85rem; margin-bottom: 14px; }
.file-label {
  display: inline-block;
  background: #334155;
  color: white;
  padding: 8px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.file-label:hover { background: #2563eb; }
.file-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #0f172a;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.file-preview-icon { font-size: 1.5rem; }
.file-name { font-weight: bold; font-size: 0.9rem; }
.file-size { color: #64748b; font-size: 0.8rem; margin-top: 2px; }
.upload-btn { background: #15803d; }
.upload-btn:hover:not(:disabled) { background: #166534; }
.upload-progress {
  width: 100%;
  height: 6px;
  background: #334155;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 10px;
  display: none;
}
.upload-progress-bar {
  height: 100%;
  background: #2563eb;
  width: 0%;
  transition: width 0.3s;
  border-radius: 3px;
}

/* ── Panel Hasil Perintah ── */
.cmd-result-card {
  background: #0f172a;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  border-left: 4px solid #2563eb;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cmd-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.cmd-result-title {
  font-weight: bold;
  font-size: 0.85rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.cmd-result-time {
  font-size: 0.75rem;
  color: #475569;
  font-family: monospace;
}

.r-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.r-item {
  background: #1e293b;
  border-radius: 8px;
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.r-item.full { grid-column: 1 / -1; }

.r-label {
  font-size: 0.68rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.r-value {
  font-size: 0.92rem;
  font-family: monospace;
  color: #e2e8f0;
  font-weight: bold;
  word-break: break-all;
}

.rv-ok   { color: #22c55e; }
.rv-fail { color: #ef4444; }
.rv-on   { color: #22c55e; }
.rv-off  { color: #f87171; }

/* ── SD key input row ── */
.sd-key-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.sd-key-row label { color: #94a3b8; font-size: 0.85rem; white-space: nowrap; }
.sd-key-row input {
  background: #0f172a; color: #f1f5f9;
  border: 1px solid #334155; border-radius: 6px;
  padding: 6px 10px; font-size: 0.85rem; flex: 1; max-width: 240px;
}

/* ── SET CONFIG form ── */
.cfg-form { display: flex; flex-direction: column; gap: 10px; }
.cfg-row  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cfg-row label { color: #94a3b8; font-size: 0.82rem; min-width: 160px; }
.cfg-row input, .cfg-row select {
  background: #0f172a; color: #f1f5f9;
  border: 1px solid #334155; border-radius: 6px;
  padding: 6px 10px; font-size: 0.82rem; width: 160px;
}
.cfg-hint { color: #475569; font-size: 0.75rem; }
.cfg-note { color: #f59e0b; font-size: 0.8rem; margin-top: 4px; }
.cfg-apply-btn {
  align-self: flex-start; margin-top: 6px;
  background: #7c3aed; padding: 8px 20px;
}
.cfg-apply-btn:hover { background: #6d28d9; }

/* ── SD file list ── */
.sd-file-list { display: flex; flex-direction: column; gap: 6px; }
.sd-file-item {
  display: flex; align-items: center; justify-content: space-between;
  background: #1e293b; border-radius: 8px; padding: 8px 12px;
}
.sd-file-info { display: flex; flex-direction: column; gap: 2px; }
.sd-file-name { font-family: monospace; font-size: 0.85rem; color: #e2e8f0; }
.sd-file-size { font-size: 0.75rem; color: #64748b; }
.sd-dl-btn    { background: #0369a1; padding: 5px 14px; font-size: 0.8rem; }
.sd-dl-btn:hover { background: #0284c7; }

/* ── SD file manager (breadcrumb & folder) ── */
.sd-breadcrumb {
  display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
  margin-bottom: 8px; font-size: 0.8rem;
}
.sd-crumb-link {
  color: #38bdf8; cursor: pointer; padding: 2px 4px; border-radius: 4px;
}
.sd-crumb-link:hover { background: #1e293b; text-decoration: underline; }
.sd-crumb-current { color: #94a3b8; padding: 2px 4px; }
.sd-crumb-sep { color: #475569; }

.sd-dir-item { cursor: pointer; }
.sd-dir-item:hover { background: #263449; }

.r-sep {
  color: #475569;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  padding: 6px 0 2px;
  border-top: 1px solid #1e293b;
  margin-top: 2px;
}

.r-placeholder {
  color: #475569;
  font-size: 0.85rem;
  padding: 6px 0;
  font-style: italic;
}

/* ── SD filter row ── */
.sd-filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.sd-filter-input {
  background: #0f172a;
  color: #f1f5f9;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.82rem;
  flex: 1;
  min-width: 130px;
}
.sd-date-input {
  background: #0f172a;
  color: #f1f5f9;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.8rem;
  width: 128px;
  color-scheme: dark;
}
.sd-date-sep {
  color: #475569;
  font-size: 0.8rem;
  white-space: nowrap;
}
.sd-reset-btn {
  background: #334155;
  padding: 5px 10px;
  font-size: 0.78rem;
  color: #94a3b8;
  flex-shrink: 0;
}
.sd-reset-btn:hover:not(:disabled) { background: #475569; color: #f1f5f9; }

/* ── SD pagination ── */
.sd-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #1e293b;
}
.sd-page-btn {
  background: #1e293b;
  padding: 4px 14px;
  font-size: 0.8rem;
}
.sd-page-btn:hover:not(:disabled) { background: #334155; }
.sd-page-info {
  color: #64748b;
  font-size: 0.8rem;
}
.sd-page-info-sm {
  display: block;
  text-align: center;
  color: #64748b;
  font-size: 0.8rem;
  border-top: 1px solid #1e293b;
  padding-top: 8px;
  margin-top: 8px;
}

/* ── Profile badge on device card ── */
.prof-badge {
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(99,102,241,0.18);
  color: #a5b4fc;
  font-family: monospace;
}
.prof-badge.unknown {
  background: rgba(100,116,139,0.15);
  color: #64748b;
}

/* ── Relay quick selector in device card ── */
.relay-sel {
  background: #0f172a;
  color: #f1f5f9;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.8rem;
  width: auto;
  max-width: 72px;
}

/* ── Profile tab ── */
.prof-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.prof-header-title {
  font-weight: bold;
  color: #94a3b8;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
}
.prof-header-actions {
  display: flex;
  gap: 8px;
}

/* Profile list */
.prof-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #0f172a;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  border: 1px solid #1e293b;
  gap: 10px;
  flex-wrap: wrap;
}
.prof-item-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.prof-item-name {
  font-weight: bold;
  font-family: monospace;
  font-size: 0.92rem;
  color: #e2e8f0;
}
.prof-prefix-chip {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(37,99,235,0.18);
  color: #93c5fd;
  font-family: monospace;
}
.prof-tag-count {
  font-size: 0.72rem;
  color: #64748b;
}
.prof-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Profile editor */
.prof-editor-form {
  background: #0f172a;
  border-radius: 10px;
  padding: 16px;
  margin-top: 14px;
  border: 1px solid #334155;
}
.prof-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-weight: bold;
  color: #7dd3fc;
  font-size: 0.9rem;
}

/* Tags table */
.prof-tags-section {
  margin-top: 16px;
}
.prof-tags-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  color: #94a3b8;
  font-size: 0.82rem;
  font-weight: bold;
}
.prof-tags-scroll {
  overflow-x: auto;
  border-radius: 8px;
}
.prof-tags-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.prof-tags-table th {
  background: #1e293b;
  color: #64748b;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 7px 10px;
  text-align: left;
  white-space: nowrap;
}
.prof-tags-table td {
  padding: 5px 6px;
  vertical-align: middle;
  border-bottom: 1px solid #1e293b;
}
.ptf {
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 5px;
  padding: 5px 7px;
  font-size: 0.8rem;
  font-family: monospace;
  width: 100%;
  min-width: 55px;
}
.ptf:focus { outline: 1px solid #2563eb; }
.ptf-type  { min-width: 90px; }
.ptf-scale { min-width: 60px; }
.ptf-unit  { min-width: 50px; }

.prof-editor-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}
