:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --border: #e4e6ea;
  --border-strong: #d2d5db;
  --text: #1c2024;
  --text-secondary: #5a626c;
  --text-muted: #8a909a;
  --accent: #b9842b;
  --accent-soft: #f6ecd9;
  --accent-text: #7a5413;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --success: #1c6b4a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); }

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 380px;
  padding: 36px 32px;
  text-align: center;
}
.login-card .logo { max-width: 190px; max-height: 70px; margin: 0 auto 22px; display: block; }
.login-card h1 { font-size: 21px; font-weight: 600; margin: 0 0 4px; }
.login-card .sub { color: var(--text-secondary); font-size: 14px; margin: 0 0 26px; }
.gbtn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 11px 16px; border: 1px solid var(--border-strong);
  border-radius: var(--radius); background: #fff; color: var(--text);
  font-size: 15px; font-weight: 500; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.gbtn:hover { background: var(--surface-2); border-color: var(--text-muted); }
.gbtn svg { width: 18px; height: 18px; }
.login-note { font-size: 12.5px; color: var(--text-muted); margin: 16px 0 0; line-height: 1.5; }
.alert {
  border-radius: var(--radius); padding: 10px 14px; font-size: 13.5px;
  margin: 0 0 18px; text-align: left;
}
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--accent-soft); color: var(--accent-text); }

/* ---------- App shell ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 10px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { height: 30px; width: auto; }
.brand .app-name { font-weight: 600; font-size: 15px; white-space: nowrap; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 13.5px; flex-shrink: 0; }
.userbox .email { color: var(--text-secondary); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-badge {
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent-text); text-transform: capitalize;
}
.role-badge.viewer { background: #eef1f5; color: #4a5260; }
.role-badge.pending { background: #fdf1e3; color: #9a5b12; }
.icon-btn {
  border: 1px solid var(--border); background: #fff; border-radius: 8px;
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-secondary);
}
.icon-btn:hover { background: var(--surface-2); }

.container { max-width: 1100px; margin: 0 auto; padding: 22px 18px 60px; }

/* ---------- Search ---------- */
.searchbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 6px; }
.search-input-wrap { position: relative; flex: 1; min-width: 220px; }
.search-input-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-muted); }
.search-input {
  width: 100%; padding: 12px 14px 12px 40px; font-size: 15px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: #fff;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.toggle-group { display: flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.toggle-group button {
  border: none; background: #fff; padding: 11px 14px; font-size: 13.5px; cursor: pointer;
  color: var(--text-secondary); font-weight: 500;
}
.toggle-group button + button { border-left: 1px solid var(--border); }
.toggle-group button.active { background: var(--accent-soft); color: var(--accent-text); }
.result-meta { font-size: 13px; color: var(--text-muted); margin: 10px 2px 14px; }

/* ---------- Results ---------- */
.cards { display: grid; grid-template-columns: 1fr; gap: 0; }
.vendor-row {
  background: var(--surface); border: 1px solid var(--border); border-bottom: none;
  padding: 14px 16px; cursor: pointer; display: flex; align-items: center; gap: 14px;
  transition: background .12s;
}
.vendor-row:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.vendor-row:last-child { border-bottom: 1px solid var(--border); border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.vendor-row:hover { background: var(--surface-2); }
.vendor-prefix {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px;
  background: var(--accent-soft); color: var(--accent-text); padding: 4px 8px; border-radius: 6px;
  flex-shrink: 0; min-width: 56px; text-align: center; font-weight: 600;
}
.vendor-main { min-width: 0; flex: 1; }
.vendor-name { font-weight: 600; font-size: 15px; }
.vendor-sub { color: var(--text-secondary); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vendor-row .chev { color: var(--text-muted); flex-shrink: 0; }
.empty { text-align: center; color: var(--text-muted); padding: 50px 20px; }

/* ---------- Detail / edit ---------- */
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.detail-title h2 { font-size: 20px; margin: 0 0 2px; }
.detail-title .cat { color: var(--text-secondary); font-size: 13.5px; }
.btn {
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  padding: 9px 16px; border-radius: var(--radius); font-size: 14px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #a6741f; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-secondary); }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--text-muted); font-weight: 600; letter-spacing: .01em; }
.field .value { font-size: 14.5px; word-break: break-word; white-space: pre-wrap; min-height: 20px; }
.field input, .field textarea {
  font-family: var(--font); font-size: 14.5px; padding: 9px 11px; border: 1px solid var(--border-strong);
  border-radius: 8px; background: #fff; color: var(--text); width: 100%; outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px; box-shadow: var(--shadow); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; opacity: 0; transition: opacity .2s; z-index: 50; }
.toast.show { opacity: 1; }

/* ---------- Pending / no access ---------- */
.notice-wrap { max-width: 460px; margin: 70px auto; text-align: center; padding: 0 20px; }
.notice-wrap .big-icon { width: 54px; height: 54px; color: var(--accent); margin-bottom: 14px; }
.notice-wrap h2 { font-size: 20px; margin: 0 0 8px; }
.notice-wrap p { color: var(--text-secondary); margin: 0 0 6px; }

/* ---------- Users admin ---------- */
.users-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.users-table th { text-align: left; font-size: 12px; color: var(--text-muted); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.users-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
.users-table tr:last-child td { border-bottom: none; }
.users-table select { padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; font-size: 13.5px; }
.tabbar { display: flex; gap: 6px; margin-bottom: 20px; }
.tabbar button { border: 1px solid var(--border); background: #fff; padding: 8px 16px; border-radius: 20px; font-size: 13.5px; font-weight: 500; color: var(--text-secondary); cursor: pointer; }
.tabbar button.active { background: var(--text); color: #fff; border-color: var(--text); }

@media (max-width: 600px) {
  .container { padding: 16px 12px 50px; }
  .vendor-sub.state { display: none; }
  .userbox .email { display: none; }
  .brand .app-name { display: none; }
  .panel { padding: 16px; }
  .users-table .col-name, .users-table .col-seen { display: none; }
}
