:root {
  --bg: #f6f7f4;
  --fg: #222;
  --muted: #777;
  --accent: #1D9E75;
  --error: #b3261e;
  --border: #d9d9d6;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  color: var(--fg);
  background: var(--bg);
}

.topnav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.topnav-left { display: flex; align-items: center; gap: 10px; }
.topnav-left .brand { font-weight: 700; color: var(--fg); text-decoration: none; font-size: 16px; }
.topnav-left .brand:hover { color: var(--accent); }
.brand-sep { color: var(--muted); }
.app-title { font-weight: 500; color: var(--muted); font-size: 15px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
a.app-title:hover { color: var(--accent); }
.app-icon { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; display: block; }

/* Parents cell (WL-8a) */
.parents-cell .btn-xs { font-size: 11px; padding: 2px 8px; margin-left: 8px; border-radius: 12px; }
.parents-edit { display: flex; flex-direction: column; gap: 4px; }
.parents-edit label.checkbox { gap: 6px; font-size: 13px; }
.parents-actions { margin-top: 8px; display: flex; gap: 6px; }

/* Suggestion badge + toolbar (WL-8b) */
.badge-suggested {
  display: inline-block;
  background: #FFF4D4; color: #6D4B00;
  font-size: 11px; font-weight: 500;
  padding: 2px 9px; border-radius: 10px;
  margin-left: 8px;
}
.suggest-toolbar { margin: 16px 0 4px; display: flex; justify-content: flex-end; }

/* Priority star (WL-OPT-STAR) */
.gift-star { font-size: 15px; margin-right: 6px; line-height: 1; }
.gift-star-own { color: #1D9E75; }
.gift-star-view { color: #085041; }

.topnav-right { display: flex; gap: 16px; align-items: center; }
.nav-link { color: var(--fg); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 6px; }
.nav-link:hover { background: #f2f2ee; color: var(--accent); }

.user-menu { position: relative; }
.user-trigger {
  display: flex; align-items: center; gap: 8px;
  background: none; border: 1px solid transparent; padding: 4px 10px 4px 4px;
  border-radius: 24px; cursor: pointer; font: inherit; color: var(--fg);
}
.user-trigger:hover { background: #f2f2ee; border-color: var(--border); }
.user-trigger .user-name { font-size: 14px; }
.user-trigger .caret { font-size: 11px; color: var(--muted); }

.user-dropdown {
  position: absolute; top: 100%; right: 0; margin-top: 6px;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.08);
  min-width: 180px; padding: 6px;
  display: none;
  z-index: 100;
}
.user-dropdown.open { display: block; }
.user-dropdown a, .user-dropdown button {
  display: block; width: 100%; text-align: left;
  padding: 8px 12px; border: none; background: none; font: inherit;
  color: var(--fg); text-decoration: none; border-radius: 6px; cursor: pointer;
}
.user-dropdown a:hover, .user-dropdown button:hover { background: #f2f2ee; color: var(--accent); }

.badge {
  font-size: 11px;
  text-transform: uppercase;
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
}

.linklike {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font: inherit; padding: 0;
}

.page-title { margin: 0 0 8px; }

.notice.success { background: #E1F5EE; color: #085041; padding: 10px 12px; border-radius: 6px; font-size: 14px; margin-bottom: 16px; }

/* My Apps launcher grid */
.my-apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin-top: 24px;
}
.my-app-card {
  display: flex; flex-direction: column; gap: 10px;
  background: #fff; border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: 14px; padding: 22px;
  text-decoration: none; color: var(--fg);
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.my-app-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 22px rgba(0,0,0,0.08);
}
.my-app-card.app-theme-property-monitor { border-top-color: #185FA5; }
.my-app-icon {
  width: 56px; height: 56px; border-radius: 12px;
  background: #E1F5EE; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.my-app-card.app-theme-property-monitor .my-app-icon { background: #E3EEFB; }
.my-app-icon img { width: 100%; height: 100%; object-fit: cover; }
.my-app-name { font-size: 18px; font-weight: 600; }
.my-app-desc { font-size: 13px; color: var(--muted); margin: 0; }
.my-app-launch { margin-top: auto; color: var(--accent); font-size: 14px; font-weight: 500; }
.my-app-card.app-theme-property-monitor .my-app-launch { color: #185FA5; }

/* Wishlist admin */
.dash-card.wl-card-families { background: linear-gradient(135deg, #1D9E75 0%, #0F6E56 100%); }
.dash-card.wl-card-visibility { background: linear-gradient(135deg, #9FE1CB 0%, #0F6E56 100%); }

form.stack.inline-row { flex-direction: row; align-items: center; gap: 10px; max-width: 100%; }
form.stack.inline-row input[type=text], form.stack.inline-row select { flex: 1; min-width: 200px; }

/* Visibility matrix */
table.data.vis-matrix th.corner {
  background: #f9f9f6; font-weight: 500; color: var(--muted); font-size: 12px;
  text-transform: none; letter-spacing: 0; text-align: center;
}
table.data.vis-matrix th { text-align: center; }
table.data.vis-matrix th.vis-row-label {
  background: #f9f9f6; font-weight: 600; font-size: 13px; text-align: left;
  text-transform: none; letter-spacing: 0; color: var(--fg);
}
.vis-col-label { font-size: 13px; text-transform: none; letter-spacing: 0; color: var(--fg); }
td.vis-self { text-align: center; color: #085041; background: #E1F5EE; font-weight: 600; }
td.vis-cell { text-align: center; }
.vis-toggle { display: inline-flex; cursor: pointer; }
.vis-toggle input { width: 18px; height: 18px; accent-color: #1D9E75; cursor: pointer; }

/* Wishlist app */
.wl-tabs { margin-bottom: 20px; }
.wl-tabs .tab.active { color: #085041; border-bottom-color: #1D9E75; }

.gift-list { list-style: none; padding: 0; margin: 16px 0; display: flex; flex-direction: column; gap: 12px; }
.gift-row {
  display: flex; justify-content: space-between; gap: 20px; align-items: flex-start;
  background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px;
  transition: border-color 0.12s;
}
.gift-row:hover { border-color: #9FE1CB; }
.gift-main { flex: 1; min-width: 0; }
.gift-title { font-size: 16px; font-weight: 600; color: #085041; margin-bottom: 4px; }
.gift-url { margin-left: 6px; text-decoration: none; font-size: 14px; color: inherit; }
.gift-url-hint { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 2px; }
.gift-url:hover .gift-url-hint { color: var(--accent); }
.gift-desc { margin: 0; color: var(--fg); font-size: 14px; white-space: pre-wrap; }
.gift-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* Wishlist home — collapsible family sections */
.wl-home-sections { display: flex; flex-direction: column; gap: 20px; margin-top: 16px; }
.wl-family-section { background: transparent; }
.wl-family-header {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  user-select: none; padding: 6px 0;
}
.wl-family-header .chevron {
  display: inline-block; transition: transform 0.15s ease;
  color: var(--muted); font-size: 14px; width: 12px; text-align: center;
}
.wl-family-section.open > .wl-family-header .chevron { transform: rotate(90deg); }
.wl-family-name {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600; color: var(--muted);
}
.wl-family-name.own { color: #0F6E56; }
.wl-family-rule { flex: 1; height: 1px; background: var(--border); }

.wl-member-grid {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin-top: 12px;
}
.wl-family-section.open > .wl-member-grid { display: grid; }

.wl-member-card {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 6px;
  background: #fff; border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 10px;
}
.wl-member-card.own { border: 1.5px solid #1D9E75; }
.wl-member-avatar {
  width: 56px; height: 56px; border-radius: 50%; overflow: hidden;
  background: #E1F5EE; display: flex; align-items: center; justify-content: center;
  color: #085041; font-weight: 700; font-size: 22px;
}
.wl-member-avatar img { width: 100%; height: 100%; object-fit: cover; }
.wl-member-initial { line-height: 1; }
.wl-member-name {
  font-size: 14px; font-weight: 600; color: var(--fg);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wl-member-count { font-size: 12px; color: var(--muted); }
.wl-member-count.has-gifts { color: #0F6E56; font-weight: 500; }
.wl-member-action {
  margin-top: 6px;
  font-size: 13px; padding: 6px 14px; border-radius: 20px;
  width: auto;
}

/* Wishlist list detail view */
.view-list-back { margin-bottom: 12px; }
.btn-back-pill {
  display: inline-block;
  background: #9FE1CB; color: #085041;
  border: none; border-radius: 20px;
  padding: 6px 14px; font-weight: 500; font-size: 13px;
  text-decoration: none;
}
.btn-back-pill:hover { filter: brightness(0.95); }

.view-list-header {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 20px;
}
.view-list-avatar {
  width: 56px; height: 56px; border-radius: 50%; overflow: hidden;
  background: #E1F5EE; display: flex; align-items: center; justify-content: center;
  color: #085041; font-weight: 700; font-size: 22px; flex-shrink: 0;
}
.view-list-avatar img { width: 100%; height: 100%; object-fit: cover; }
.view-list-title { margin: 0; font-size: 22px; font-weight: 600; }
.view-list-subtitle { font-size: 13px; color: var(--muted); margin-top: 2px; }

.badge-bought {
  display: inline-block;
  background: #E1F5EE; color: #085041;
  font-size: 11px; font-weight: 500;
  padding: 2px 9px; border-radius: 10px;
  margin-left: 8px;
}
.badge-removed {
  display: inline-block;
  background: #F1EFE8; color: #444441;
  font-size: 11px; font-weight: 500;
  padding: 2px 9px; border-radius: 10px;
  margin-left: 6px;
}
.gift-row.is-removed .gift-title,
.gift-row.is-removed .gift-desc { color: #999; }
.gift-row.is-removed { background: #fafaf7; }

.content { padding: 32px 24px; max-width: 900px; margin: 0 auto; }

.auth-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  max-width: 380px;
  margin: 48px auto;
}

.auth-card h1 { margin-top: 0; font-size: 22px; }

.auth-card form { display: flex; flex-direction: column; gap: 14px; }

.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

.auth-card label.checkbox { flex-direction: row; align-items: center; color: var(--fg); font-size: 14px; }

.auth-card input[type=email],
.auth-card input[type=password] {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
}

.auth-card button[type=submit] {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.auth-card button[type=submit]:hover { filter: brightness(1.05); }

.error {
  background: #fde8e6;
  color: var(--error);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
}

.notice {
  background: #fff7e0;
  color: #6d4b00;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
}

.hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

.placeholder {
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 24px;
  color: var(--muted);
}

/* Admin shell: tab bar + card panel */
.admin-shell { display: flex; flex-direction: column; gap: 0; }

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.tab-bar .tab {
  padding: 12px 18px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
}
.tab-bar .tab:hover { color: #085041; }
.tab-bar .tab.active { color: #085041; border-bottom-color: var(--accent); }

.admin-panel { padding: 0 4px; }
.admin-panel h1 { margin: 0 0 20px; font-size: 22px; }
.admin-panel h2 { font-size: 15px; margin: 0; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.admin-panel h2.danger { color: var(--error); }
.admin-panel hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }

.header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }

/* Clickable stat tiles (used on Users list status summary) */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
.tile {
  display: block;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-decoration: none;
  color: var(--fg);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.tile:not(.static):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(8, 80, 65, 0.08);
  border-color: var(--accent);
}
.tile-icon { font-size: 22px; margin-bottom: 8px; }
.tile-num { font-size: 32px; font-weight: 600; color: #085041; line-height: 1.1; }
.tile-label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; }
.tile-hint { font-size: 12px; color: var(--accent); margin-top: 10px; font-weight: 500; }

/* Dashboard color-coded clickable square cards */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}
.dash-card {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 20px;
  padding: 22px;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #fff;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  overflow: hidden;
}
.dash-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(0,0,0,0.12);
}
.dash-card-icon { font-size: 32px; line-height: 1; opacity: 0.9; }
.dash-card-num {
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  margin-top: auto;
}
.dash-card-label {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  opacity: 0.92;
  margin-top: 6px;
}
.dash-card-meta {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.25);
  padding-top: 10px;
  line-height: 1.4;
}
.dash-card-meta strong { font-weight: 600; }

.dash-users {
  background: linear-gradient(135deg, #1D9E75 0%, #0F6E56 100%);
}
.dash-apps {
  background: linear-gradient(135deg, #185FA5 0%, #0F3F7A 100%);
}

/* Applications list cards */
.app-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.app-card {
  display: flex;
  gap: 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  text-decoration: none;
  color: var(--fg);
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.app-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.06);
  border-color: var(--accent);
}
.app-card.inactive { opacity: 0.6; }
.app-card.inactive:hover { border-color: var(--border); }
.app-card-icon {
  width: 56px; height: 56px; border-radius: 12px; overflow: hidden; flex-shrink: 0;
  background: #E1F5EE; display: flex; align-items: center; justify-content: center;
}
.app-card-icon img { width: 100%; height: 100%; object-fit: cover; }
.icon-placeholder { font-size: 22px; font-weight: 700; color: #085041; }
.app-card-body { flex: 1; min-width: 0; }
.app-card-title {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  font-weight: 600; font-size: 16px; margin-bottom: 4px;
}
.app-card-slug { font-size: 12px; margin-bottom: 8px; }
.app-card-desc { font-size: 13px; color: var(--fg); margin: 0 0 10px; }
.app-card-meta { font-size: 12px; color: var(--muted); }

/* Audit log filter row + pager */
.filter-row { display: flex; gap: 12px; align-items: end; margin-bottom: 16px; }
.filter-row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filter-row select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; font-family: inherit; background: #fff; min-width: 220px;
}
.audit-detail { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager { display: flex; align-items: center; gap: 14px; margin-top: 16px; }

/* Section block with count badge header */
.section-block { margin-top: 24px; }
.section-header { display: flex; align-items: center; gap: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.count-badge { background: #E1F5EE; color: #085041; font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 10px; }
.count-badge.small { font-size: 11px; padding: 1px 8px; }

/* Polished data table */
table.data.polished { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table.data.polished th, table.data.polished td { border-bottom: none; padding: 12px 16px; }
table.data.polished thead { background: #f9f9f6; }
table.data.polished thead th { border-bottom: 1px solid var(--border); }
table.data.polished tbody tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
table.data.polished tbody tr:hover { background: #fafaf7; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

/* Activity action chips */
.action-chip {
  display: inline-block;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 10px;
  text-transform: capitalize;
  font-weight: 500;
  background: #f2f2ee;
  color: var(--fg);
}
.action-chip.action-create  { background: #E1F5EE; color: #085041; }
.action-chip.action-update  { background: #E3EEFB; color: #1A4D86; }
.action-chip.action-enable  { background: #E1F5EE; color: #085041; }
.action-chip.action-disable { background: #FDECE9; color: #8A2A1F; }
.action-chip.action-reset   { background: #FFF4D4; color: #6D4B00; }
.action-chip.action-delete  { background: #FDECE9; color: #8A2A1F; }
.action-chip.action-grant   { background: #E1F5EE; color: #085041; }

/* User row avatar chip */
.user-cell { display: flex; align-items: center; gap: 10px; }
.avatar-chip {
  width: 32px; height: 32px; border-radius: 50%;
  background: #E1F5EE; color: #085041; font-weight: 600; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
}
.avatar-chip img { width: 100%; height: 100%; object-fit: cover; }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.data th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
table.data a { color: var(--accent); text-decoration: none; }
table.data a:hover { text-decoration: underline; }

.status { font-size: 11px; padding: 2px 8px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.04em; }
.status.active { background: #E1F5EE; color: #085041; }
.status.suspended { background: #F1EFE8; color: #444441; }

form.stack { display: flex; flex-direction: column; gap: 14px; max-width: 520px; }
form.stack.inline { margin-top: 12px; }
form.inline { display: inline-block; }
form.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
form.stack label.checkbox { flex-direction: row; align-items: center; color: var(--fg); font-size: 14px; gap: 8px; }
form.stack input[type=text], form.stack input[type=email], form.stack input[type=password], form.stack input[type=date], form.stack textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-family: inherit;
}
form.stack fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 12px 16px; display: flex; flex-direction: column; gap: 6px; }
form.stack fieldset legend { padding: 0 6px; font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 10px; }

.btn { background: #fff; border: 1px solid var(--border); color: var(--fg); padding: 8px 14px; border-radius: 6px; cursor: pointer; text-decoration: none; font-size: 14px; display: inline-block; }
.btn:hover { background: #f2f2ee; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn.warn { background: #fff7e0; border-color: #e3cc80; color: #6d4b00; }
.btn.danger { background: var(--error); color: #fff; border-color: var(--error); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.avatar-row { display: flex; gap: 16px; align-items: center; }
.avatar-preview { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }
.avatar-preview.empty { display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); background: #f2f2ee; }
