/* ============================================================
   UNIVERSAL FORM SYSTEM (UNI CARD + FORM ELEMENTS)
   ============================================================ */
.uni-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 40px 0;
}

.uni-card {
  width: 75%;
  max-width: 1300px;
  background: var(--card-bg);
  padding: 40px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 32px;
  box-sizing: border-box;
}

.uni-title {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.uni-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Two-column layout */
.uni-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

/* Form fields */
.uni-field {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.uni-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.uni-input {
  width: 100%;
  padding: 15px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  transition: all 0.25s ease;
}

.uni-input:focus {
  border-color: var(--nav-accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(201, 166, 58, 0.28);
  outline: none;
}

.uni-info {
  font-size: 0.95rem;
  color: var(--text-muted);
}

/* Primary action button */
.uni-btn {
  width: 220px;
  padding: 15px;
  background: var(--nav-accent);
  color: #000;
  font-size: 1.1rem;
  font-weight: 600;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.25s ease;
}

.uni-btn:hover {
  background: var(--accent-dark);
}

/* Inline success/error messages */
.uni-message {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  display: none;
}

.uni-message.success {
  display: block;
  background: #e7ffee;
  color: #00662e;
  border: 1px solid #aad9b6;
}

.uni-message.error {
  display: block;
  background: #ffebeb;
  color: #a10000;
  border: 1px solid #e5b4b4;
}

/* ============================================================
   DEVICE TABLE — UNI-STYLED, CENTERED, SCROLLABLE
   ============================================================ */
.device-table-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}

.device-table {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
  text-align: center;
  background: var(--card-bg);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.device-table th {
  background: var(--surface-2);
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

.device-table td {
  padding: 14px 16px;
  font-size: 0.95rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.device-table tr:last-child td {
  border-bottom: none;
}

.device-table th,
.device-table td {
  white-space: nowrap;
  font-size: clamp(0.75rem, 1.2vw, 0.95rem);
}

/* ============================================================
   STATUS CELL — CENTERED WITH FLEX WRAPPER
   ============================================================ */
.status-cell {
  padding: 0;
  vertical-align: middle;
}

.status-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  padding: 10px 12px;
  box-sizing: border-box;
}

.device-status {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.device-status.active   { background: #0e9b78; }
.device-status.inactive { background: #5b7c99; }
.device-status.failed   { background: #d6453a; }

.current-device-icon {
  font-size: 20px;
  color: var(--nav-accent);
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.2s ease;
}

.current-device-icon:hover {
  color: var(--accent-dark);
}

/* ============================================================
   DEVICE LINK
   ============================================================ */
.device-link {
  color: var(--nav-accent);
  text-decoration: none;
  font-weight: 600;
  transition: text-decoration 0.2s ease;
}

.device-link:hover {
  text-decoration: underline;
}

/* ============================================================
   GLOBAL MODAL SYSTEM
   ============================================================ */
.global-modal {
  display: none;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 9999;
  justify-content: center;
  align-items: flex-start;
  padding: 60px 20px 20px;
  transition: opacity 0.25s ease;
}

.global-modal.show {
  display: flex;
  opacity: 1;
  pointer-events: auto;
}

.global-modal-content {
  background: #ffffff;
  padding: 25px 30px;
  border-radius: 10px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  animation: modalFadeDown 0.25s ease-out;
}

.global-modal-content h2 {
  margin: 0 0 10px 0;
  font-size: 22px;
  font-weight: 600;
  color: #222;
}

.global-modal-content p {
  margin: 10px 0;
  font-size: 16px;
  color: #444;
}

#globalErrorClose {
  margin-top: 18px;
  background: #c0392b;
  color: white;
  border: none;
  padding: 10px 22px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.2s ease;
}

#globalErrorClose:hover {
  background: #a02e25;
}

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

.global-modal-content.success {
  border-top: 6px solid #0e9b78;
}

.global-modal-content.success h2 {
  color: #0e9b78;
}

.global-modal-content.error {
  border-top: 6px solid #d6453a;
}

.global-modal-content.error h2 {
  color: #d6453a;
}

/* ============================================================
   DRAWER OVERLAY
   ============================================================ */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 998;
}

.drawer-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

body.drawer-open {
  overflow: hidden;
}

/* ============================================================
   DEVICE DRAWER — SEAMLESS, COMPACT HEADER WITH YELLOW ACCENT
   ============================================================ */
.device-drawer {
  position: fixed;
  top: 0;
  right: -40%;
  width: 40%;
  height: 100%;
  background: #ffffff;
  box-shadow: -12px 0 36px rgba(0, 0, 0, 0.25);
  z-index: 999;
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.device-drawer.active {
  right: 0;
}

/* Compact header with yellow background */
.drawer-header {
  position: relative;
  height: 56px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--nav-accent);
  color: #000;
}

#drawerTitle {
  font-size: 17px;
  font-weight: 700;
  color: #000;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  padding-right: 16px;
}

.drawer-close {
  background: none;
  border: none;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #000;
  border-radius: 6px;
  font-size: 22px;
  line-height: 1;
  transition: background 0.2s ease, transform 0.15s ease;
}

.drawer-close:hover {
  background: rgba(0, 0, 0, 0.12);
  transform: scale(1.1);
}

.drawer-close:active {
  transform: scale(0.95);
}

/* Drawer content */
.drawer-content {
  padding: 28px 24px 20px;
  overflow-y: auto;
  flex: 1;
  background: #ffffff;
}

.drawer-loading,
.drawer-empty,
.drawer-error {
  font-size: 14px;
  color: #6b7280;
  text-align: center;
  padding: 20px 0;
}

.drawer-error {
  color: #b91c1c;
}

/* ============================================================
   DEVICE META – CLEAN KEY-VALUE STYLE
   ============================================================ */
.device-drawer-meta {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 32px;
}

.device-meta-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}

.device-meta-item:last-of-type {
  border-bottom: none;
}

.device-meta-label {
  font-size: 14px;
  font-weight: 500;
  color: #6b7280;
}

.device-meta-value {
  font-size: 15px;
  font-weight: 600;
  color: #111827;
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
}

/* Status text */
.device-meta-status-text {
  font-weight: 600;
  text-transform: capitalize;
}

.device-meta-status-text.active   { color: #166534; }
.device-meta-status-text.inactive { color: #92400e; }
.device-meta-status-text.failed   { color: #991b1b; }

/* Current device tag */
.device-meta-current {
  font-size: 13px;
  font-weight: 600;
  color: #000;
  background: rgba(201, 166, 58, 0.3);
  padding: 4px 10px;
  border-radius: 6px;
  align-self: flex-end;
  margin-top: 8px;
}

/* ============================================================
   ACTIONS LIST – UNIFORM BUTTONS IN TABLED STYLE
   ============================================================ */
.device-actions-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 32px 0;
}

.device-action-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: #f9fafb;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  transition: all 0.2s ease;
}

.device-action-item:hover {
  background: #f1f5f9;
  border-color: #d1d5db;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.device-action-label {
  font-size: 15px;
  font-weight: 600;
  color: #111827;
}

/* Block Device – Toggle Switch */
.device-action-block .toggle-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 32px;
}

.device-action-block .toggle-input {
  opacity: 0;
  width: 0;
  height: 0;
}

.device-action-block .toggle-label {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #9ca3af;
  border-radius: 999px;
  transition: background-color 0.25s ease;
}

.device-action-block .toggle-label::before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.25s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.device-action-block .toggle-input:checked + .toggle-label {
  background-color: #dc2626;
}

.device-action-block .toggle-input:checked + .toggle-label::before {
  transform: translateX(28px);
}

/* Logout Button – Same size and style */
.device-action-logout {
  background: none;
  border: none;
  padding: 0;
  font-size: 15px;
  font-weight: 600;
  color: #dc2626;
  cursor: pointer;
  transition: color 0.2s ease;
}

.device-action-logout:hover {
  color: #b91c1c;
}

/* Disabled state for current device logout */
.device-action-item.disabled {
  opacity: 0.6;
  pointer-events: none;
}

.device-action-item.disabled .device-action-logout {
  color: #9ca3af;
  cursor: not-allowed;
}

/* ============================================================
   DIVIDER
   ============================================================ */
.device-divider {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 32px 0 24px;
}

/* ============================================================
   LOGIN HISTORY TABLE
   ============================================================ */
.device-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.device-history-table thead th {
  text-align: center;
  font-weight: 600;
  color: #374151;
  padding: 12px 8px;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
}

.device-history-table tbody td {
  padding: 10px 8px;
  color: #111827;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
  text-align: center;
}

.device-history-table tbody tr:hover {
  background: #f9fafb;
}

.device-history-table td.success {
  font-weight: 600;
  color: #166534;
}

.device-history-table td.failed {
  font-weight: 600;
  color: #991b1b;
}

/* ============================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================ */
@media (max-width: 900px) {
  .device-drawer {
    width: 100%;
    right: -100%;
  }

  .device-drawer.active {
    right: 0;
  }

  .drawer-header {
    height: 52px;
    padding: 0 16px;
  }

  #drawerTitle {
    font-size: 16px;
  }

  .uni-card {
    width: 90%;
    padding: 32px 24px;
  }

  .uni-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .device-history-table thead {
    display: none;
  }

  .device-history-table tbody tr {
    display: block;
    padding: 12px 0;
    border-bottom: 1px solid #e5e7eb;
  }

  .device-history-table tbody td {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border: none;
    text-align: right;
  }

  .device-history-table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    flex: 1;
    text-align: left;
  }
}

/* ============================================================
   SLIDEOUT HEADER NAV — CROSS-BROWSER HARDENING (EDGE FIX)
============================================================ */

/* Critical box sizing normalization (Edge fix) */
.device-drawer *,
.device-drawer *::before,
.device-drawer *::after{
  box-sizing:border-box;
}

/* Grid hardening */
.device-header-nav{
  display:grid;
  grid-template-columns:minmax(0,1fr) auto minmax(0,1fr);
  align-items:center;
  column-gap:16px;
  min-width:0;
}

/* Edge requires min-width reset on grid children */
.device-header-left,
.device-header-center,
.device-header-right{
  min-width:0;
  display:flex;
  align-items:center;
}

/* Explicit alignment (Edge sometimes ignores implicit alignment) */
.device-header-left{
  justify-content:flex-start;
}

.device-header-center{
  justify-content:center;
  text-align:center;
}

.device-header-right{
  justify-content:flex-end;
  gap:12px;
}

/* Prevent text overflow collapse */
.device-header-nav *{
  min-width:0;
  max-width:100%;
}

/* ============================================================
   FLEX FALLBACK — FOR EDGE / SAFARI GRID QUIRKS
============================================================ */

@supports not (grid-template-columns: minmax(0,1fr)){
  .device-header-nav{
    display:flex;
    align-items:center;
    justify-content:space-between;
  }

  .device-header-left,
  .device-header-center,
  .device-header-right{
    flex:1 1 0;
  }

  .device-header-center{
    justify-content:center;
  }

  .device-header-right{
    justify-content:flex-end;
  }
}
