:root {
  --brand: #8e2f7e;
  --brand-deep: #5f2260;
  --brand-dark: #3b1040;
  --brand-soft: #f8edf6;
}

html { min-height: 100%; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { min-height: 100%; margin: 0; font-family: Inter, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; letter-spacing: .008em; }
button, a, input, select, textarea { font: inherit; transition: border-color .15s, box-shadow .15s, background-color .15s, color .15s, opacity .15s; }
code { border-radius: .35rem; background: #f2f4f7; padding: .1rem .35rem; color: #5f2260; font-size: .85em; }

.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; overflow-x: hidden; }
.app-content { min-width: 0; flex: 1 1 0%; }
body.app-modal-open { overflow: hidden; }

.text-brand { color: var(--brand); }
.text-brand-deep { color: var(--brand-deep); }
.bg-brand-soft { background: var(--brand-soft); }

.brand-mark {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  border-radius: .9rem;
  background: linear-gradient(145deg, #a63e85, #5f2260);
  color: white;
  font-size: 1.15rem;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(94, 34, 96, .2);
}
.brand-mark.large { width: 4rem; height: 4rem; border-radius: 1.25rem; font-size: 1.65rem; }

.app-sidebar { box-shadow: 8px 0 30px rgba(16, 24, 40, .02); }
.app-sidebar.open { transform: translateX(0); }
.app-nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  border-radius: .75rem;
  padding: .7rem .8rem;
  color: #475467;
  font-size: .9rem;
  font-weight: 500;
}
.app-nav-item::before {
  display: grid;
  width: 2rem;
  height: 2rem;
  flex: 0 0 2rem;
  place-items: center;
  border-radius: .6rem;
  background: #f2f4f7;
  color: #667085;
  content: attr(data-icon);
  font-size: .75rem;
  font-weight: 700;
}
.app-nav-item:hover { background: #f9fafb; color: #1d2939; }
.app-nav-item.active { background: var(--brand-soft); color: var(--brand-deep); }
.app-nav-item.active::before { background: var(--brand); color: white; }

.app-icon-button {
  display: grid;
  width: 2.5rem;
  height: 2.5rem;
  place-items: center;
  border: 1px solid #e4e7ec;
  border-radius: .7rem;
  background: white;
  color: #344054;
}

.app-card { overflow: hidden; border: 1px solid #e4e7ec; border-radius: 1rem; background: white; box-shadow: 0 1px 3px rgba(16, 24, 40, .04); }
.app-card-header { display: flex; min-height: 4.75rem; align-items: center; justify-content: space-between; border-bottom: 1px solid #f2f4f7; padding: 1rem 1.25rem; }
.app-card-title { color: #101828; font-size: 1rem; font-weight: 650; }
.app-card-subtitle { margin-top: .2rem; color: #667085; font-size: .78rem; }

.app-modal-host:empty { display: none; }
.app-modal-host {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.app-modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(29, 13, 31, .62);
  cursor: default;
}
.app-modal-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 48rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, .6);
  border-radius: 1.15rem;
  background: white;
  box-shadow: 0 24px 70px rgba(35, 16, 39, .28);
  -webkit-overflow-scrolling: touch;
}
.app-modal-panel.compact { max-width: 40rem; }
.app-modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  min-height: 4.75rem;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #f2f4f7;
  background: rgba(255, 255, 255, .97);
  padding: 1rem 1.25rem;
}
.app-modal-body { padding: 1.25rem; }
.app-modal-close {
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  flex: 0 0 2.25rem;
  place-items: center;
  border: 1px solid #e4e7ec;
  border-radius: .7rem;
  background: white;
  color: #667085;
  font-size: 1.4rem;
  line-height: 1;
}
.app-modal-close:hover { border-color: #d0d5dd; background: #f9fafb; color: #344054; }
.app-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  border-top: 1px solid #f2f4f7;
  padding-top: 1.1rem;
}
.app-form-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }

.metric-card { display: flex; align-items: center; gap: 1rem; border: 1px solid #e4e7ec; border-radius: 1rem; background: white; padding: 1.25rem; box-shadow: 0 1px 3px rgba(16, 24, 40, .04); }
.metric-icon { display: grid; width: 3rem; height: 3rem; flex: 0 0 3rem; place-items: center; border-radius: .85rem; font-size: .85rem; font-weight: 700; }
.metric-icon.purple { background: #f8edf6; color: #8e2f7e; }
.metric-icon.blue { background: #eff8ff; color: #175cd3; }
.metric-icon.green { background: #ecfdf3; color: #027a48; }
.metric-icon.amber { background: #fffaeb; color: #b54708; }
.metric-value { color: #101828; font-size: 1.65rem; font-weight: 700; line-height: 1.1; }
.metric-label { margin-top: .3rem; color: #667085; font-size: .78rem; }

.app-table { width: 100%; min-width: 46rem; border-collapse: collapse; }
.app-table th { background: #fcfcfd; color: #667085; font-size: .72rem; font-weight: 600; letter-spacing: .02em; text-align: left; white-space: nowrap; }
.app-table th, .app-table td { border-bottom: 1px solid #f2f4f7; padding: .85rem 1rem; vertical-align: middle; }
.app-table td { color: #475467; font-size: .8rem; }
.app-table tbody tr:last-child td { border-bottom: 0; }
.app-table tbody tr:hover td { background: #fcfcfd; }
.empty-state { padding: 3rem 1rem !important; color: #98a2b3 !important; text-align: center; }

.app-label { display: block; margin-bottom: .4rem; color: #344054; font-size: .78rem; font-weight: 550; }
.app-input { display: block; width: 100%; border: 1px solid #d0d5dd; border-radius: .65rem; background: white; padding: .65rem .8rem; color: #101828; font-size: .86rem; outline: 0; }
.app-input:hover { border-color: #98a2b3; }
.app-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(142, 47, 126, .12); }
.app-input.compact { width: auto; min-width: 8rem; padding: .5rem .7rem; font-size: .8rem; }
.app-field-error { margin-top: .25rem; color: #d92d20; font-size: .72rem; }

.app-button { display: inline-flex; min-height: 2.6rem; align-items: center; justify-content: center; border-radius: .7rem; padding: .65rem 1rem; font-size: .86rem; font-weight: 600; }
.app-button.primary { border: 1px solid var(--brand); background: var(--brand); color: white; box-shadow: 0 2px 6px rgba(95, 34, 96, .16); }
.app-button.primary:hover { border-color: var(--brand-deep); background: var(--brand-deep); }
.app-button.secondary { border: 1px solid #d0d5dd; background: white; color: #344054; }
.app-button.secondary:hover { background: #f9fafb; }
.app-button.small { min-height: 2.25rem; padding: .45rem .75rem; font-size: .78rem; }
.app-button.htmx-request, .htmx-request .app-button { cursor: wait; opacity: .6; }
.app-link { color: var(--brand); font-size: .8rem; font-weight: 600; }
.app-link:hover { color: var(--brand-deep); text-decoration: underline; }
.app-link.danger { color: #d92d20; }

.app-badge { display: inline-flex; align-items: center; border-radius: 999px; background: #f2f4f7; padding: .25rem .55rem; color: #475467; font-size: .7rem; font-weight: 600; white-space: nowrap; }
.app-badge.success { background: #ecfdf3; color: #027a48; }
.app-badge.neutral { background: #f2f4f7; color: #475467; }
.app-badge.danger { background: #fef3f2; color: #b42318; }
.app-badge.purple { background: var(--brand-soft); color: var(--brand-deep); }

.app-alert { border: 1px solid; border-radius: .75rem; padding: .7rem .9rem; font-size: .8rem; line-height: 1.45; }
.app-alert.success { border-color: #abefc6; background: #ecfdf3; color: #067647; }
.app-alert.error { border-color: #fecdca; background: #fef3f2; color: #b42318; }
.app-alert.warning { border-color: #fedf89; background: #fffaeb; color: #93370d; }
.app-alert.info { border-color: #b2ddff; background: #eff8ff; color: #175cd3; }

.auth-body { min-height: 100vh; background: #f8f7fa; }
.auth-layout { display: grid; min-height: 100vh; grid-template-columns: minmax(0, 1.05fr) minmax(28rem, .95fr); }
.auth-brand-panel { position: relative; display: flex; overflow: hidden; align-items: center; padding: 4rem; background: linear-gradient(145deg, #341038 0%, #672567 48%, #a63e85 100%); }
.auth-brand-panel::before { position: absolute; inset: -20%; background: radial-gradient(circle at 65% 35%, rgba(255,255,255,.2), transparent 28%), radial-gradient(circle at 25% 80%, rgba(240,185,63,.18), transparent 25%); content: ""; }
.auth-brand-content { position: relative; z-index: 1; margin: 0 auto; width: 100%; max-width: 36rem; }
.auth-form-panel { display: flex; align-items: center; justify-content: center; background: white; padding: 3rem; }

@media (max-width: 1023px) {
  .auth-layout { display: block; }
  .auth-brand-panel { display: none; }
  .auth-form-panel { min-height: 100vh; padding: 2rem 1.25rem; }
}

@media (max-width: 639px) {
  .app-modal-host { align-items: flex-end; padding: .5rem; }
  .app-modal-panel { max-height: calc(100vh - 1rem); border-radius: 1rem; }
  .app-form-columns { grid-template-columns: minmax(0, 1fr); }
  .app-modal-actions .app-button { flex: 1 1 0%; }
}

@supports (height: 100dvh) {
  .app-modal-panel { max-height: calc(100dvh - 2rem); }
  @media (max-width: 639px) {
    .app-modal-panel { max-height: calc(100dvh - 1rem); }
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  button, a, input, select, textarea { transition: none; }
}
