:root {
  --navy: #073a63;
  --navy-deep: #052f52;
  --teal: #123f49;
  --cyan: #19a8e0;
  --mint: #5bd27b;
  --lime: #c8ff3d;
  --lavender: #d9c7ff;
  --orange: #ff9e26;
  --red: #e54868;
  --ink: #1d2330;
  --muted: #7a8795;
  --line: #e8edf3;
  --bg: #f5f7fa;
  --panel: #ffffff;
}

* { box-sizing: border-box; }

html { min-height: 100%; font-size: 15px; }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

a { color: inherit; text-decoration: none; }

button, input, select {
  font: inherit;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 230px;
  background: linear-gradient(180deg, #06345b, #073f70);
  color: #fff;
  padding: 24px 18px;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  margin-bottom: 34px;
}

.brand-mark {
  width: 28px;
  height: 18px;
  display: inline-block;
  border-radius: 16px 16px 6px 16px;
  background: linear-gradient(90deg, #f26a7d, #7b61ff, #ff9e26);
}

.profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0 22px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  margin-bottom: 22px;
}

.profile span, .muted { color: var(--muted); }

.profile span {
  display: block;
  color: #7ec7f2;
  font-size: .82rem;
}

.avatar {
  border: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #fff, #7ec7f2);
  color: var(--navy);
  font-weight: 800;
  overflow: hidden;
  flex: 0 0 auto;
  padding: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-button img {
  animation: avatarIdleWiggle 5.5s ease-in-out infinite;
  transform-origin: 50% 50%;
}

.avatar-button {
  cursor: pointer;
}

.avatar-button:hover,
.avatar-button:focus-visible {
  animation: avatarWiggle .62s ease-in-out;
}

.avatar-button:disabled,
.avatar-button[data-avatar-url=""] {
  cursor: default;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.side-nav a {
  display: block;
  padding: 12px 14px;
  border-radius: 8px;
  color: #8ec8ef;
  transition: .16s ease;
}

.side-nav a:hover {
  background: rgba(255,255,255,.12);
  color: #fff;
}

.topbar {
  position: fixed;
  inset: 0 0 auto 230px;
  height: 72px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 34px;
  z-index: 4;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 1.25rem;
  font-weight: 800;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.app-shell {
  margin-left: 230px;
  padding-top: 72px;
}

.login-shell {
  margin-left: 0;
  padding-top: 0;
}

.content {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: 28px 30px 48px;
}

.login-shell .content {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #cfdae0;
}

.login-card {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(8, 45, 70, .16);
}

.login-art {
  min-height: 560px;
  padding: 48px;
  background: var(--teal);
  color: #fff;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: end;
}

.login-art h2 {
  font-size: clamp(2rem, 5vw, 3.1rem);
  line-height: 1.05;
  max-width: 360px;
  margin: 0 0 16px;
}

.login-art p {
  max-width: 360px;
  color: #d4e7ec;
  margin: 0;
}

.orb { position: absolute; border-radius: 999px; }
.orb.lime { width: 360px; height: 180px; background: var(--lime); left: -40px; top: -56px; transform: rotate(13deg); }
.orb.lavender { width: 330px; height: 330px; background: var(--lavender); left: 44px; top: 150px; }
.orb.mint { width: 98px; height: 98px; background: var(--mint); right: 28px; top: 120px; }

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

.auth-form {
  padding: 48px;
  align-content: center;
}

.auth-form h1 {
  font-size: 1.9rem;
  margin: 0;
}

label {
  font-weight: 700;
  font-size: .88rem;
}

input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus, select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 4px rgba(25,168,224,.12);
}

.btn {
  border: 0;
  border-radius: 7px;
  padding: 11px 18px;
  font-weight: 800;
}

.btn-primary {
  background: linear-gradient(135deg, #148bd2, #22c6c3);
  color: #fff;
}

.btn-danger-soft {
  background: #ffe8ed;
  color: var(--red);
}

.hint {
  margin-top: 8px;
  padding: 10px;
  background: #eef8fb;
  color: var(--navy);
  border-radius: 8px;
  font-size: .9rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 22px;
  margin-bottom: 26px;
}

.stat-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(13, 41, 66, .07);
}

.stat-card {
  min-height: 126px;
  padding: 22px;
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 45px;
  background: linear-gradient(135deg, rgba(20,139,210,.2), rgba(255,158,38,.45));
  clip-path: polygon(0 70%, 25% 35%, 45% 64%, 72% 18%, 100% 72%, 100% 100%, 0 100%);
}

.stat-card span, .stat-card small {
  color: var(--muted);
  display: block;
}

.stat-card strong {
  display: block;
  font-size: 1.75rem;
  margin: 8px 0 2px;
  letter-spacing: 0;
}

.stat-card.dark, .dark-panel {
  background: var(--navy-deep);
  color: #fff;
}

.stat-card.dark span, .stat-card.dark small, .dark-panel p, .dark-panel span {
  color: #b7d6e5;
}

.up { color: #41b95d !important; }
.down, .danger-text { color: var(--red) !important; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.35fr .75fr;
  gap: 26px;
  margin-bottom: 26px;
}

.panel {
  padding: 22px;
}

.panel.narrow {
  max-width: 560px;
}

.panel h2 {
  margin: 0 0 18px;
  font-size: 1.05rem;
  font-weight: 800;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-head h2 { margin: 0; }
.panel-head a { color: #148bd2; font-weight: 800; }

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

.quick-actions a {
  min-height: 78px;
  display: grid;
  place-items: center;
  padding: 14px;
  border-radius: 8px;
  background: #eef7fb;
  color: var(--navy);
  font-weight: 800;
}

.dark-panel {
  min-height: 190px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.dark-panel strong {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: 0;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th, td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  font-size: .78rem;
  text-transform: uppercase;
  color: var(--muted);
}

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

.row-actions button {
  border: 0;
  background: #edf7fd;
  color: var(--navy);
  border-radius: 6px;
  padding: 7px 10px;
  font-weight: 700;
}

.table-action-link {
  display: inline-block;
  border: 0;
  background: #edf7fd;
  color: var(--navy);
  border-radius: 6px;
  padding: 7px 10px;
  font-weight: 700;
}

.inline-form {
  min-width: 150px;
}

.avatar-editor {
  width: min(320px, 100%);
  aspect-ratio: 1;
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: #eef7fb;
  border: 1px solid var(--line);
  touch-action: none;
}

.avatar-editor canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

.avatar-editor:active canvas {
  cursor: grabbing;
}

.avatar-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 18px;
  box-shadow:
    inset 0 0 0 999px rgba(5, 47, 82, .22),
    inset 0 0 0 2px rgba(255, 255, 255, .85);
  clip-path: circle(50% at 50% 50%);
}

.avatar-current {
  align-items: center;
  text-align: center;
}

.avatar-current img {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid rgba(255,255,255,.55);
  margin: 16px 0;
}

.avatar-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.avatar-modal.open {
  display: flex;
}

.avatar-modal.open .avatar-modal-content img {
  animation: avatarPopupWiggle .72s ease-out;
}

.avatar-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 17, 28, .72);
  backdrop-filter: blur(4px);
}

.avatar-modal-content {
  position: relative;
  width: min(420px, 86vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.avatar-modal-content img,
.avatar-modal-placeholder {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 6px solid rgba(255, 255, 255, .72);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .35);
}

.avatar-modal-content img {
  object-fit: cover;
}

.avatar-modal-placeholder {
  display: none;
  place-items: center;
  background: linear-gradient(135deg, #d9c7ff, #5bd27b);
  color: var(--navy);
  font-size: clamp(4rem, 18vw, 7rem);
  font-weight: 900;
}

.avatar-modal.no-image .avatar-modal-content img {
  display: none;
}

.avatar-modal.no-image .avatar-modal-placeholder {
  display: grid;
}

.avatar-modal-close {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--navy);
  font-weight: 900;
  font-size: 1.25rem;
  line-height: 1;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .24);
  z-index: 2;
}

.avatar-modal-change {
  position: absolute;
  left: 50%;
  bottom: -58px;
  transform: translateX(-50%);
  min-width: 120px;
  padding: 11px 16px;
  border-radius: 999px;
  background: #fff;
  color: var(--navy);
  text-align: center;
  font-weight: 900;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .24);
}

.message-box {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  z-index: 120;
}

.message-box.open {
  display: flex;
}

.message-box-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 17, 28, .62);
  backdrop-filter: blur(4px);
}

.message-box-content {
  position: relative;
  width: min(420px, 100%);
  background: #fff;
  border-radius: 10px;
  padding: 26px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
  text-align: center;
}

.message-box-content h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
  font-weight: 900;
}

.message-box-content p {
  margin: 0 0 20px;
  color: var(--ink);
  font-weight: 700;
}

.message-box-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #eef7fb;
  color: var(--navy);
  font-weight: 900;
}

.user-list-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(135deg, #d9c7ff, #5bd27b);
  color: var(--navy);
  font-weight: 900;
  border: 2px solid #fff;
  box-shadow: 0 8px 18px rgba(13, 41, 66, .12);
}

.user-list-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

@keyframes avatarWiggle {
  0%, 100% { transform: rotate(0deg) scale(1); }
  15% { transform: rotate(-8deg) scale(1.04); }
  30% { transform: rotate(7deg) scale(1.04); }
  45% { transform: rotate(-5deg) scale(1.03); }
  60% { transform: rotate(4deg) scale(1.02); }
  75% { transform: rotate(-2deg) scale(1.01); }
}

@keyframes avatarIdleWiggle {
  0%, 84%, 100% { transform: rotate(0deg) scale(1); }
  88% { transform: rotate(-5deg) scale(1.03); }
  92% { transform: rotate(4deg) scale(1.03); }
  96% { transform: rotate(-2deg) scale(1.01); }
}

@keyframes avatarPopupWiggle {
  0% { transform: rotate(0deg) scale(.88); opacity: 0; }
  18% { transform: rotate(-7deg) scale(1.04); opacity: 1; }
  34% { transform: rotate(6deg) scale(1.02); }
  50% { transform: rotate(-4deg) scale(1.01); }
  66% { transform: rotate(3deg) scale(1); }
  82% { transform: rotate(-1deg) scale(1); }
  100% { transform: rotate(0deg) scale(1); opacity: 1; }
}

.mobile-nav {
  display: none;
}

.mobile-logout-form {
  margin: 0;
}

canvas {
  width: 100%;
  max-width: 100%;
}

@media (max-width: 860px) {
  body {
    background: #cfdae0;
  }

  .sidebar, .topbar {
    display: none;
  }

  .app-shell {
    margin-left: 0;
    padding-top: 0;
    padding-bottom: 76px;
  }

  .content {
    padding: 18px 16px 22px;
  }

  .login-shell .content {
    padding: 0;
  }

  .login-card {
    min-height: 100svh;
    grid-template-columns: 1fr;
    border-radius: 0;
    background: var(--teal);
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .login-art {
    min-height: 250px;
    padding: 28px 28px 46px;
    border-radius: 0 0 28px 28px;
    justify-content: end;
  }

  .login-art h2 {
    font-size: 2rem;
  }

  .orb.lime { width: 260px; height: 130px; }
  .orb.lavender { width: 200px; height: 200px; left: 28px; top: 96px; }
  .orb.mint { width: 70px; height: 70px; right: 20px; top: 88px; }

  .auth-form {
    margin: -30px 16px 18px;
    padding: 20px;
    border-radius: 26px;
    background: #fff;
    z-index: 2;
    gap: 8px;
  }

  .auth-form h1 {
    font-size: 1.55rem;
  }

  .auth-form input {
    min-height: 40px;
  }

  .stat-grid, .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 14px;
  }

  .stat-card, .panel {
    border-radius: 22px;
    box-shadow: 0 10px 28px rgba(18,63,73,.1);
  }

  .stat-card.dark, .dark-panel {
    background: var(--teal);
  }

  .panel {
    padding: 18px;
  }

  .quick-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .quick-actions a {
    min-height: 68px;
    border-radius: 18px;
    background: #f1eefb;
    font-size: .9rem;
    text-align: center;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  table {
    min-width: 560px;
  }

  .mobile-nav {
    position: fixed;
    inset: auto 16px 14px;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
    background: #fff;
    border-radius: 22px;
    box-shadow: 0 14px 40px rgba(18,63,73,.18);
    z-index: 10;
  }

  .mobile-nav a,
  .mobile-nav button {
    width: 100%;
    border: 0;
    background: transparent;
    padding: 10px 4px;
    text-align: center;
    border-radius: 16px;
    color: var(--teal);
    font-weight: 800;
    font-size: .86rem;
  }

  .mobile-nav a:hover,
  .mobile-nav button:hover {
    background: var(--teal);
    color: #fff;
  }

  .mobile-avatar-button {
    position: relative;
    display: grid;
    place-items: center;
    padding: 0 !important;
    margin-top: -22px;
    background: transparent !important;
  }

  .mobile-avatar {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    overflow: hidden;
    background: linear-gradient(135deg, #d9c7ff, #5bd27b);
    color: var(--navy);
    border: 5px solid #fff;
    box-shadow: 0 12px 30px rgba(18,63,73,.24);
    font-weight: 900;
    animation: avatarIdleWiggle 5.5s ease-in-out infinite;
  }

  .mobile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }

  .mobile-logout-form button {
    color: var(--red);
  }

  .avatar-modal-content {
    width: min(330px, 82vw);
  }

  .avatar-modal-change {
    bottom: -54px;
  }
}
