* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f1f5f9;
  color: #1e293b;
}

/* Login */
/* Xếp dọc: form đăng nhập trên, khối tải tiện ích ngay dưới, cùng bề ngang */
.login-wrap {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; padding: 32px 16px;
}
.login-box {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px;
  padding: 32px; width: 360px; max-width: 100%; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.06);
}
.login-box .logo { font-size: 40px; }
.login-box h1 { margin: 8px 0 2px; font-size: 20px; }
.login-box .sub { margin: 0 0 20px; font-size: 12px; color: #64748b; }
.login-box input {
  width: 100%; padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; outline: none;
}
.login-box input:focus { border-color: #0284c7; }
.login-box button {
  width: 100%; padding: 10px; background: #0284c7; color: #fff;
  border: none; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.login-box button:hover { background: #0369a1; }
.error { color: #dc2626; font-size: 12.5px; margin-top: 10px; min-height: 16px; }

/* Dashboard */
.dashboard { max-width: 1000px; margin: 0 auto; padding: 24px 16px 60px; }
header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
header h1 { font-size: 20px; margin: 0; }
header h1 span { font-size: 13px; font-weight: 400; color: #64748b; margin-left: 8px; }
.btn-outline {
  background: #fff; border: 1px solid #cbd5e1; border-radius: 8px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; color: #475569; cursor: pointer;
}
.btn-outline:hover { border-color: #0284c7; color: #0284c7; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tabs button {
  padding: 9px 16px; border: none; background: #fff; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; color: #475569; cursor: pointer;
  border: 1px solid #e2e8f0;
}
.tabs button.active { background: #0284c7; color: #fff; border-color: #0284c7; }

.panel {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 16px; margin-bottom: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 14px; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.form-row input, .form-row select {
  flex: 1; min-width: 140px; padding: 9px 11px;
  border: 1px solid #cbd5e1; border-radius: 8px; font-size: 13px; outline: none;
}
.form-row input:focus, .form-row select:focus { border-color: #0284c7; }
.form-row .field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
.form-row .field label { font-size: 11.5px; font-weight: 600; color: #475569; }
.form-row .field input, .form-row .field select { width: 100%; flex: none; }
.form-row .field-btn { flex: 0 0 auto; min-width: 0; }
.form-hint { font-size: 11.5px; color: #64748b; margin: 10px 0 0; }
.btn-primary {
  background: #0284c7; color: #fff; border: none; border-radius: 8px;
  padding: 9px 18px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: #0369a1; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 12px 16px; display: flex; align-items: center; gap: 12px;
}
.item .info { flex: 1; min-width: 0; }
.item .info .title { font-weight: 600; font-size: 13.5px; }
.item .info .desc { font-size: 11.5px; color: #64748b; margin-top: 2px; }
.badge { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 8px; }
.badge.ok { background: #d1fae5; color: #059669; }
.badge.revoked { background: #fee2e2; color: #dc2626; }
.badge.expired { background: #fef3c7; color: #b45309; }

.btn-sm {
  border: 1px solid #cbd5e1; background: #fff; border-radius: 7px;
  padding: 5px 10px; font-size: 11.5px; font-weight: 600; cursor: pointer; color: #475569;
}
.btn-sm:hover { border-color: #0284c7; color: #0284c7; }
.btn-sm.danger { color: #dc2626; }
.btn-sm.danger:hover { border-color: #dc2626; color: #dc2626; }

.newkey {
  background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 10px;
  padding: 14px 16px; margin-bottom: 16px;
}
.newkey .label { font-size: 11.5px; font-weight: 700; color: #059669; margin-bottom: 6px; }
.newkey .key { font-family: monospace; font-size: 16px; font-weight: 700; letter-spacing: 1px; word-break: break-all; }
.newkey .hint { font-size: 11px; color: #475569; margin-top: 6px; }

.empty { color: #94a3b8; font-size: 13px; text-align: center; padding: 20px; }

/* Table */
.table {
  width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid #e2e8f0; border-radius: 10px; overflow: hidden;
}
.table th, .table td {
  text-align: left; padding: 10px 12px; font-size: 12.5px;
  border-bottom: 1px solid #f1f5f9;
}
.table thead th {
  background: #f8fafc; font-size: 11px; font-weight: 700; color: #64748b;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions .btn-sm { margin-left: 4px; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  background: #fff; border-radius: 12px; padding: 20px; width: 380px; max-width: 92vw;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.modal-box h3 { margin: 0 0 12px; font-size: 15px; }
.modal-key {
  font-family: monospace; font-size: 15px; font-weight: 700; letter-spacing: 0.5px;
  word-break: break-all; background: #f8fafc; border: 1px solid #e2e8f0;
  border-radius: 8px; padding: 12px; margin-bottom: 14px;
}
.modal-key.muted { font-family: inherit; font-weight: 400; font-size: 12.5px; color: #94a3b8; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.device-full { color: #b91c1c; font-weight: 700; }

.panel-note { font-size: 12.5px; color: #64748b; margin: -4px 0 12px; line-height: 1.55; }
.env-hint {
  background: #0f172a; color: #e2e8f0; border-radius: 8px; padding: 12px;
  font-size: 12px; line-height: 1.7; overflow-x: auto; margin-top: 12px;
}
.ai-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid #e2e8f0; border-radius: 8px; margin-bottom: 8px;
}
.ai-code {
  font-size: 12px; font-weight: 800; background: #0f172a; color: #fff;
  padding: 3px 10px; border-radius: 8px;
}
.ai-meta { font-size: 12.5px; color: #475569; }
.ai-ok { color: #15803d; font-weight: 700; }
.ai-bad { color: #b91c1c; font-weight: 700; }
.ai-key-input { width: 100%; margin-top: 6px; }

.muted { color: #94a3b8; font-size: 11.5px; }
#deviceBox code { font-size: 11.5px; color: #475569; }

.order-box { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 12px; margin-bottom: 14px; }
.order-title { font-size: 12.5px; font-weight: 700; color: #0f172a; margin-bottom: 6px; }
.ai-off { opacity: 0.55; }
.ai-pos { font-size: 10.5px; font-weight: 800; background: #e0f2fe; color: #0369a1; padding: 2px 8px; border-radius: 8px; }
.ai-pos.off { background: #fee2e2; color: #b91c1c; }

.dl-box {
  width: 360px; max-width: 100%; margin: 0; background: #fff;
  border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.06);
}
.dl-title { font-size: 13.5px; font-weight: 800; color: #0f172a; margin-bottom: 10px; }
.dl-btn {
  display: block; text-align: center; text-decoration: none;
  background: #0f172a; color: #fff; border-radius: 8px;
  padding: 11px 14px; font-size: 13.5px; font-weight: 700;
}
.dl-btn:hover { background: #1e293b; }
.dl-note { font-size: 11.5px; color: #94a3b8; margin-top: 8px; text-align: center; }
.dl-steps { margin: 12px 0 0; padding-left: 20px; font-size: 12px; color: #475569; line-height: 1.75; }
.dl-steps code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; }
