:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f5f7fb);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #172033);
  --muted: var(--tg-theme-hint-color, #6e7a8b);
  --line: rgba(105, 119, 140, 0.24);
  --accent: var(--tg-theme-button-color, #2d73ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --good: #16845f;
  --warn: #be7b16;
  --danger: #bf334d;
  --shadow: 0 10px 24px rgba(18, 28, 45, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(45, 115, 255, 0.10), transparent 240px),
    var(--bg);
}

body[data-theme="green"] {
  --accent: #16845f;
}

body[data-theme="rose"] {
  --accent: #bf3f66;
}

body[data-theme="amber"] {
  --accent: #b06f13;
}

body[data-theme="ink"] {
  --accent: #3d5874;
}

body[data-theme="violet"] {
  --accent: #7352c7;
}

.watermark-dots {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.watermark-dots span {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text), transparent 76%);
  opacity: 0.34;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

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

.is-busy button,
.is-busy input,
.is-busy select {
  opacity: 0.62;
}

.app-shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

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

.brand-logo {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 15ch;
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.06;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 16px;
  line-height: 1.2;
}

.identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface), transparent 8%);
  color: var(--text);
  text-align: left;
}

.identity:disabled {
  cursor: default;
  opacity: 1;
}

.avatar {
  display: grid;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--good));
  color: #ffffff;
  font-size: 13px;
  font-weight: 900;
}

.identity-text {
  min-width: 0;
}

.identity-name,
.identity-role {
  display: block;
  overflow: hidden;
  max-width: 170px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity-name {
  font-size: 14px;
  font-weight: 800;
}

.identity-role {
  color: var(--muted);
  font-size: 12px;
}

.login-panel,
.voice-panel,
.panel {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-note {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.voice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.impersonation-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--accent), transparent 60%);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent), transparent 90%);
}

.impersonation-banner strong,
.impersonation-banner span {
  display: block;
}

.impersonation-banner span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.login-actions {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.google-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  font-weight: 850;
  text-decoration: none;
}

.login-note,
.login-divider {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.login-divider {
  margin-bottom: 10px;
  font-weight: 800;
}

.needs-voice .tabs,
.needs-voice .view {
  display: none;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.metric {
  min-height: 74px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-value,
.metric-label {
  display: block;
}

.metric-value {
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.metric-label {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 14px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface), transparent 20%);
}

.tab {
  min-height: 38px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.tab.is-active {
  color: var(--accent-text);
  background: var(--accent);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.inline-form,
.profile-form,
.two-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.profile-form,
.two-cols {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.profile-code {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.profile-drawer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: start end;
  padding: 16px;
  background: rgba(12, 18, 30, 0.34);
}

.profile-card {
  width: min(420px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 46px rgba(18, 28, 45, 0.22);
}

.profile-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.profile-meta div {
  min-height: 54px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface), var(--bg) 34%);
}

.profile-meta span,
.profile-meta strong {
  display: block;
}

.profile-meta span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.profile-meta strong {
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.icon-button {
  min-width: 42px;
  width: 42px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.stack-form,
.admin-release-form {
  display: grid;
  gap: 10px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
.urgency-select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: color-mix(in srgb, var(--surface), var(--bg) 34%);
  color: var(--text);
  padding: 0 12px;
}

input:focus,
select:focus,
.urgency-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 78%);
}

.primary-button,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  padding: 0 14px;
  font-weight: 850;
}

.primary-button {
  color: var(--accent-text);
  background: var(--accent);
}

.ghost-button {
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--surface);
}

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

.list {
  display: grid;
  gap: 8px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 0 10px;
}

.section-head h2 {
  margin-bottom: 0;
}

.release-card,
.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.release-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.release-main,
.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.item {
  min-height: 64px;
  padding: 12px;
}

.item-title {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 850;
}

.item-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
}

.pill.open {
  color: var(--good);
  background: color-mix(in srgb, var(--good), transparent 86%);
}

.pill.closed {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn), transparent 84%);
}

.slot-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.slot-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted), transparent 84%);
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.booking-names {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--muted), transparent 92%);
  color: var(--muted);
  font-size: 13px;
}

.booking-names p {
  margin: 0;
  overflow-wrap: anywhere;
}

.release-link {
  margin-left: 8px;
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.card-actions,
.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.empty {
  min-height: 72px;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface), transparent 28%);
  line-height: 1.4;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 10;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  color: var(--accent-text);
  background: color-mix(in srgb, var(--text), #000000 8%);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 780px) {
  .admin-grid,
  .inline-form,
  .profile-form,
  .profile-meta,
  .two-cols {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .ghost-button,
  .danger-button {
    width: 100%;
  }

  .impersonation-banner {
    display: grid;
  }
}

@media (max-width: 460px) {
  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .brand-logo {
    width: 44px;
    height: 44px;
  }

  h1 {
    font-size: 25px;
  }

  .identity {
    width: 100%;
  }

  .identity-name,
  .identity-role {
    max-width: calc(100vw - 96px);
  }

  .status-grid,
  .slot-row,
  .release-main,
  .item {
    grid-template-columns: 1fr;
  }

  .card-actions,
  .item-actions {
    justify-content: stretch;
  }
}
