/* ========== RESET CƠ BẢN ========== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", sans-serif;
  background: #04130a;
  color: #f7fdf8;
}

/* ========== KHUNG APP ========== */
.app-root {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  background: radial-gradient(circle at top, #2ecc71 0, #04130a 55%);
}

.app-container {
  width: 100%;
  max-width: 480px;           /* ưu tiên điện thoại, tablet vừa */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.4);
}

/* ========== HEADER CỐ ĐỊNH ========== */
.main-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(120deg, #27ae60, #2ecc71);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.header-left {
  flex: 1 1 auto;
  min-width: 0;
}

.app-title {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-subtitle {
  font-size: 0.75rem;
  opacity: 0.9;
}

/* Ô tìm kiếm nhỏ gọn */
.header-search {
  flex: 2 1 auto;
}

.header-search input {
  width: 100%;
  border-radius: 999px;
  border: none;
  padding: 6px 10px;
  font-size: 0.8rem;
  outline: none;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.header-search input::placeholder {
  color: rgba(255, 255, 255, 0.75);
}

/* Nút bên phải */
.header-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.icon-btn {
  border: none;
  border-radius: 999px;
  padding: 4px 7px;
  font-size: 0.9rem;
  cursor: pointer;
  background: rgba(3, 46, 16, 0.25);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.text-icon {
  font-size: 0.8rem;
}

.icon-btn:active {
  transform: scale(0.94);
  background: rgba(0, 0, 0, 0.3);
}

/* ========== DANH SÁCH THIẾT BỊ ========== */
.devices-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 8px 16px;
}

/* card khi chưa có thiết bị */
.empty-card {
  background: rgba(3, 28, 13, 0.9);
  border-radius: 12px;
  padding: 12px 14px;
  border: 1px dashed rgba(46, 204, 113, 0.8);
  text-align: center;
  color: #dfffe5;
  font-size: 0.85rem;
}

.empty-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.empty-text {
  font-size: 0.8rem;
}

/* card thiết bị */
.device-card {
  background: #06150b;
  border-radius: 14px;
  padding: 10px 8px 14px;
  margin-bottom: 10px;
  border: 1px solid rgba(39, 174, 96, 0.65);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.device-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.device-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.device-serial {
  font-size: 0.75rem;
  color: #9be7b0;
}

/* nút xoá card */
.delete-btn {
  border: none;
  background: none;
  color: #ffd1d1;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 999px;
}

.delete-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.delete-btn:active {
  transform: scale(0.9);
}

/* khung iframe */
.device-panel-wrapper {
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
}

/* iframe – panel điều khiển */
.device-panel {
  width: 100%;
  height: 520px;              /* đủ dùng trên mobile, kéo được bên trong */
  border: none;
}

/* card được highlight khi tìm kiếm */
.device-card.highlight {
  box-shadow: 0 0 0 2px #2ecc71, 0 6px 14px rgba(0, 0, 0, 0.6);
}

/* ========== MODAL THÊM THIẾT BỊ ========== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;           /* JS bật thành flex */
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 20;
}

.modal {
  width: 100%;
  max-width: 360px;
  background: #04160b;
  border-radius: 18px;
  padding: 14px 14px 16px;
  border: 1px solid #27ae60;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.7);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.modal-header h3 {
  font-size: 1rem;
}

.modal-close {
  border: none;
  background: none;
  font-size: 1.2rem;
  color: #ffffff;
  cursor: pointer;
}

/* form trong modal */
.form-group {
  margin-bottom: 10px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.form-group input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(46, 204, 113, 0.7);
  padding: 7px 9px;
  font-size: 0.85rem;
  outline: none;
  background: rgba(3, 21, 11, 0.95);
  color: #f7fff8;
}

.form-group input::placeholder {
  color: rgba(222, 255, 231, 0.75);
}

/* nút trong modal */
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.btn-secondary,
.btn-primary {
  border-radius: 999px;
  border: none;
  padding: 7px 14px;
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #e0ffe9;
}

.btn-primary {
  background: #27ae60;
  color: white;
}

.btn-secondary:active,
.btn-primary:active {
  transform: scale(0.96);
}

/* thông báo ở modal */
.message {
  margin-top: 6px;
  font-size: 0.8rem;
}

.message.error {
  color: #ffb3b3;
}

.message.success {
  color: #9cffc2;
}

/* ========== RESPONSIVE NHẸ ========== */
@media (min-width: 600px) {
  .app-container {
    max-width: 520px;
  }

  .device-panel {
    height: 560px;
  }
}
