/* ====== Miezo 設備啟用平台 共用樣式 ====== */
:root {
  --brand-primary: #0066CC;
  --brand-primary-dark: #004C99;
  --brand-primary-light: #E6F0FA;
  --brand-soft-bg: #DCE9F7;          /* 主按鈕底色：淺藍 */
  --brand-soft-bg-hover: #C7DBF1;
  --brand-accent: #00B894;
  --brand-accent-soft: #E6F7F2;
  --brand-warning: #F59E0B;
  --brand-danger: #EF4444;
  --gray-900: #1F2937;
  --gray-700: #374151;
  --gray-500: #6B7280;
  --gray-400: #9CA3AF;
  --gray-300: #D1D5DB;
  --gray-200: #E5E7EB;
  --gray-100: #F3F4F6;
  --gray-50:  #F9FAFB;
  --white: #FFFFFF;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,102,204,0.08);
  --shadow-lg: 0 12px 32px rgba(0,102,204,0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", "Helvetica Neue", sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ====== 客戶端 ====== */
.customer-app {
  min-height: 100vh;
  background: linear-gradient(180deg, var(--brand-primary-light) 0%, var(--white) 100%);
  display: flex;
  flex-direction: column;
}
.top-bar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 20px;
  color: var(--brand-primary);
  text-decoration: none;
}
.logo:hover { text-decoration: none; }
.logo-img {
  height: 44px;
  width: auto;
  display: block;
  -ms-interpolation-mode: bicubic;
}
.logo-suffix {
  font-size: 14px;
  color: var(--gray-500);
  font-weight: 500;
  border-left: 1px solid var(--gray-200);
  padding-left: 12px;
}
.logo-mark {
  width: 36px;
  height: 36px;
  background: var(--brand-primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 900;
  font-size: 18px;
}
.top-bar .help-link { color: var(--gray-500); font-size: 14px; }
.top-bar .help-link:hover { color: var(--brand-primary); }

.content-wrap {
  flex: 1;
  padding: 48px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* ====== 卡片 ====== */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 480px;
}
.card.wide { max-width: 760px; }
.card-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--brand-primary-light);
  color: var(--brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 28px;
}
.card-title {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  color: var(--brand-primary);
}
.card-desc {
  text-align: center;
  color: var(--gray-500);
  font-size: 14px;
  margin-bottom: 32px;
}

/* ====== 表單 ====== */
.form-group { margin-bottom: 20px; }
.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 8px;
}
.form-label .required { color: var(--brand-danger); margin-left: 2px; }
.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-family: inherit;
  transition: all 0.2s;
  background: var(--white);
  color: var(--gray-900);
}
.form-input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-primary-light);
}
.form-input.error {
  border-color: var(--brand-danger);
}
.form-help {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 6px;
}
.form-error {
  font-size: 12px;
  color: var(--brand-danger);
  margin-top: 6px;
  display: none;
}
.form-error.visible { display: block; }

/* ====== 按鈕 ====== */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* 主按鈕：淺藍底 + 品牌藍字（QR Lock 同款配色）*/
.btn-primary {
  background: var(--brand-soft-bg);
  color: var(--brand-primary);
  width: 100%;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-soft-bg-hover); }

/* 實心藍按鈕（保留供需要強調的場合使用）*/
.btn-solid {
  background: var(--brand-primary);
  color: var(--white);
  width: 100%;
}
.btn-solid:hover:not(:disabled) { background: var(--brand-primary-dark); }

/* 成功動作按鈕：淺綠底 + 綠字 */
.btn-success {
  background: var(--brand-accent-soft);
  color: #065F46;
}
.btn-success:hover:not(:disabled) { background: #C9F0DF; }

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}
.btn-secondary:hover { background: var(--gray-200); }
.btn-text {
  background: transparent;
  color: var(--brand-primary);
  padding: 8px 12px;
}
.btn-text:hover { background: var(--brand-primary-light); text-decoration: none; }
.btn-text.btn-gray {
  color: var(--gray-500);
  font-weight: 500;
}
.btn-text.btn-gray:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}
.btn-ghost-danger {
  background: transparent;
  color: var(--brand-danger);
  border: 1px solid var(--brand-danger);
}
.btn-ghost-danger:hover { background: #FEF2F2; }

/* ====== 設備卡片 ====== */
.device-list { display: grid; gap: 16px; }
.device-card {
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 20px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  background: var(--white);
  transition: all 0.15s;
}
.device-card:hover { border-color: var(--gray-300); box-shadow: var(--shadow-sm); }
.device-card.activated { cursor: default; }
.device-card.activated:hover { border-color: var(--gray-200); box-shadow: none; }
.device-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.device-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.device-info h4 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--gray-900);
}
.device-info .meta { font-size: 13px; color: var(--gray-500); margin-bottom: 6px; }
.device-info .address { font-size: 13px; color: var(--gray-700); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-success { background: var(--brand-accent-soft); color: #065F46; }
.badge-info    { background: var(--brand-primary-light); color: var(--brand-primary); }

/* ====== 提示 ====== */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin-bottom: 20px;
}
.alert-info    { background: var(--brand-primary-light); color: var(--brand-primary); }
.alert-success { background: var(--brand-accent-soft); color: #065F46; }
.alert-warning { background: #FEF3C7; color: #92400E; }
.alert-danger  { background: #FEE2E2; color: #991B1B; }

/* ====== 啟用成功 ====== */
.success-state { text-align: center; padding: 32px 0; }
.success-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--brand-accent);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 8px 24px rgba(0,184,148,0.32);
}
.success-detail {
  background: var(--gray-50);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin: 24px 0;
  text-align: left;
  font-size: 14px;
  color: var(--gray-700);
  border-left: 3px solid var(--brand-accent);
}

/* ====== 管理員後台 ====== */
.admin-app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
  background: var(--gray-50);
}
.admin-sidebar {
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.admin-sidebar .logo-img { height: 26px; }
.sidebar-logo { margin-bottom: 28px; display:flex; flex-direction:row; align-items:center; gap:12px; }
.sidebar-logo-top { display:flex; align-items:center; }
.sidebar-brand { display:none; }
.sidebar-subtitle { font-size:13px; font-weight:500; color:var(--gray-500); border-left:1px solid var(--gray-200); padding-left:12px; white-space:nowrap; }
.admin-sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  color: var(--gray-500);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: all 0.15s;
  text-decoration: none;
}
.nav-item:hover { background: var(--gray-100); color: var(--gray-900); text-decoration: none; }
.nav-item.active { background: var(--brand-primary-light); color: var(--brand-primary); font-weight: 600; }
.admin-sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--gray-100);
  font-size: 13px;
  color: var(--gray-500);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.admin-sidebar-footer a { color: var(--gray-400); font-size: 12px; }
.admin-sidebar-footer a:hover { color: var(--brand-danger); }
.admin-main { padding: 28px 32px; overflow: auto; }
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 20px; font-weight: 700; color: var(--gray-700); }

.search-bar {
  display: flex;
  gap: 12px;
  background: var(--white);
  padding: 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  border: 1px solid var(--gray-200);
}
.search-bar .form-input { margin: 0; }
.search-bar .btn { flex-shrink: 0; }

/* ====== 表格 ====== */
.data-table {
  background: var(--white);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}
table { width: 100%; border-collapse: collapse; }
th {
  background: var(--gray-50);
  padding: 14px 16px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-200);
}
td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}
tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }
.table-actions { display: flex; gap: 6px; }
.table-actions .btn { padding: 6px 12px; font-size: 13px; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 24px;
  background: var(--gray-50);
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  margin-bottom: 20px;
}
.info-row .label { font-size: 12px; color: var(--gray-500); margin-bottom: 2px; }
.info-row .value { font-size: 14px; color: var(--gray-900); font-weight: 500; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--white);
  padding: 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}
.stat-card .label { font-size: 12px; color: var(--gray-500); }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 4px; }

/* ====== Loading ====== */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0,102,204,0.2);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ====== Modal ====== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-backdrop.visible { display: flex; }
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 32px 32px 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal h3 { font-size: 18px; margin-bottom: 10px; color: var(--gray-900); font-weight: 700; }
.modal p { color: var(--gray-700); font-size: 14px; margin-bottom: 24px; line-height: 1.65; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}
.modal-actions .btn { width: auto; padding: 10px 22px; }

/* ====== RWD ====== */
/* ====== RWD ====== */
@media (max-width: 768px) {

  /* 客戶端 */
  .top-bar { padding: 12px 16px; }
  .content-wrap { padding: 20px 16px; }
  .card { padding: 28px 20px; }
  .card.wide { max-width: 100%; }

  /* 設備清單底部按鈕：手機改垂直排列 */
  #activateAllBtn,
  a[href="index.html"].btn { flex: unset !important; width: 100%; }

  /* 設備卡片 */
  .device-list { gap: 10px; }

  /* admin：sidebar 改成頂部橫向捲動 nav */
  .admin-app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .admin-sidebar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 0 12px;
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
    overflow-x: auto;
    gap: 0;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-logo { margin-bottom:0; margin-right:8px; flex-shrink:0; flex-direction:row; align-items:center; gap:8px; }
  .sidebar-logo-top { gap:6px; }
  .sidebar-subtitle { display:none; }
  .admin-sidebar-nav { flex-direction: row; gap: 2px; flex: 1; overflow-x: auto; padding: 6px 0; }
  .nav-item { white-space: nowrap; padding: 6px 10px; font-size: 13px; }
  .admin-sidebar-footer {
    border-top: none;
    border-left: 1px solid var(--gray-100);
    padding: 6px 0 6px 10px;
    flex-shrink: 0;
    font-size: 12px;
    white-space: nowrap;
  }
  .admin-main { padding: 16px 14px 32px; }
  .page-header { margin-bottom: 14px; }
  .page-header h1 { font-size: 17px; }

  /* 統計卡片：強制 2 欄（覆蓋 inline style） */
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
  .stat-card { padding: 14px 16px; }
  .stat-card .value { font-size: 22px; }

  /* 搜尋列 */
  .search-bar { flex-wrap: wrap; gap: 8px; padding: 12px; }
  .search-bar .form-input { flex: 1 0 auto !important; min-width: 0; }
  .search-bar .btn { flex-shrink: 0; width: auto !important; padding: 10px 20px; }

  /* 表格水平捲動（主列表） */
  .data-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table > table { min-width: 560px; }

  /* 登入頁 */
  .login-wrap { padding: 24px 16px; align-items: flex-start; padding-top: 40px; }
  .login-body { padding: 32px 24px 24px; }
  .login-strip { padding: 12px 24px; }

  /* 新增訂單 */
  .section-card { padding: 16px 14px; }
  .form-row.col2,
  .form-row.col3 { grid-template-columns: 1fr; }
  .device-item { padding: 12px 14px; }
  .submit-bar { flex-direction: column-reverse; }
  .submit-bar .btn { width: 100% !important; }
}
