:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #e4e7ec;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --soft: #f7f8fa;
  --accent: #1d4ed8;
  --accent-contrast: #ffffff;
  --control-border: #cfd4dc;
  --control-background: #ffffff;
  --header-link: #475467;
  --avatar: #344054;
  --focus: rgba(29, 78, 216, .36);
  --shadow: rgba(16, 24, 40, .14);
  --info-background: #eff8ff;
  --info-ink: #175cd3;
  --error-background: #fef3f2;
  --error-ink: #b42318;
  --warning-background: #fffaeb;
  --warning-ink: #934f00;
  --success-background: #ecfdf3;
  --success-ink: #067647;
  --badge-background: #f2f4f7;
  --badge-ink: #344054;
  --secret-background: #fff4e5;
  --sensitive-background: #fffcf5;
  --sensitive-border: #fdb022;
  --table-stripe: rgba(16, 24, 40, .025);
  --table-hover: rgba(29, 78, 216, .055);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f0f4fc;
  --muted: #aeb8ca;
  --line: #3a465b;
  --surface: #111827;
  --surface-elevated: #1b2535;
  --soft: #222d3e;
  --accent: #8bb4ff;
  --accent-contrast: #07152f;
  --control-border: #53627a;
  --control-background: #172132;
  --header-link: #c4ccda;
  --avatar: #5571a4;
  --focus: rgba(139, 180, 255, .55);
  --shadow: rgba(0, 0, 0, .42);
  --info-background: #102a4c;
  --info-ink: #a7cbff;
  --error-background: #421d25;
  --error-ink: #ffb4b8;
  --warning-background: #3a2b12;
  --warning-ink: #ffd48a;
  --success-background: #123528;
  --success-ink: #8de5bd;
  --badge-background: #2b3749;
  --badge-ink: #d6deeb;
  --secret-background: #3b2b16;
  --sensitive-background: #2f2818;
  --sensitive-border: #bc8529;
  --table-stripe: rgba(255, 255, 255, .025);
  --table-hover: rgba(139, 180, 255, .08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { color-scheme: dark; background: #111827; }
}

* { 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, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus);
  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: var(--header-link); 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: var(--accent-contrast); background: var(--accent); }
.button-secondary { color: var(--ink); border-color: var(--line); background: var(--surface-elevated); }
.button-link:hover, .button-primary:hover { color: var(--accent-contrast); filter: brightness(1.08); }
.button-secondary:hover { color: var(--ink); background: var(--soft); }
.button-link:disabled, .button-primary:disabled, .button-secondary:disabled { opacity: .55; cursor: not-allowed; }
.theme-selector select {
  min-height: 36px; padding: .35rem 1.8rem .35rem .6rem; border: 1px solid var(--line);
  border-radius: 7px; color: var(--ink); background-color: var(--control-background); font: inherit;
  font-size: .82rem; font-weight: 600; cursor: pointer;
}
.apps-menu { position: relative; }

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--header-link);
  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 var(--shadow);
}

.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: var(--avatar); 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 var(--control-border); border-radius: 7px;
  color: var(--ink); background: var(--control-background); font: inherit;
}
.field textarea { min-height: 110px; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: 1; }
.field input:disabled, .field select:disabled, .field textarea:disabled { color: var(--muted); background: var(--soft); opacity: 1; }
.field-validation-error, .validation-summary-errors { color: var(--error-ink); font-size: .9rem; }
.validation-summary-valid { display: none; }
.status-message { margin: 1rem 0; padding: .8rem 1rem; border-radius: 7px; background: var(--info-background); color: var(--info-ink); }
.status-message.error { background: var(--error-background); color: var(--error-ink); }
.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: var(--secret-background); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.sensitive-result { border-color: var(--sensitive-border); background: var(--sensitive-background); }
.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: var(--badge-ink); background: var(--badge-background); font-size: .76rem; font-weight: 650; }
.badge.ok { color: var(--success-ink); background: var(--success-background); }
.badge.warn { color: var(--warning-ink); background: var(--warning-background); }
.data-table tbody tr:nth-child(even) { background: var(--table-stripe); }
.data-table tbody tr:hover { background: var(--table-hover); }
.card { margin-top: 1rem; padding: 1.25rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-elevated); color: var(--ink); }
.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; }
  .theme-selector select { max-width: 76px; }
  .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; }
}
