/* ═══════════════════════════════════════════
   COMPONENTS.CSS — Reusable UI Components
   ═══════════════════════════════════════════ */

/* ── Card ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.card-title {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 1rem;
}

/* ── Metric Cards ── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.metric-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.metric-label {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.5rem;
}

.metric-value {
  font-size: 30px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -1px;
}

.metric-sub {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--mono);
  margin-top: 4px;
}

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-family: var(--mono);
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 6px;
}

.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-amber  { background: var(--amber-bg);  color: var(--amber); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-blue   { background: rgba(61,154,255,0.1); color: var(--accent); }
.badge-teal   { background: rgba(0,212,212,0.1);  color: var(--teal); }
.badge-purple { background: rgba(167,139,250,0.1); color: var(--purple); }

/* ── Status Dot ── */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot-green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-amber { background: var(--amber); }
.dot-gray  { background: var(--text3); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--display);
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-primary            { background: var(--accent); color: #000; }
.btn-primary:hover      { background: #5ab0ff; }

.btn-secondary          { background: var(--bg3); color: var(--text); border: 1px solid var(--border2); }
.btn-secondary:hover    { background: var(--bg4); }

.btn-danger             { background: var(--red-bg); color: var(--red); border: 1px solid rgba(255,77,106,0.2); }
.btn-danger:hover       { background: rgba(255,77,106,0.15); }

.btn-ghost              { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover        { background: var(--bg3); color: var(--text); }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 11px; }
.btn-lg { padding: 0.85rem 1.75rem; font-size: 15px; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  padding: 0.4rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.btn-icon:hover { color: var(--text); border-color: var(--border2); }
.btn-icon svg   { width: 14px; height: 14px; }

/* ── Form Elements ── */
.form-grid        { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid.single { grid-template-columns: 1fr; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.span2 { grid-column: span 2; }

label {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input,
select,
textarea {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus { border-color: var(--accent); }

input::placeholder { color: var(--text3); }

select option { background: var(--bg3); }

textarea { resize: vertical; min-height: 80px; }

/* ── Alert ── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 1rem;
}

.alert-info    { background: rgba(61,154,255,0.08);  border: 1px solid rgba(61,154,255,0.2);  color: #7bbcff; }
.alert-success { background: var(--green-bg);         border: 1px solid rgba(30,217,122,0.2);  color: var(--green); }
.alert-warning { background: var(--amber-bg);         border: 1px solid rgba(245,166,35,0.2);  color: var(--amber); }
.alert-danger  { background: var(--red-bg);           border: 1px solid rgba(255,77,106,0.2);  color: var(--red); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(99, 160, 255, 0.06);
  color: var(--text2);
}

tbody tr:hover td { background: rgba(61, 154, 255, 0.03); }
tbody tr:last-child td { border-bottom: none; }

.td-mono { font-family: var(--mono); font-size: 12px; }
.td-center { text-align: center; }

/* ── Tabs ── */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.tab {
  padding: 0.65rem 1.25rem;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
}

.tab.active         { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover:not(.active) { color: var(--text2); }

.tab-panel          { display: none; }
.tab-panel.active   { display: block; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 14, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 2rem;
  width: 520px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 1.5rem;
  color: var(--text);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 9999;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1.25rem;
  font-size: 13px;
  color: var(--text);
  max-width: 300px;
  display: none;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.toast.show    { display: flex; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }

/* ── Device Cards ── */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.device-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.device-card:hover {
  border-color: var(--border2);
  background: var(--bg3);
  transform: translateY(-1px);
}

.device-card.online { border-color: rgba(30, 217, 122, 0.2); }

.device-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.device-card-name { font-size: 15px; font-weight: 700; color: var(--text); }
.device-card-id   { font-size: 10px; font-family: var(--mono); color: var(--text3); margin-top: 2px; }

.device-values { display: flex; flex-direction: column; gap: 6px; margin-top: 0.75rem; }

.device-value-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dv-name { font-size: 11px; font-family: var(--mono); color: var(--text3); }
.dv-val  { font-size: 13px; font-family: var(--mono); color: var(--text); font-weight: 500; }
.dv-val.live { color: var(--teal); }

.device-footer {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.device-ts { font-size: 10px; font-family: var(--mono); color: var(--text3); }

/* ── Value Schema Chips ── */
.value-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 0.75rem; min-height: 40px; }

.value-chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.vc-name   { font-size: 11px; color: var(--text2); font-family: var(--mono); }
.vc-type   { font-size: 10px; color: var(--text3); background: var(--bg4); padding: 1px 6px; border-radius: 4px; font-family: var(--mono); }
.vc-unit   { font-size: 10px; color: var(--teal); font-family: var(--mono); }
.vc-remove { cursor: pointer; color: var(--text3); font-size: 16px; line-height: 1; transition: color 0.1s; }
.vc-remove:hover { color: var(--red); }

/* ── Latest Value Cards (Monitor) ── */
.latest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.latest-val-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  text-align: center;
}

.lvc-label { font-size: 10px; font-family: var(--mono); color: var(--text3); text-transform: uppercase; letter-spacing: 0.5px; }
.lvc-value { font-size: 26px; font-weight: 800; color: var(--teal); letter-spacing: -1px; margin: 6px 0 2px; }
.lvc-type  { font-size: 10px; font-family: var(--mono); color: var(--text3); }
.lvc-ts    { font-size: 9px; font-family: var(--mono); color: var(--text3); margin-top: 4px; }

/* ── Device Pills (Monitor selector) ── */
.device-select-bar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.device-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.4rem 1rem;
  border-radius: 30px;
  background: var(--bg3);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  color: var(--text2);
  transition: all 0.15s;
}

.device-pill.active {
  background: rgba(61, 154, 255, 0.12);
  border-color: rgba(61, 154, 255, 0.35);
  color: var(--accent);
}

.device-pill:hover:not(.active) { border-color: var(--border2); color: var(--text); }

/* ── Chart Container ── */
.chart-wrap { position: relative; width: 100%; }

/* ── Auth Tabs ── */
.auth-tabs {
  display: flex;
  background: var(--bg3);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 1.5rem;
  gap: 4px;
}

.auth-tab {
  flex: 1;
  text-align: center;
  padding: 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text3);
  transition: all 0.15s;
}

.auth-tab.active { background: var(--bg2); color: var(--text); }

.auth-form { display: flex; flex-direction: column; gap: 1rem; }

/* ── Publish Grid ── */
.publish-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.publish-field { display: flex; flex-direction: column; gap: 6px; }
.publish-field label { font-size: 10px; font-family: var(--mono); color: var(--text3); text-transform: uppercase; }
