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

:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --border:   #30363d;
  --text:     #c9d1d9;
  --muted:    #8b949e;
  --green:    #2ea043;
  --green-h:  #3fb950;
  --red:      #da3633;
  --yellow:   #d29922;
  --blue:     #388bfd;
  --radius:   8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */
.dashboard-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: calc(100vh - 52px);
}
.dashboard-main {
  min-width: 0;
}
.device-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: calc(100vh - 52px);
  position: sticky;
  top: 52px;
  align-self: start;
  z-index: 92;
  transition: transform .2s ease, opacity .2s ease;
}
.device-sidebar-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.device-sidebar-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.device-sidebar-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.device-sidebar-close {
  display: none;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
}
.device-sidebar-close::before {
  content: '×';
}
.device-sidebar-close:hover {
  border-color: var(--green);
  color: var(--green-h);
}
.sidebar-toggle-btn {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  margin-right: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s, color .15s;
}
.sidebar-toggle-btn:hover {
  border-color: var(--green);
  color: var(--green-h);
}
.sidebar-toggle-btn::before {
  content: '‹';
}
body.device-sidebar-collapsed .dashboard-shell {
  grid-template-columns: minmax(0, 1fr);
}
body.device-sidebar-collapsed .device-sidebar {
  display: none;
}
body.device-sidebar-collapsed .sidebar-toggle-btn::before {
  content: '☰';
}
.container {
  padding: 24px 24px;
}
.container.wide {}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .icon { font-size: 18px; }

/* ── Logo / Header ── */
.logo {
  text-align: center;
  padding: 40px 0 32px;
}
.logo h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--green-h);
}
.logo p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ── Form ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}
.form-input:focus { border-color: var(--blue); }
.form-input.mono { font-family: 'Consolas', monospace; letter-spacing: 1px; text-transform: uppercase; }
.username-field {
  position: relative;
}
.username-field .form-input {
  padding-right: 42px;
}
.username-generate-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  height: 30px;
  width: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.username-generate-btn::before { content: '↻'; }
.username-generate-btn.loading::before { content: '…'; }
.username-generate-btn:hover:not(:disabled) {
  background: var(--border);
}
.username-generate-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
}
.password-field {
  position: relative;
}
.password-field .form-input {
  padding-right: 42px;
}
.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.password-toggle:hover {
  background: var(--border);
  color: var(--text);
}
.field-hint {
  min-height: 16px;
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
}
.field-hint:empty {
  min-height: 0;
  margin-top: 0;
}
.field-hint.ok { color: var(--green-h); }
.field-hint.error { color: #f85149; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .2s, background .2s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--green-h); }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: .85; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Alert / Toast ── */
.alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.alert.show { display: block; }
.alert-error   { background: rgba(218,54,51,.15); border: 1px solid rgba(218,54,51,.4); color: #f85149; }
.alert-success { background: rgba(46,160,67,.15);  border: 1px solid rgba(46,160,67,.4);  color: var(--green-h); }
.alert-info    { background: rgba(56,139,253,.15); border: 1px solid rgba(56,139,253,.4); color: var(--blue); }

/* ── Toast popup ── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(8px);
  transition: all .25s;
  pointer-events: none;
  z-index: 999;
}
#toast.show {
  opacity: 1;
  transform: translateY(0);
}
#toast.success { background: var(--green);  color: #fff; }
#toast.error   { background: var(--red);    color: #fff; }
#toast.info    { background: #1c2128; border: 1px solid var(--border); color: var(--text); }
#formToast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(320px, calc(100vw - 36px));
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 220;
}
#formToast.show {
  opacity: 1;
  transform: translateY(0);
}
#formToast.error {
  border-color: rgba(218,54,51,.4);
  color: #f85149;
}
#formToast.success {
  border-color: rgba(46,160,67,.4);
  color: var(--green-h);
}

/* ── Navbar ── */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--green-h);
  letter-spacing: 1.5px;
}
.navbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.navbar-email { color: var(--muted); font-size: 12px; }

/* ── Badge / Pill ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green  { background: rgba(46,160,67,.2);   color: var(--green-h); }
.badge-yellow { background: rgba(210,153,34,.2);  color: var(--yellow); }
.badge-red    { background: rgba(218,54,51,.2);   color: #f85149; }
.badge-muted  { background: var(--border);         color: var(--muted); }

/* ── Info row ── */
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.info-row:last-child { border-bottom: none; padding-bottom: 0; }
.info-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.info-value { font-weight: 500; font-size: 14px; }
.info-value.mono { font-family: 'Consolas', monospace; }

/* ── Grid dua kolom ── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }

/* ── Divider / section ── */
.section-sep {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 16px 0;
  position: relative;
}
.section-sep::before,
.section-sep::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 42%;
  height: 1px;
  background: var(--border);
}
.section-sep::before { left: 0; }
.section-sep::after  { right: 0; }

/* ── Status dot ── */
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}
.dot-green  { background: var(--green-h); box-shadow: 0 0 6px var(--green-h); }
.dot-red    { background: #f85149; }
.dot-muted  { background: var(--border); }

/* ── Link toggle ── */
.link-toggle { cursor: pointer; font-size: 13px; color: var(--blue); background: none; border: none; padding: 0; }
.link-toggle:hover { text-decoration: underline; }

/* ── Loading spinner ── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--green-h);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Device Sidebar List ── */
.device-bar {
  max-height: calc(100vh - 114px);
  overflow-y: auto;
  scrollbar-width: thin;
}
.device-bar-inner {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}
.device-pill {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all .15s;
  white-space: nowrap;
}
.device-pill:hover { border-color: var(--green); color: var(--text); }
.device-pill.active { border-color: var(--green-h); background: rgba(63,185,80,.1); color: var(--green-h); }
.device-pill .pill-callsign { font-family: 'Consolas', monospace; font-size: 11px; font-weight: 700; }
.device-pill .pill-name { color: inherit; opacity: .75; }
.device-pill .pill-sep { margin: 0 4px; opacity: .4; }
.device-pill .pill-no-callsign { opacity: .45; font-size: 11px; font-style: italic; }
.device-pill-info {
  padding: 9px 10px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  cursor: default;
  font-size: 11px;
}

/* ── Tab Bar ── */
.tab-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px;
  z-index: 90;
}
.tab-bar-inner {
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 0;
  min-height: 40px;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: 12px 16px;
  transition: color .15s, border-color .15s;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--green-h); border-bottom-color: var(--green-h); }

/* ── Data Table ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(48,54,61,.5);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: rgba(48,54,61,.3); }
.mono-key { font-family: 'Consolas', monospace; font-size: 12px; color: var(--muted); }

/* ── Stat Cards ── */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (max-width: 700px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 400px) { .grid-4 { grid-template-columns: 1fr; } }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.stat-value { font-size: 18px; font-weight: 600; color: var(--text); }

/* ── Backup Table ── */
.backup-row-rp td { background: rgba(63,185,80,.05); }
.backup-row-rp:hover td { background: rgba(63,185,80,.1) !important; }

/* ── Track Filter Bar ── */
.track-filter-btn {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  transition: all .15s;
  white-space: nowrap;
}
.track-filter-btn:hover { border-color: var(--green); color: var(--text); }
.track-filter-btn.active { border-color: var(--green-h); background: rgba(63,185,80,.1); color: var(--green-h); }

@media (max-width: 800px) {
  .dashboard-shell {
    display: block;
    min-height: calc(100vh - 52px);
  }
  body:not(.device-sidebar-collapsed)::before {
    content: '';
    position: fixed;
    left: 0;
    right: 0;
    top: 52px;
    bottom: 0;
    background: rgba(1,4,9,.55);
    z-index: 91;
  }
  .device-sidebar {
    position: fixed;
    left: 0;
    top: 52px;
    bottom: 0;
    width: min(82vw, 300px);
    min-height: 0;
    box-shadow: 20px 0 40px rgba(0,0,0,.35);
  }
  .device-sidebar-close {
    display: inline-flex;
  }
  body.device-sidebar-collapsed .device-sidebar {
    display: block;
    transform: translateX(-105%);
    opacity: 0;
    pointer-events: none;
  }
  .tab-bar {
    top: 52px;
  }
}
