@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap");

:root {
  --bg0: #dcdad6;
  --bg1: #f3f2ef;
  --bg2: #ebe9e5;
  --surface: #ffffff;
  --line: rgba(44, 43, 41, 0.08);
  --text: #2c2b29;
  --muted: #6f6d69;
  --accent: #b8956a;
  --accent-soft: rgba(184, 149, 106, 0.18);
  --ok: #5a8f6e;
  --bad: #c06a5c;
  --warn: #b89a4a;
  --shadow: 0 8px 24px rgba(40, 38, 35, 0.1);
  --shadow-soft: 0 4px 14px rgba(40, 38, 35, 0.08);
  --rail-w: 200px;
  --tools-w: 56px;
  --panel-w: 300px;
  --r: 14px;
  --r-pill: 999px;
  --ease: 0.22s ease;
  --ease-pill: 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  --font: "Manrope", system-ui, sans-serif;
  --display: "Manrope", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg0);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button {
  transition:
    background-color var(--ease),
    border-color var(--ease),
    color var(--ease),
    box-shadow var(--ease);
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.boot-screen {
  height: 100%;
  display: grid;
  place-items: center;
  background: var(--bg0);
}

.boot-screen[hidden],
#app[hidden],
#loginScreen[hidden] {
  display: none !important;
}

.boot-card {
  text-align: center;
  color: var(--muted);
}

.boot-brand {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--text);
  margin-bottom: 8px;
}

.boot-text {
  margin: 0;
  font-size: 0.85rem;
}

.login-screen {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg0);
}

.login-card {
  width: min(380px, 100%);
  padding: 26px 22px;
  background: var(--surface);
  border: none;
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.2rem;
  margin-bottom: 6px;
}

.login-lede {
  color: var(--muted);
  margin: 0 0 16px;
  font-size: 0.85rem;
}

.login-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 0.75rem;
  color: var(--muted);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-list li.off {
  opacity: 0.55;
}

.audit {
  max-height: 120px;
  overflow: auto;
  background: var(--bg2);
  border-radius: var(--r);
  padding: 8px 10px;
}

.audit-line {
  font-size: 0.72rem;
  color: var(--muted);
  padding: 2px 0;
}

#btnLogout {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.78rem;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: transparent;
  min-height: 48px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 8px;
}

.brand-name {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1rem;
}

.brand-tag {
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 3px 8px;
  border-radius: var(--r-pill);
}

.diag {
  display: flex;
  gap: 6px;
}

.diag-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: var(--r-pill);
  cursor: pointer;
  min-height: 34px;
}

.diag-item:hover {
  color: var(--text);
}

.diag-item[data-state="ok"] .diag-dot {
  background: var(--ok);
}

.diag-item[data-state="bad"] .diag-dot {
  background: var(--bad);
}

.diag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
}

.user-chip {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}

.user-name {
  white-space: nowrap;
}

.shell {
  flex: 1;
  display: grid;
  grid-template-columns: var(--rail-w) 1fr var(--tools-w);
  gap: 10px;
  min-height: 0;
  padding: 0 10px 10px;
  transition: grid-template-columns 0.22s ease;
}

.shell.panel-open {
  grid-template-columns: var(--rail-w) 1fr var(--tools-w) var(--panel-w);
}

.rail {
  background: transparent;
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.rail-label,
.rail-hint {
  margin: 0;
  padding: 0 10px;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.rail-hint {
  margin-top: auto;
  padding-bottom: 6px;
  opacity: 0.8;
}

.rail-nav {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  min-height: 0;
}

.rail-pill {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-radius: var(--r-pill);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  transition:
    transform var(--ease-pill),
    width var(--ease-pill),
    height var(--ease-pill),
    opacity 0.18s ease;
}

.rail-btn {
  position: relative;
  z-index: 1;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: var(--r-pill);
  cursor: pointer;
  min-height: 44px;
}

.rail-btn:hover {
  color: var(--text);
}

.rail-btn.active {
  color: var(--text);
  font-weight: 600;
  background: transparent;
}

.rail-btn .sub {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--muted);
  margin-top: 2px;
}

.stage {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 16px 18px;
  background: var(--bg1);
  border-radius: var(--r);
  box-shadow: var(--shadow-soft);
}

.stage.stage-enter {
  animation: stageFade 0.18s ease;
}

@keyframes stageFade {
  from {
    opacity: 0.55;
  }
  to {
    opacity: 1;
  }
}

.side-tools {
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}

.tool-btn {
  width: 48px;
  min-height: 48px;
  border: none;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  color: var(--muted);
  border-radius: var(--r);
  padding: 8px 2px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font: inherit;
}

.tool-btn:hover {
  color: var(--text);
}

.tool-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
}

.tool-glyph {
  font-size: 1rem;
  line-height: 1;
}

.tool-name {
  font-size: 0.6rem;
  letter-spacing: 0.03em;
}

.panel {
  background: var(--bg1);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  animation: panelIn 0.22s ease;
}

@keyframes panelIn {
  from {
    opacity: 0.4;
    transform: translateX(8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.panel[hidden] {
  display: none !important;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  min-height: 44px;
}

.panel-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.panel-close {
  border: none;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  color: var(--muted);
  font-size: 1.15rem;
  cursor: pointer;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
}

.panel-close:hover {
  color: var(--text);
}

.panel-body {
  padding: 0;
  overflow: hidden;
  flex: 1;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-body p {
  margin: 0 0 8px;
  padding: 12px 14px;
}

.module-frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: transparent;
  min-height: 0;
}

.stage-empty {
  max-width: 360px;
  margin-top: 6vh;
}

.stage-empty h1 {
  font-weight: 600;
  font-size: 1.2rem;
  margin: 0 0 8px;
}

.stage-empty p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.updates-gate {
  max-width: 520px;
  margin: 24px auto;
}

.updates-list {
  margin: 12px 0;
  padding-left: 1.2em;
  color: var(--text);
}

.updates-list li {
  margin: 6px 0;
}

.card {
  background: var(--surface);
  border: none;
  border-radius: var(--r);
  box-shadow: var(--shadow-soft);
  padding: 16px 18px;
  max-width: 900px;
}

.card h1 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 6px;
}

.card .lede {
  color: var(--muted);
  margin: 0 0 12px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 12px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  border: none;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.btn:hover:not(:disabled) {
  box-shadow: var(--shadow);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-soft);
  color: #6a4f2e;
  font-weight: 600;
  box-shadow: var(--shadow-soft);
}

.btn-primary:hover:not(:disabled) {
  background: rgba(184, 149, 106, 0.28);
}

.btn-ghost {
  background: transparent;
  box-shadow: none;
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.35);
  box-shadow: none;
}

.msg {
  font-size: 0.85rem;
  padding: 10px 12px;
  border-radius: var(--r);
  margin-bottom: 10px;
  background: var(--bg2);
  line-height: 1.4;
}

.msg.ok {
  background: rgba(90, 143, 110, 0.12);
  color: #2f5a3e;
}

.msg.bad {
  background: rgba(192, 106, 92, 0.12);
  color: #8a3d34;
}

.msg.info {
  color: var(--muted);
}

.password-once {
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: var(--r);
  padding: 16px 18px;
  margin-bottom: 14px;
  border: 1px solid rgba(184, 149, 106, 0.35);
}

.password-once-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 6px;
}

.password-once-value {
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.04em;
  word-break: break-all;
}

.password-once-hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  background: var(--bg2);
  border-radius: var(--r);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.75rem;
}

tr:last-child td {
  border-bottom: none;
}

.input,
select.input,
textarea.input {
  font: inherit;
  color: var(--text);
  background: var(--bg2);
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 42px;
  width: 100%;
}

.input:focus {
  outline: 2px solid rgba(184, 149, 106, 0.35);
  background: var(--surface);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text);
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 14px;
}

.admin-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--bg2);
  border-radius: var(--r);
  overflow: hidden;
}

.admin-list li {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}

.admin-list li:last-child {
  border-bottom: none;
}

.admin-list li:hover,
.admin-list li.active {
  background: var(--surface);
}

.admin-list li.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.subhead {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0 0 8px;
}

.grant-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mono {
  font-family: var(--mono);
}

.rail-empty {
  margin: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

@media (max-width: 900px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 14px;
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 12px 6px;
  }

  .brand-tag {
    display: none;
  }

  .diag {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .user-chip {
    justify-self: stretch;
    justify-content: space-between;
  }

  .shell,
  .shell.panel-open {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto auto;
    gap: 8px;
    padding: 0 8px 8px;
  }

  .rail {
    order: 2;
    flex-direction: row;
    align-items: center;
    width: 100%;
    overflow-x: auto;
    padding: 4px;
  }

  .rail-label,
  .rail-hint {
    display: none;
  }

  .rail-nav,
  #miniApps {
    display: flex;
    flex-direction: row;
    gap: 4px;
    width: max-content;
    min-width: 100%;
    padding: 4px;
  }

  .rail-btn {
    flex: 0 0 auto;
    min-width: 88px;
    text-align: center;
    padding: 10px 16px;
  }

  .rail-btn .sub {
    display: none;
  }

  .stage {
    order: 1;
    min-height: 0;
  }

  .side-tools {
    order: 3;
    flex-direction: row;
    width: 100%;
    justify-content: center;
    gap: 10px;
    padding: 4px;
  }

  .shell.panel-open .panel {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 8px;
    top: auto;
    height: min(70vh, 520px);
    width: auto;
    z-index: 40;
    animation: panelUp 0.22s ease;
  }

  @keyframes panelUp {
    from {
      opacity: 0.4;
      transform: translateY(12px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .login-card {
    width: min(100%, 400px);
    margin: 0 12px;
  }

  .updates-gate {
    margin: 12px;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rail-pill {
    transition: none !important;
  }

  .stage.stage-enter,
  .panel,
  .shell.panel-open .panel {
    animation: none !important;
  }

  button {
    transition: none;
  }
}
