:root {
  color-scheme: dark;
  --bg: #070a10;
  --bg-raised: #0c111a;
  --panel: rgba(16, 23, 33, 0.82);
  --panel-strong: rgba(21, 29, 41, 0.94);
  --panel-soft: rgba(24, 33, 46, 0.66);
  --panel-border: rgba(255, 255, 255, 0.1);
  --panel-border-strong: rgba(255, 255, 255, 0.18);
  --text: rgba(255, 255, 255, 0.96);
  --muted: rgba(255, 255, 255, 0.62);
  --faint: rgba(255, 255, 255, 0.42);
  --blue: #2f8fff;
  --blue-pressed: #2475d6;
  --gold: #d8b46a;
  --green: #45c77a;
  --mint: #58c7a8;
  --red: #f25f5c;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px) 0 0 / 82px 82px,
    linear-gradient(180deg, rgba(47, 143, 255, 0.15), transparent 34rem),
    linear-gradient(180deg, var(--bg-raised), var(--bg) 46%, #05070b);
  color: var(--text);
  font-family: "Avenir Next", "Geist", "Satoshi", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, transparent, rgba(88, 199, 168, 0.05), transparent 58%),
    linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.2));
}

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

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  border-right: 1px solid var(--panel-border);
  background: rgba(5, 8, 13, 0.76);
  backdrop-filter: blur(24px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 42px;
  margin-bottom: 30px;
  font-size: 1.08rem;
  font-weight: 860;
}

.brand > span:not(.brand-icon) {
  color: var(--gold);
}

.brand-icon,
.login-brand > span {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid rgba(47, 143, 255, 0.38);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.15), transparent),
    url("/images/kalotrack-logo.png") center / cover no-repeat;
  box-shadow: 0 14px 36px rgba(47, 143, 255, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.login-brand > span {
  color: transparent;
  font-size: 0;
}

.nav {
  display: grid;
  gap: 7px;
}

.nav a {
  position: relative;
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--muted);
  font-weight: 690;
  transition: color 220ms var(--ease), background 220ms var(--ease), border-color 220ms var(--ease), transform 220ms var(--ease);
}

.nav a:hover {
  color: var(--text);
  border-color: rgba(47, 143, 255, 0.18);
  background: rgba(47, 143, 255, 0.09);
  transform: translateX(3px);
}

.logout-form {
  margin-top: auto;
}

.logout-form button {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(242, 95, 92, 0.24);
  border-radius: 14px;
  color: #ffc4c2;
  background: rgba(242, 95, 92, 0.08);
  font: inherit;
  font-weight: 780;
  cursor: pointer;
  transition: transform 220ms var(--ease), background 220ms var(--ease), border-color 220ms var(--ease);
}

.logout-form button:hover {
  background: rgba(242, 95, 92, 0.13);
  border-color: rgba(242, 95, 92, 0.34);
  transform: translateY(-1px);
}

.content {
  display: grid;
  gap: 24px;
  min-width: 0;
  padding: 36px;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  padding-bottom: 8px;
  animation: riseIn 520ms var(--ease) both;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.2rem, 4vw, 4.6rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.hero p {
  max-width: 680px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.65;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.kpi {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid.split {
  grid-template-columns: 1.35fr 1fr;
}

.card {
  position: relative;
  overflow: hidden;
  padding: 22px;
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), transparent),
    var(--panel);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  animation: riseIn 560ms var(--ease) both;
  transition: transform 240ms var(--ease), border-color 240ms var(--ease), background 240ms var(--ease);
}

.card:hover {
  transform: translateY(-2px);
  border-color: rgba(47, 143, 255, 0.22);
}

.card h2,
.card h3 {
  margin-top: 0;
}

.access-card {
  border-color: rgba(47, 143, 255, 0.24);
}

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

.access-link {
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  transition: transform 220ms var(--ease), border-color 220ms var(--ease), background 220ms var(--ease);
}

.access-link:hover {
  transform: translateY(-2px);
  border-color: rgba(47, 143, 255, 0.28);
  background: rgba(47, 143, 255, 0.08);
}

.access-link span,
.metric-label,
.muted {
  color: var(--muted);
}

.access-link strong {
  color: #b9dcff;
  overflow-wrap: anywhere;
}

.metric-value {
  margin-top: 8px;
  color: var(--text);
  font-family: "Geist Mono", "SF Mono", Consolas, monospace;
  font-size: 2.2rem;
  font-weight: 760;
}

.pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(47, 143, 255, 0.22);
  border-radius: 999px;
  color: #d9eaff;
  background: rgba(47, 143, 255, 0.14);
}

.pill.success {
  border-color: rgba(69, 199, 122, 0.25);
  color: #bbf7d0;
  background: rgba(69, 199, 122, 0.14);
}

.pill.warning {
  border-color: rgba(216, 180, 106, 0.25);
  color: #ffe5a3;
  background: rgba(216, 180, 106, 0.14);
}

.pill.compact {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.pill.compact.surplus {
  border-color: rgba(242, 95, 92, 0.24);
  color: #ffc4c2;
  background: rgba(242, 95, 92, 0.12);
}

.pill.compact.deficit {
  border-color: rgba(69, 199, 122, 0.24);
  color: #bbf7d0;
  background: rgba(69, 199, 122, 0.12);
}

.pill.compact.maintenance {
  border-color: rgba(47, 143, 255, 0.24);
  color: #bfdbfe;
  background: rgba(47, 143, 255, 0.12);
}

.stack {
  display: grid;
  gap: 12px;
}

.thread {
  padding: 15px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.035);
}

.thread header,
.chat-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.message {
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: 10px;
}

.message strong,
.message small,
.stat-grid strong,
.stat-grid span,
.switch-row span,
.switch-row small {
  display: block;
}

.message small,
.thread-preview span,
.thread-preview small,
.chat-message small,
.switch-row small,
.secret-box small {
  color: var(--muted);
}

.message-list,
.chat-stack,
.chat-reply-form,
.reply-form,
.inline-form,
.settings-form {
  display: grid;
  gap: 12px;
}

.support-inbox {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.thread-list-panel {
  position: sticky;
  top: 24px;
  display: grid;
  gap: 14px;
}

.panel-title {
  font-weight: 820;
}

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

.thread-preview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.035);
  transition: transform 220ms var(--ease), border-color 220ms var(--ease), background 220ms var(--ease);
}

.thread-preview:hover,
.thread-preview.active {
  border-color: rgba(47, 143, 255, 0.3);
  background: rgba(47, 143, 255, 0.11);
}

.thread-preview:hover {
  transform: translateX(2px);
}

.thread-preview strong,
.thread-preview span {
  display: block;
}

.thread-preview span {
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-panel {
  padding: 0;
  overflow: hidden;
}

.chat-header {
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-header h2,
.chat-header p {
  margin: 0;
}

.chat-header p {
  color: var(--muted);
  margin-top: 4px;
}

.chat-messages {
  display: grid;
  gap: 10px;
  padding: 20px;
  background: rgba(0, 0, 0, 0.14);
}

.chat-message {
  width: fit-content;
  max-width: min(680px, 82%);
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
}

.chat-message.admin {
  justify-self: end;
  border-color: rgba(47, 143, 255, 0.28);
  background: rgba(47, 143, 255, 0.18);
}

.chat-reply-form {
  padding: 18px 20px 20px;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 15px;
  background: rgba(3, 8, 16, 0.68);
  color: var(--text);
  font: inherit;
  padding: 12px 14px;
  outline: none;
  transition: border-color 220ms var(--ease), background 220ms var(--ease), box-shadow 220ms var(--ease);
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(47, 143, 255, 0.42);
  background: rgba(3, 8, 16, 0.84);
  box-shadow: 0 0 0 4px rgba(47, 143, 255, 0.09);
}

textarea {
  resize: vertical;
}

input[type="checkbox"] {
  width: 24px;
  height: 24px;
  accent-color: var(--blue);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

button,
.small-link {
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 780;
  cursor: pointer;
}

.primary-button,
.secondary-button,
.small-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 16px;
  transition: transform 220ms var(--ease), filter 220ms var(--ease), box-shadow 220ms var(--ease);
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, var(--blue), #49adff);
  box-shadow: 0 16px 42px rgba(47, 143, 255, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.primary-button:hover {
  transform: translateY(-2px);
  filter: brightness(1.04);
  box-shadow: 0 22px 58px rgba(47, 143, 255, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.secondary-button,
.small-link {
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #d9eaff;
  background: rgba(255, 255, 255, 0.06);
}

button:active,
.small-link:active {
  transform: translateY(1px) scale(0.985);
}

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

.empty-state {
  color: var(--muted);
}

.warning-banner {
  padding: 14px 16px;
  margin: 14px 0;
  border: 1px solid rgba(216, 180, 106, 0.22);
  border-radius: 18px;
  color: #ffe5a3;
  background: rgba(216, 180, 106, 0.12);
}

.warning-banner.danger {
  color: #ffc4c2;
  border-color: rgba(242, 95, 92, 0.22);
  background: rgba(242, 95, 92, 0.1);
}

.warning-banner.success {
  color: #bbf7d0;
  border-color: rgba(69, 199, 122, 0.22);
  background: rgba(69, 199, 122, 0.1);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
}

.switch-row small {
  margin-top: 4px;
}

.secret-box {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(47, 143, 255, 0.14);
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.22);
}

.secret-box code,
.inline-json {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  color: #bfdbfe;
  font-size: 0.82rem;
}

.inline-json {
  max-width: 360px;
  line-height: 1.5;
}

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

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

.stat-grid div {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
}

.stat-grid strong {
  font-family: "Geist Mono", "SF Mono", Consolas, monospace;
  font-size: 1.6rem;
}

.stat-grid span {
  color: var(--muted);
}

.usage-list {
  display: grid;
  gap: 16px;
}

.usage-row {
  display: grid;
  gap: 8px;
}

.usage-row > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.usage-row span {
  color: var(--muted);
}

.usage-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.usage-track div {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--mint));
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.login-page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}

.login-panel {
  width: min(480px, 100%);
  display: grid;
  gap: 24px;
  padding: 28px;
  border: 1px solid var(--panel-border);
  border-radius: 30px;
  background: rgba(7, 17, 31, 0.86);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(24px);
  animation: riseIn 520ms var(--ease) both;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.login-brand p,
.login-panel h1 {
  margin: 0;
}

.login-access {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 12px;
  padding: 14px;
  border: 1px solid rgba(47, 143, 255, 0.16);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.035);
  font-size: 0.88rem;
}

.login-access span {
  color: var(--muted);
}

.login-access a {
  color: #bfdbfe;
  overflow-wrap: anywhere;
}

.login-form {
  display: grid;
  gap: 14px;
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 1100px) {
  .grid.kpi,
  .grid.split,
  .support-inbox,
  .access-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--panel-border);
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content {
    padding: 24px 18px;
  }

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

  .thread-list-panel {
    position: static;
  }
}
