* { box-sizing: border-box; }
body.admin-body {
  margin: 0;
  font-family: var(--font-primary, 'WNian', Tahoma, sans-serif);
  background: #f4f6fb;
  color: #1a1a2e;
}
.admin-header { background: #4C76E3; color: #fff; padding: 0 16px; }
.admin-header-inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; min-height: 56px; gap: 16px; flex-wrap: wrap; }
.admin-brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.admin-nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.admin-menu-toggle { display: none; width: 40px; height: 40px; border: 1px solid rgba(255,255,255,.45); border-radius: 8px; background: transparent; color: #fff; font-size: 1.35rem; cursor: pointer; }
.admin-nav a { color: #fff; text-decoration: none; opacity: 0.9; }
.admin-nav a:hover { opacity: 1; }
.inline-form { display: inline; margin: 0; }
.link-btn { background: none; border: none; color: #fff; cursor: pointer; font: inherit; opacity: 0.9; padding: 0; }
.link-btn:hover { opacity: 1; text-decoration: underline; }
.lang-switch { display: flex; gap: 8px; }
.lang-switch a { font-size: 0.85rem; padding: 2px 6px; border-radius: 4px; }
.lang-switch a.active { background: rgba(255,255,255,0.2); }
.admin-main { max-width: 1200px; margin: 0 auto; padding: 24px 16px; }
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.alert-success { background: #d4edda; color: #155724; }
.alert-error { background: #f8d7da; color: #721c24; }
.card { background: #fff; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.06); padding: 24px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.card-title { margin: 0; font-size: 1.35rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font: inherit; text-decoration: none; }
.btn-primary { background: #4C76E3; color: #fff; }
.btn-secondary { background: #e9ecef; color: #333; }
.btn-danger { background: #dc3545; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 0.875rem; }
.table { width: 100%; border-collapse: collapse; }
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll .table { min-width: 680px; }
.table th, .table td { padding: 10px 12px; text-align: start; border-bottom: 1px solid #eee; }
.table th { font-weight: 600; background: #f8f9fc; }
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-weight: 600; }
.form-input { width: 100%; max-width: 480px; padding: 10px 12px; border: 1px solid #d0d5dd; border-radius: 8px; font: inherit; }
.form-select { max-width: 220px; background: #fff; }
.list-filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 0 0 18px; }
.list-filters .form-input { flex: 1 1 220px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.form-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
.meta { color: #666; font-size: 0.9rem; }
.quota-badge { background: #eef2ff; color: #4C76E3; padding: 4px 10px; border-radius: 20px; font-size: 0.85rem; }
.editor-layout { margin: -24px -16px; }
.editor-toolbar-admin { background: #fff; border-bottom: 1px solid #e5e7eb; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; position: sticky; top: 0; z-index: 100; }
.editor-toolbar-admin .left, .editor-toolbar-admin .right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.save-status { font-size: 0.85rem; color: #666; min-width: 120px; }
.save-status.is-dirty { color: #b45309; }
.save-status.is-saving { color: #4C76E3; }
.save-status.is-error { color: #dc3545; }
.save-status.is-saved { color: #198754; }

/* Guest / login landing */
body.guest-body {
    margin: 0;
    min-height: 100vh;
    background: linear-gradient(160deg, #4C76E3 0%, #2d4a9e 45%, #15162a 100%);
    font-family: var(--font-primary, 'WNian', Tahoma, sans-serif);
    color: #1a1a2e;
}
.guest-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}
.guest-header { text-align: center; color: #fff; margin-bottom: 24px; }
.guest-brand { margin: 0 0 8px; font-size: 1.75rem; font-weight: 800; }
.guest-tagline { margin: 0; opacity: .85; font-size: 1rem; }
.guest-main { width: 100%; max-width: 420px; }
.guest-card { margin: 0 auto; }
.guest-card .card-title { margin: 0 0 20px; font-size: 1.25rem; }
.guest-footer { margin-top: 24px; }
.lang-switch-guest a {
    color: #fff;
    text-decoration: none;
    margin: 0 6px;
    opacity: .75;
    font-size: 0.9rem;
}
.lang-switch-guest a.active, .lang-switch-guest a:hover { opacity: 1; text-decoration: underline; }
.btn-block { width: 100%; }

/* RBAC admin UI */
.rbac-tabs { display: flex; gap: 8px; margin: 20px 0 0; border-bottom: 1px solid #e5e7eb; flex-wrap: wrap; }
.rbac-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 10px 16px; cursor: pointer; font: inherit; font-weight: 600; color: #666;
}
.rbac-tab.is-active { color: #4C76E3; border-bottom-color: #4C76E3; }
.rbac-panel { display: none; padding: 20px 0; }
.rbac-panel.is-active { display: block; }
.perm-group { border: 1px solid #e8ecf4; border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.perm-group-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-weight: 800; padding: 0 8px; }
.perm-level { margin-top: 14px; }
.perm-level-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.perm-level-label { font-weight: 700; color: #4C76E3; font-size: 0.9rem; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.perm-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid #eee; border-radius: 8px; cursor: pointer; }
.perm-item:hover { background: #f8f9fc; }
.perm-item input { margin-top: 4px; flex-shrink: 0; }
.perm-item-body { display: flex; flex-direction: column; gap: 4px; }
.perm-item-body small { color: #666; font-size: 0.85rem; line-height: 1.4; }
.perm-item-body code { font-size: 0.75rem; color: #888; }
.member-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.member-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid #eee; border-radius: 8px; }
.member-item small { display: block; color: #666; font-size: 0.85rem; }
.role-checkboxes { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.role-check-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid #eee; border-radius: 8px; }
.role-check-item small { display: block; margin-top: 4px; }
.settings-subnav { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.settings-subnav a { padding: 8px 14px; border-radius: 8px; background: #fff; color: #4C76E3; text-decoration: none; border: 1px solid #d0d5dd; font-size: 0.95rem; }
.settings-subnav a.active { background: #4C76E3; color: #fff; border-color: #4C76E3; }
.form-error { color: #b00020; font-size: 0.875rem; margin-top: 6px; }
.update-status { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0 0 16px; }
.update-status dt { font-weight: 600; margin: 0; }
.update-status dd { margin: 0; }
.update-cli { background: #f4f4f4; padding: 12px; overflow: auto; font-size: 12px; direction: ltr; text-align: left; white-space: pre-wrap; border-radius: 8px; }

/* Admin icon buttons + tooltips */
.admin-header-actions { display: inline-flex; align-items: center; gap: 4px; margin-inline-start: 8px; }
.admin-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1;
  font: inherit;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.admin-icon-btn--sm { width: 32px; height: 32px; border-radius: 6px; }
.admin-icon-btn--primary { background: #4C76E3; color: #fff; }
.admin-icon-btn--primary:hover { background: #3d62c4; }
.admin-icon-btn--danger { background: #dc3545; color: #fff; }
.admin-icon-btn--danger:hover { background: #c82333; }
.admin-icon-btn--secondary { background: #e9ecef; color: #333; }
.admin-icon-btn--secondary:hover { background: #dde1e6; }
.admin-icon-btn--navbar { background: transparent; color: #fff; }
.admin-icon-btn--navbar:hover { background: rgba(255, 255, 255, 0.15); }
.admin-icon-btn--navbar.is-active { background: rgba(255, 255, 255, 0.22); }
.admin-ki { display: inline-flex; align-items: center; justify-content: center; font-size: 1.05rem; line-height: 1; color: inherit; }
.admin-table-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.admin-form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.admin-floating-tip {
  position: fixed;
  z-index: 10000;
  max-width: 240px;
  padding: 6px 10px;
  border-radius: 6px;
  background: #1a1a2e;
  color: #fff;
  font-size: 0.8rem;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -4px);
  transition: opacity 0.12s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.admin-floating-tip.is-visible { opacity: 1; }
.admin-floating-tip.is-below { transform: translate(-50%, 4px); }
.gdocs-status-form { margin: 0; }
.gdocs-status-form select { cursor: pointer; }

@media (max-width: 760px) {
  .admin-header-inner { min-height: 60px; }
  .admin-menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .admin-nav { display: none; flex-basis: 100%; width: 100%; padding: 4px 0 14px; align-items: stretch; }
  .admin-nav.is-open { display: flex; }
  .admin-nav > a { padding: 9px 10px; border-radius: 7px; }
  .admin-header-actions { width: 100%; margin-inline-start: 0; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.18); }
  .admin-main { padding: 16px 12px; }
  .card { padding: 16px; border-radius: 10px; }
  .list-filters { align-items: stretch; }
  .list-filters .form-input, .list-filters .btn { max-width: none; width: 100%; }
}
