:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #e4e7ec;
  --surface: #ffffff;
  --soft: #f7f8fa;
  --accent: #1d4ed8;
}

* { box-sizing: border-box; }

html { font-size: 16px; min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--surface);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: var(--accent); }

a:focus-visible, button:focus-visible {
  outline: 3px solid rgba(29, 78, 216, .28);
  outline-offset: 2px;
}

.site-header {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .65rem clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--line);
}

.site-identity {
  color: var(--ink);
  font-size: 1.12rem;
  font-weight: 650;
  letter-spacing: -.02em;
  text-decoration: none;
}

.header-actions { display: flex; align-items: center; gap: .65rem; }
.header-link, .link-button { color: #475467; font-size: .86rem; font-weight: 600; text-decoration: none; }
.header-link:hover, .link-button:hover { color: var(--accent); }
.inline-form { display: inline; margin: 0; }
.link-button { padding: .4rem; border: 0; background: transparent; cursor: pointer; }
.button-link, .button-primary, .button-secondary {
  display: inline-flex; align-items: center; justify-content: center; min-height: 42px;
  padding: .65rem 1rem; border: 1px solid transparent; border-radius: 8px;
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer;
}
.button-link, .button-primary { color: #fff; background: var(--accent); }
.button-secondary { color: var(--ink); border-color: var(--line); background: #fff; }
.apps-menu { position: relative; }

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #475467;
  background: transparent;
  cursor: pointer;
}

.icon-button:hover, .icon-button[aria-expanded="true"] { background: var(--soft); color: var(--ink); }
.apps-icon { width: 22px; height: 22px; fill: currentColor; }

.apps-popover {
  position: absolute;
  z-index: 10;
  top: calc(100% + .65rem);
  right: 0;
  width: min(290px, calc(100vw - 2rem));
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 14px 35px rgba(16, 24, 40, .14);
}

.apps-popover-title { font-weight: 650; }
.apps-empty { margin: .8rem 0 0; color: var(--muted); font-size: .92rem; }
.apps-list { list-style: none; margin: .75rem 0 0; padding: 0; }
.apps-list a { display: block; padding: .65rem; border-radius: 7px; text-decoration: none; }
.apps-list a:hover { background: var(--soft); }

.account-link {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .3rem .45rem;
  border-radius: 9px;
  color: var(--ink);
  text-decoration: none;
}

.account-link:hover { background: var(--soft); }
.account-avatar { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: #fff; background: #344054; font-size: .86rem; font-weight: 700; }
.account-copy { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.account-name, .account-username { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-name { font-size: .88rem; font-weight: 650; }
.account-username { color: var(--muted); font-size: .75rem; }

.page-shell { width: min(1120px, 100%); margin: 0 auto; padding: clamp(2rem, 8vw, 6rem) clamp(1.25rem, 4vw, 3rem); }
.welcome { max-width: 700px; }
.eyebrow, .section-label { margin: 0 0 .75rem; color: var(--accent); font-size: .78rem; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; }
h1 { max-width: 850px; margin: 0; font-size: clamp(2.1rem, 6vw, 4.2rem); font-weight: 680; letter-spacing: -.045em; line-height: 1.03; }
.welcome > p:last-child { max-width: 630px; margin: 1.25rem 0 0; color: var(--muted); font-size: clamp(1.05rem, 2vw, 1.24rem); line-height: 1.7; }

.profile-page { max-width: 780px; }
.profile-page h1 { font-size: clamp(2rem, 5vw, 3.4rem); }
.back-link { display: inline-block; margin-bottom: 2.5rem; font-size: .9rem; text-decoration: none; }
.profile-details { margin: 2rem 0 0; border-top: 1px solid var(--line); }
.profile-details > div { display: grid; grid-template-columns: minmax(150px, 220px) 1fr; gap: 1rem; padding: 1rem 0; border-bottom: 1px solid var(--line); }
.profile-details dt { color: var(--muted); font-weight: 500; }
.profile-details dd { margin: 0; overflow-wrap: anywhere; font-weight: 600; }
.authorization-debug { margin-top: 3.5rem; padding: 1.5rem; border: 1px solid var(--line); border-radius: 12px; background: var(--soft); }
.authorization-debug h2 { margin: 0; font-size: 1.35rem; }
.authorization-debug .profile-details { margin-top: 1rem; }

.auth-page { width: min(460px, 100%); margin: 0 auto; }
.auth-page h1, .admin-page h1 { font-size: clamp(2rem, 5vw, 3.2rem); }
.lede { margin: 1rem 0 2rem; color: var(--muted); line-height: 1.65; }
.form-grid { display: grid; gap: 1rem; }
.field { display: grid; gap: .4rem; }
.field label { font-weight: 650; }
.field input, .field select, .field textarea {
  width: 100%; padding: .7rem .8rem; border: 1px solid #cfd4dc; border-radius: 7px;
  color: var(--ink); background: #fff; font: inherit;
}
.field textarea { min-height: 110px; resize: vertical; }
.field-validation-error, .validation-summary-errors { color: #b42318; font-size: .9rem; }
.validation-summary-valid { display: none; }
.status-message { margin: 1rem 0; padding: .8rem 1rem; border-radius: 7px; background: #eff8ff; color: #175cd3; }
.status-message.error { background: #fef3f2; color: #b42318; }
.admin-actions { display: flex; flex-wrap: wrap; gap: .65rem; margin: 1.5rem 0; }
.writer-health { display: flex; align-items: center; gap: .65rem; margin: 1rem 0; color: var(--muted); }
.entitlement-choice { display: grid; grid-template-columns: auto auto 1fr auto; align-items: start; gap: .5rem; padding: .7rem 0; }
.confirmation { display: flex; align-items: flex-start; gap: .45rem; margin-bottom: .55rem; color: var(--muted); font-size: .88rem; }
.secret-value { padding: .55rem .7rem; border-radius: 6px; background: #fff4e5; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.sensitive-result { border-color: #fdb022; background: #fffcf5; }
.data-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.data-table th, .data-table td { padding: .8rem .65rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data-table th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-block; padding: .25rem .5rem; border-radius: 999px; color: #344054; background: #f2f4f7; font-size: .76rem; font-weight: 650; }
.badge.ok { color: #067647; background: #ecfdf3; }
.badge.warn { color: #b54708; background: #fffaeb; }
.card { margin-top: 1rem; padding: 1.25rem; border: 1px solid var(--line); border-radius: 10px; }
.card h2 { margin: 0 0 1rem; font-size: 1.25rem; }
.muted { color: var(--muted); }
.filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; margin: 1rem 0; }

@media (max-width: 600px) {
  .site-header { align-items: flex-start; }
  .account-copy { display: none; }
  .profile-details > div { grid-template-columns: 1fr; gap: .3rem; }
  .header-link { display: none; }
  .filters { grid-template-columns: 1fr; }
  .data-table { display: block; overflow-x: auto; }
  .entitlement-choice { grid-template-columns: auto 1fr; }
}
