:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #6f746f;
  --line: #e2d9cc;
  --surface: #ffffff;
  --canvas: #faf6f1;
  --soft: #f4eee6;
  --wash: #ede3d7;
  --accent: #7a8b7a;
  --accent-dark: #556a59;
  --terracotta: #d5724a;
  --danger: #a0433c;
  --danger-dark: #7f2e2e;
  --ok: #687f68;
  --warn: #a9633f;
  --shadow: 0 14px 34px rgba(17, 24, 39, 0.07);
  --page-max: 1180px;
  --page-pad-x: 20px;
  --body-size: 15px;
  --app-header-height: 73px;
  --touch-target: 44px;
  --focus-ring: 0 0 0 3px rgba(122, 139, 122, 0.28);
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(180deg, var(--canvas) 0, #fff 390px);
  font-size: var(--body-size);
  min-width: 320px;
  overflow-x: hidden;
}

header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 246, 241, 0.98);
  backdrop-filter: blur(8px);
}

.topbar {
  max-width: var(--page-max);
  margin: 0 auto;
  padding:
    calc(16px + var(--safe-area-top))
    max(var(--page-pad-x), var(--safe-area-right))
    16px
    max(var(--page-pad-x), var(--safe-area-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-brand {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-lockup h1 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand,
.brand-lockup {
  display: flex;
  align-items: center;
}

.brand { gap: 14px; }

.brand-lockup {
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
}

.topbar-actions {
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-left: auto;
  min-width: min(520px, 100%);
}

.auth-entry {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.sign-in-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  color: #fff;
  background: var(--ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.sign-in-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.account-menu {
  position: relative;
}

.account-button {
  max-width: min(320px, 48vw);
  min-height: var(--touch-target);
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-dark);
  background: rgba(237, 227, 215, 0.54);
  font-size: 13px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-button:hover,
.account-button[aria-expanded="true"] {
  color: #fff;
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.account-panel {
  position: absolute;
  z-index: 120;
  top: calc(100% + 8px);
  right: 0;
  width: min(280px, calc(100vw - 28px));
  max-height: calc(100dvh - var(--app-header-height) - 18px - var(--safe-area-bottom));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 249, 0.98);
  box-shadow: var(--shadow);
}

.account-context {
  display: grid;
  gap: 3px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}

.account-context strong {
  font-size: 13px;
}

.account-context span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.account-action {
  width: 100%;
  justify-content: start;
  color: var(--ink);
  border-color: transparent;
  background: transparent;
  text-align: left;
}

.account-action:hover {
  color: #fff;
  background: var(--ink);
}

.nav-menu {
  position: relative;
  z-index: 110;
  flex: 0 0 auto;
}

.menu-button {
  width: var(--touch-target);
  height: var(--touch-target);
  border-color: transparent;
  padding: 4px;
  display: inline-grid;
  place-items: center;
  background: transparent;
}

.menu-button img {
  width: 34px;
  height: 34px;
  display: block;
}

.menu-button:hover,
.menu-button[aria-expanded="true"] {
  border-color: var(--line);
  background: #fffdf9;
  box-shadow: 0 8px 18px rgba(17, 24, 39, 0.08);
}

.menu-panel {
  position: absolute;
  z-index: 120;
  top: calc(100% + 10px);
  left: 0;
  width: min(320px, calc(100vw - 32px));
  max-height: calc(100dvh - var(--app-header-height) - 18px - var(--safe-area-bottom));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fffdf9;
  box-shadow: 0 20px 48px rgba(17, 24, 39, 0.18);
  isolation: isolate;
}

.menu-panel[hidden] {
  display: none;
}

.menu-title {
  padding: 9px 10px 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.menu-item {
  display: grid;
  gap: 3px;
  border-radius: 7px;
  padding: 10px;
  color: var(--ink);
  text-decoration: none;
}

.menu-item:hover,
.menu-item.active {
  background: var(--soft);
}

.menu-item strong {
  font-size: 14px;
}

.menu-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  min-height: var(--touch-target);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 12px;
  background: #fffdf9;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.35;
}

textarea {
  resize: vertical;
}

button,
.nav-link {
  min-height: var(--touch-target);
  border: 1px solid var(--ink);
  border-radius: 7px;
  padding: 10px 14px;
  color: #fff;
  background: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

button:hover,
.nav-link:hover {
  background: #26343b;
}

button.secondary,
.nav-link.secondary {
  color: var(--ink);
  border-color: var(--line);
  background: #fff;
}

button.secondary:hover,
.nav-link.secondary:hover {
  color: #fff;
  border-color: var(--ink);
  background: var(--ink);
}

button.danger {
  border-color: var(--danger);
  background: var(--danger);
}

button.danger:hover { background: var(--danger-dark); }

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button:focus-visible,
.nav-link:focus-visible,
.menu-item:focus-visible,
.sign-in-button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

header + main {
  padding-left: max(var(--page-pad-x), var(--safe-area-left));
  padding-right: max(var(--page-pad-x), var(--safe-area-right));
  padding-bottom: calc(40px + var(--safe-area-bottom));
}

.admin-tools {
  padding-left: max(var(--page-pad-x), var(--safe-area-left));
  padding-right: max(var(--page-pad-x), var(--safe-area-right));
}

.status {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.status.ok { color: var(--ok); }
.status.error { color: var(--danger); }

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.app-time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
}

.section-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 249, 0.94);
  box-shadow: var(--shadow);
}

.empty {
  color: var(--muted);
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--soft);
}

@media (max-width: 820px) {
  .topbar-actions {
    min-width: 0;
  }
  .topbar-actions {
    justify-content: stretch;
    margin-left: 0;
  }
  .auth-entry {
    justify-content: stretch;
    width: 100%;
  }
  .sign-in-button {
    justify-content: center;
    text-align: center;
    width: 100%;
  }
  .account-menu,
  .account-button {
    width: 100%;
  }
}

@media (max-width: 640px) {
  header .topbar {
    align-items: center;
    flex-direction: row;
    gap: 10px;
    padding-top: calc(10px + var(--safe-area-top));
    padding-bottom: 10px;
  }
  header .topbar-brand {
    flex: 1 1 auto;
    gap: 9px;
  }
  header .topbar-actions {
    flex: 0 1 auto;
    justify-content: flex-end;
    width: auto;
    min-width: 0;
    margin-left: auto;
  }
  header .auth-entry {
    width: auto;
  }
  header .sign-in-button {
    width: auto;
    padding-inline: 12px;
  }
  header .account-menu,
  header .account-button {
    width: auto;
  }
  header .account-button {
    max-width: 42vw;
  }
  header .brand-lockup h1 {
    font-size: 18px;
  }
  .menu-button img {
    width: 32px;
    height: 32px;
  }
  .menu-panel,
  .account-panel {
    position: fixed;
    top: calc(var(--app-header-height) + 8px);
    left: max(12px, var(--safe-area-left));
    right: max(12px, var(--safe-area-right));
    width: auto;
  }
}
