/* 悠然生活 · 權限總控制台 — main.css */
:root {
  --P900:#0d2240; --P800:#133060; --P700:#1a4480;
  --P600:#2563a8; --P500:#3b82c4; --P400:#60a0d8;
  --P200:#bfdbf7; --P100:#dbeeff; --P50:#f0f7ff;
  --G600:#16a34a; --G100:#dcfce7;
  --R600:#dc2626; --R100:#fee2e2;
  --Y600:#d97706; --Y100:#fef3c7;
  --N950:#0f172a; --N800:#1e293b; --N700:#334155;
  --N600:#475569; --N500:#64748b; --N400:#94a3b8;
  --N300:#cbd5e1; --N200:#e2e8f0; --N100:#f1f5f9; --N50:#f8fafc;
  --WHITE:#ffffff;
  --shadow-s:0 1px 3px rgba(0,0,0,.08),0 1px 2px rgba(0,0,0,.05);
  --shadow-m:0 4px 12px rgba(0,0,0,.09),0 2px 4px rgba(0,0,0,.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--N50);
  color: var(--N800);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ── TOPBAR ── */
.topbar {
  height: 56px;
  background: var(--P800);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  z-index: 100;
  flex-shrink: 0;
}
.logo-text {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.2px;
}
.topbar .divider {
  width: 1px;
  height: 18px;
  background: rgba(255,255,255,.25);
}
.topbar-title {
  font-size: 14px;
  color: rgba(255,255,255,.75);
}
.topbar-r {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-info {
  font-size: 13px;
  color: rgba(255,255,255,.8);
}

/* ── LAYOUT ── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 220px;
  background: var(--WHITE);
  border-right: 1px solid var(--N200);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-inner { padding: 10px 8px; }
.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--N400);
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 10px 10px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--N600);
  transition: all .15s;
  user-select: none;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--N100); color: var(--N800); }
.nav-item.active { background: var(--P50); color: var(--P700); }

/* ── MAIN ── */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.view { display: none; flex-direction: column; gap: 20px; }
.view.active { display: flex; }

/* ── LOGIN ── */
.login-card {
  max-width: 380px;
  margin: 80px auto 0;
  background: var(--WHITE);
  border-radius: 16px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: var(--shadow-m);
}
.login-title { font-size: 20px; font-weight: 600; color: var(--N950); margin-bottom: 8px; }
.login-sub { font-size: 13px; color: var(--N500); margin-bottom: 28px; }
.btn-lg { height: 44px; font-size: 15px; padding: 0 24px; }

/* ── PAGE HEADER ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title { font-size: 20px; font-weight: 500; color: var(--N950); }
.page-sub { font-size: 13px; color: var(--N500); margin-top: 3px; }
.hdr-act { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ── BUTTONS ── */
.btn {
  height: 36px;
  padding: 0 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .15s;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--P600); color: #fff; }
.btn-primary:hover { background: var(--P700); }
.btn-outlined {
  background: var(--WHITE);
  color: var(--P700);
  border: 1.5px solid var(--N300);
}
.btn-outlined:hover { background: var(--P50); border-color: var(--P400); }
.btn-ghost { background: transparent; color: rgba(255,255,255,.85); padding: 0 10px; }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-danger { background: var(--R600); color: #fff; }
.btn-danger:hover { opacity: .9; }

/* ── CARD ── */
.card {
  background: var(--WHITE);
  border-radius: 12px;
  box-shadow: var(--shadow-s);
  border: 1px solid var(--N200);
  overflow: hidden;
}

/* ── TABLE ── */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  padding: 10px 16px;
  background: var(--N50);
  color: var(--N500);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .5px;
  text-transform: uppercase;
  text-align: left;
  border-bottom: 1px solid var(--N200);
  white-space: nowrap;
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--N100);
  color: var(--N700);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--N50); }

/* ── CHIP ── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.chip-dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
/* 舊 chip 變體（相容保留） */
.chip-green  { background: var(--G100); color: var(--G600); }
.chip-red    { background: var(--R100); color: var(--R600); }
.chip-yellow { background: var(--Y100); color: var(--Y600); }
.chip-grey   { background: var(--N200); color: var(--N600); }
/* 新 dot chip 變體 */
.c-green  { background: var(--G100); color: #15803d; }
.c-green .chip-dot  { background: #16a34a; }
.c-red    { background: var(--R100); color: #991b1b; }
.c-red .chip-dot    { background: var(--R600); }
.c-yellow { background: var(--Y100); color: #92400e; }
.c-yellow .chip-dot { background: var(--Y600); }
.c-grey   { background: var(--N100); color: var(--N600); }
.c-grey .chip-dot   { background: var(--N400); }
.c-blue   { background: var(--P100); color: var(--P700); }
.c-blue .chip-dot   { background: var(--P500); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--WHITE);
  border-radius: 14px;
  width: 440px;
  max-width: 95vw;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--N200);
}
.modal-title { font-size: 16px; font-weight: 600; color: var(--N950); }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--N400);
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--N100); }
.modal-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer {
  padding: 16px 24px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--N200);
}

/* ── FORM ── */
.form-label { font-size: 12px; font-weight: 600; color: var(--N600); }
.required { color: var(--R600); }
.form-input {
  width: 100%;
  height: 36px;
  border: 1.5px solid var(--N300);
  border-radius: 6px;
  padding: 0 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--N800);
  outline: none;
  transition: border-color .15s;
}
.form-input:focus { border-color: var(--P500); }

/* ── PAGINATION ── */
.pagination-wrap {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-top: 1px solid var(--N100);
}
.page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--N300);
  border-radius: 6px;
  background: var(--WHITE);
  cursor: pointer;
  font-size: 13px;
  color: var(--N700);
}
.page-btn:hover { background: var(--N50); }
.page-btn.active { background: var(--P600); color: #fff; border-color: var(--P600); }
.page-info { font-size: 12px; color: var(--N400); }

/* ── TOAST ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}
.toast {
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-m);
  animation: slideIn .2s ease;
  max-width: 320px;
}
.toast-success { background: var(--G600); }
.toast-error   { background: var(--R600); }
.toast-info    { background: var(--P600); }
@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── KEY DISPLAY ── */
.key-display {
  background: var(--N50);
  border: 1px solid var(--N200);
  border-radius: 8px;
  padding: 12px;
}
.key-warning { font-size: 12px; color: var(--R600); font-weight: 500; margin-bottom: 6px; }
.key-value {
  display: block;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  word-break: break-all;
  color: var(--N800);
}

/* ── STATS GRID ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.stat-card {
  background: var(--WHITE);
  border: 1.5px solid var(--N200);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: var(--shadow-s);
  cursor: pointer;
  transition: all .2s;
  position: relative;
  overflow: hidden;
}
.stat-card:hover {
  box-shadow: var(--shadow-m);
  transform: translateY(-1px);
  border-color: var(--N300);
}
.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-icon svg { width: 18px; height: 18px; }
.si-blue   { background: var(--P50);  color: var(--P600); }
.si-green  { background: var(--G100); color: var(--G600); }
.si-yellow { background: var(--Y100); color: var(--Y600); }
.si-red    { background: var(--R100); color: var(--R600); }
.stat-val {
  font-size: 28px;
  font-weight: 600;
  color: var(--N950);
  line-height: 1;
  margin-bottom: 3px;
}
.stat-lbl { font-size: 12px; color: var(--N500); }
.card-hdr {
  padding: 14px 20px;
  border-bottom: 1px solid var(--N100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--N800); }
.card-sub   { font-size: 12px; color: var(--N500); margin-top: 2px; }

/* ── TABLE ACTIONS ── */
.row-actions { display: flex; gap: 6px; align-items: center; }
.icon-action {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--N500);
}
.icon-action:hover { background: var(--N100); color: var(--N800); }

/* ── FILTER ROW ── */
.filter-row { display: flex; align-items: center; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--N100); flex-wrap: wrap; }
.filter-chip { height: 28px; padding: 0 12px; border: 1.5px solid var(--N200); border-radius: 14px; font-size: 12px; background: var(--WHITE); cursor: pointer; display: inline-flex; align-items: center; color: var(--N600); font-family: inherit; font-weight: 500; transition: all .15s; }
.filter-chip:hover, .filter-chip.active { border-color: var(--P500); color: var(--P700); background: var(--P50); }

/* ── USER CELL ── */
.user-cell { display: flex; align-items: center; gap: 10px; }
.uav { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0; }
.uname { font-size: 13px; font-weight: 500; color: var(--N800); }
.uemail { font-size: 11px; color: var(--N500); }

/* ── TAGS ── */
.tags { display: flex; flex-wrap: wrap; gap: 3px; }
.tag { padding: 2px 7px; background: var(--P50); color: var(--P700); border: 1px solid var(--P200); border-radius: 4px; font-size: 11px; font-weight: 500; font-family: 'Courier New', monospace; }
code { font-family: 'Courier New', monospace; background: var(--N100); padding: 2px 6px; border-radius: 4px; font-size: 11px; color: var(--N700); border: 1px solid var(--N200); }

/* ── STAT CARD ACCENT ── */
.stat-card::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 3px; border-radius: 0 0 12px 12px; background: var(--accent, var(--P500)); opacity: 0; transition: opacity .2s; }
.stat-card:hover::after { opacity: 1; }
.stat-badge { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 9px; }
.sb-up { background: var(--G100); color: var(--G600); }
.sb-n  { background: var(--N100); color: var(--N500); }
.stat-hint { font-size: 11px; color: var(--P500); margin-top: 6px; display: flex; align-items: center; gap: 4px; font-weight: 500; }

/* ── NAV BADGE ── */
.nav-badge { margin-left: auto; background: var(--P500); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 9px; line-height: 16px; }
.nav-badge.grey { background: var(--N200); color: var(--N500); }
.s-divider { height: 1px; background: var(--N200); margin: 6px 10px; }

/* ── API KEY BOX ── */
.api-key-box { background: var(--N950); border-radius: 8px; padding: 12px 14px; font-family: 'Courier New', monospace; font-size: 12px; color: #93c5fd; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.api-key-val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* ── INFO / WARN BOX ── */
.info-box { background: var(--P50); border: 1px solid var(--P200); border-radius: 8px; padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; font-size: 12px; color: var(--P800); line-height: 1.6; }
.info-box svg { color: var(--P600); flex-shrink: 0; margin-top: 1px; }
.warn-box { background: #fef2f2; border: 1px solid var(--R100); border-radius: 8px; padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; font-size: 12px; color: #991b1b; line-height: 1.6; }
.warn-box svg { color: var(--R600); flex-shrink: 0; margin-top: 1px; }

/* ── EMPTY STATE ── */
.empty-state { padding: 32px 20px; text-align: center; }
.empty-state svg { color: var(--N300); margin: 0 auto 10px; display: block; }
.empty-title { font-size: 14px; font-weight: 500; color: var(--N500); margin-bottom: 4px; }
.empty-desc { font-size: 12px; color: var(--N400); }

/* ── BTN ROW ── */
.btn-row { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.btn-ghost-sm { background: transparent; color: var(--P600); padding: 0 8px; height: 28px; font-size: 12px; border: none; border-radius: 5px; cursor: pointer; font-family: inherit; font-weight: 500; transition: background .15s; }
.btn-ghost-sm:hover { background: var(--P50); }
.btn-danger-sm { background: transparent; color: var(--R600); padding: 0 8px; height: 28px; font-size: 12px; border: none; border-radius: 5px; cursor: pointer; font-family: inherit; font-weight: 500; transition: background .15s; }
.btn-danger-sm:hover { background: var(--R100); }

/* ── SEARCH WRAP (topbar) ── */
.search-wrap { flex: 1; max-width: 420px; margin: 0 8px; position: relative; }
.search-wrap input { width: 100%; height: 34px; background: rgba(255,255,255,.12); border: 1.5px solid rgba(255,255,255,.2); border-radius: 17px; padding: 0 14px 0 38px; font-size: 13px; font-family: inherit; color: #fff; outline: none; transition: all .2s; }
.search-wrap input::placeholder { color: rgba(255,255,255,.5); }
.search-wrap input:focus { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.4); }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: rgba(255,255,255,.5); pointer-events: none; }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; border: none; background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; color: rgba(255,255,255,.7); transition: background .15s; }
.icon-btn:hover { background: rgba(255,255,255,.12); }
.topbar-avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--P400), var(--P600)); border: 2px solid rgba(255,255,255,.3); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 11px; font-weight: 700; margin-left: 4px; }

/* ── FORM HINT ── */
.form-hint { font-size: 11px; color: var(--N400); line-height: 1.5; }
select.form-input { appearance: auto; }

/* ── DASH GRID ── */
.dash-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.dash-list { padding: 12px 20px; display: flex; flex-direction: column; gap: 10px; min-height: 60px; }
.dash-tool-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--N100); font-size: 13px; }
.dash-tool-row:last-child { border-bottom: none; }
.dash-empty { font-size: 13px; color: var(--N400); padding: 12px 0; }

/* ── USER DETAIL ── */
.detail-row { display: flex; align-items: center; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--N100); }
.detail-row:last-child { border-bottom: none; }
.detail-label { font-size: 12px; font-weight: 600; color: var(--N500); min-width: 80px; }

/* ── TOOL PERM ROW ── */
.tool-perm-row { border-bottom: 1px solid var(--N100); }
.tool-perm-row:last-child { border-bottom: none; }
.tool-perm-row.expanded { background: var(--N50); }
.tool-perm-title { display: flex; align-items: center; gap: 12px; padding: 12px 20px; cursor: pointer; transition: background .15s; }
.tool-perm-title:hover { background: var(--N50); }
.perm-chevron { font-size: 10px; color: var(--N400); flex-shrink: 0; width: 12px; }
.feature-list { padding: 0 20px 12px 44px; }
.feature-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--N100); font-size: 13px; color: var(--N700); }
.feature-row:last-child { border-bottom: none; }
.feature-hint { font-size: 12px; color: var(--N400); padding: 8px 0; }

/* ── TOGGLE ── */
.toggle { position: relative; display: inline-block; width: 34px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--N300); border-radius: 20px; transition: all .2s; cursor: pointer; }
.toggle-slider::before { content: ''; position: absolute; width: 14px; height: 14px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: all .2s; }
.toggle input:checked + .toggle-slider { background: var(--P600); }
.toggle input:checked + .toggle-slider::before { transform: translateX(14px); }
.toggle input:disabled + .toggle-slider { opacity: .4; cursor: not-allowed; }

/* ── PERMISSIONS TAB ── */
.perm-tabs { display: flex; gap: 4px; margin-bottom: 0; }
.perm-tab { height: 36px; padding: 0 16px; border: none; border-bottom: 2px solid transparent; background: transparent; font-size: 13px; font-weight: 500; color: var(--N500); cursor: pointer; font-family: inherit; transition: all .15s; border-radius: 6px 6px 0 0; }
.perm-tab:hover { color: var(--N800); background: var(--N100); }
.perm-tab.active { color: var(--P700); border-bottom-color: var(--P600); background: var(--P50); }
