/* ─── COMPONENTS: Cards, tables, badges, buttons, forms, modals, toast ─── */

/* ─── Stat Cards ─── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s var(--transition);
}

.stat:hover {
  border-color: rgba(255,255,255,0.08);
}

.stat::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
}

.stat.s-green::before { background: var(--green); }
.stat.s-red::before { background: var(--red); }
.stat.s-blue::before { background: var(--brand); }
.stat.s-yellow::before { background: var(--yellow); }
.stat.s-cyan::before { background: var(--cyan); }
.stat.s-purple::before { background: var(--purple); }
.stat.s-orange::before { background: var(--orange); }

.stat-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1.5px;
  line-height: 1;
}

.stat-label {
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
  font-weight: 500;
}

/* ─── Sections / Cards ─── */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  animation: fadeIn 0.3s var(--transition) forwards;
}

.section h2 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section h2 .subtitle {
  font-weight: 400;
  color: var(--text3);
  font-size: 11px;
}

/* ─── Tables ─── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  user-select: none;
}

th.sortable {
  cursor: pointer;
  transition: color 0.15s;
}

th.sortable:hover {
  color: var(--text2);
}

th.sortable::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 4px;
  vertical-align: middle;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-top: 4px solid var(--text3);
  opacity: 0.3;
}

th.sort-asc::after {
  border-top: none;
  border-bottom: 4px solid var(--brand);
  opacity: 1;
}

th.sort-desc::after {
  border-top: 4px solid var(--brand);
  opacity: 1;
}

td {
  padding: 7px 12px;
  border-bottom: 1px solid rgba(30,41,59,0.3);
  vertical-align: middle;
}

tr {
  transition: background 0.15s;
}

tr:hover {
  background: rgba(30,41,59,0.3);
}

tbody tr:last-child td {
  border-bottom: none;
}

.cell-strong {
  font-weight: 600;
  color: var(--text);
}

.cell-muted {
  color: var(--text3);
  font-size: 11px;
}

.empty {
  color: var(--text3);
  font-size: 12px;
  text-align: center;
  padding: 40px 20px;
}

/* ─── Badges ─── */
.badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  display: inline-block;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.badge-green { background: rgba(74,222,128,0.12); color: var(--green); }
.badge-red { background: rgba(248,113,113,0.12); color: var(--red); }
.badge-yellow { background: rgba(251,191,36,0.12); color: var(--yellow); }
.badge-blue { background: rgba(59,130,246,0.12); color: var(--brand); }
.badge-purple { background: rgba(167,139,250,0.12); color: var(--purple); }
.badge-cyan { background: rgba(34,211,238,0.12); color: var(--cyan); }
.badge-orange { background: rgba(251,146,60,0.12); color: var(--orange); }
.badge-gray { background: rgba(100,116,139,0.12); color: var(--text3); }

/* ─── Buttons ─── */
.btn {
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  font-family: inherit;
  line-height: 1.2;
}

.btn:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand2); }

.btn-green {
  background: rgba(74,222,128,0.12);
  color: var(--green);
  border: 1px solid rgba(74,222,128,0.2);
}
.btn-green:hover { background: rgba(74,222,128,0.2); }

.btn-red {
  background: rgba(248,113,113,0.12);
  color: var(--red);
  border: 1px solid rgba(248,113,113,0.2);
}
.btn-red:hover { background: rgba(248,113,113,0.2); }

.btn-yellow {
  background: rgba(251,191,36,0.12);
  color: var(--yellow);
  border: 1px solid rgba(251,191,36,0.2);
}

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

.btn-sm { padding: 3px 10px; font-size: 10px; border-radius: 6px; }
.btn-lg { padding: 10px 24px; font-size: 14px; border-radius: var(--radius); }
.btn-icon { padding: 5px 8px; }

.btn-group {
  display: flex;
  gap: 6px;
}

/* ─── Forms & Inputs ─── */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input, .select {
  width: 100%;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s var(--transition);
  font-family: inherit;
}

.input:focus, .select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

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

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
}

.input-error {
  border-color: var(--red) !important;
}

.form-error {
  font-size: 11px;
  color: var(--red);
  margin-top: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}

/* ─── Search ─── */
.search {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px 8px 34px;
  font-size: 12px;
  color: var(--text);
  width: 100%;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s var(--transition);
  font-family: inherit;
}

.search:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.search::placeholder {
  color: var(--text3);
}

.search-wrapper {
  position: relative;
}

.search-wrapper svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text3);
  pointer-events: none;
}

/* ─── Toolbar (search + filter row) ─── */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar .search-wrapper {
  flex: 1;
  min-width: 200px;
}

.toolbar .search {
  margin-bottom: 0;
}

.toolbar .select {
  width: auto;
  min-width: 160px;
}

/* ─── Modal ─── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s var(--transition) forwards;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s var(--transition) forwards;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: all 0.15s;
  line-height: 0;
}

.modal-close:hover {
  background: var(--surface2);
  color: var(--text);
}

.modal-close svg {
  width: 18px;
  height: 18px;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ─── Toast ─── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 13px;
  color: var(--text);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.35s var(--transition);
  pointer-events: auto;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success { border-color: rgba(74,222,128,0.3); }
.toast.error { border-color: rgba(248,113,113,0.3); }
.toast.info { border-color: rgba(59,130,246,0.3); }

/* ─── Spinner ─── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}

.spinner-lg {
  width: 28px;
  height: 28px;
  border-width: 3px;
}

.spinner-brand {
  border-color: rgba(59,130,246,0.2);
  border-top-color: var(--brand);
}

.loading-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  flex-direction: column;
  gap: 12px;
}

.loading-center span {
  color: var(--text3);
  font-size: 12px;
}

/* ─── Login page ─── */
.login-page {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 60% at 50% -20%, rgba(59,130,246,0.15), transparent),
    radial-gradient(ellipse 60% 50% at 80% 50%, rgba(139,92,246,0.08), transparent),
    radial-gradient(ellipse 50% 40% at 10% 90%, rgba(34,211,238,0.06), transparent);
  z-index: 9999;
  padding: 20px;
}
.login-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h60v60H0z' fill='none'/%3E%3Cpath d='M30 0v60M0 30h60' stroke='%23ffffff' stroke-opacity='0.02' stroke-width='1'/%3E%3C/svg%3E");
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: rgba(17,24,39,0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 48px 40px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.03) inset;
  animation: slideUp 0.5s var(--transition) forwards;
  position: relative;
}
.login-card::before {
  content: '';
  position: absolute;
  top: 0; left: 20%; right: 20%; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(59,130,246,0.5), transparent);
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 36px;
}

.login-logo .logo-icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 24px;
  color: white;
  margin-bottom: 16px;
  box-shadow: 0 8px 32px rgba(59,130,246,0.3);
}

.login-logo h2 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}

.login-logo p {
  font-size: 13px;
  color: var(--text3);
  margin-top: 6px;
}

.login-error {
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--red);
  margin-bottom: 16px;
  display: none;
}
.login-error.visible {
  display: block;
  animation: fadeIn 0.2s var(--transition) forwards;
}

.login-card .form-group {
  margin-bottom: 20px;
}
.login-card .form-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text2);
  margin-bottom: 6px;
}
.login-card .input {
  padding: 12px 16px;
  font-size: 14px;
  background: rgba(15,23,42,0.6);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  transition: all 0.2s;
}
.login-card .input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
  background: rgba(15,23,42,0.9);
}

.login-card .btn-primary {
  width: 100%;
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
  margin-top: 8px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  box-shadow: 0 4px 16px rgba(59,130,246,0.3);
  transition: all 0.2s;
}
.login-card .btn-primary:hover {
  box-shadow: 0 6px 24px rgba(59,130,246,0.4);
  transform: translateY(-1px);
}

.login-footer {
  text-align: center;
  margin-top: 28px;
  font-size: 11px;
  color: var(--text3);
  line-height: 1.6;
}

/* ─── Page container ─── */
.page {
  display: none;
}

.page.active {
  display: block;
  animation: fadeIn 0.25s var(--transition) forwards;
}

/* ─── Status indicator in tables ─── */
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}

.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: var(--red); }
.status-dot.idle { background: var(--yellow); }

/* ─── Responsive table wrapper ─── */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ─── Info grid (key-value pairs) ─── */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.info-grid .info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(30,41,59,0.3);
}

.info-grid .info-row:last-child {
  border-bottom: none;
}

.info-label {
  font-size: 12px;
  color: var(--text3);
}

.info-value {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}
