:root {
  --bg: #eef5ff;
  --bg-soft: #f8fbff;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --surface-soft: #f4f9ff;
  --text: #0f172a;
  --muted: #6b7a90;
  --border: rgba(33, 92, 180, 0.1);
  --border-strong: rgba(33, 92, 180, 0.16);
  --accent: #2a6fdb;
  --accent-2: #6fb6ff;
  --accent-soft: rgba(42, 111, 219, 0.1);
  --danger: #d14f5d;
  --danger-soft: rgba(209, 79, 93, 0.08);
  --success: #1f8f72;
  --success-soft: rgba(31, 143, 114, 0.08);
  --shadow-sm: 0 10px 28px rgba(40, 89, 160, 0.07);
  --shadow-md: 0 24px 54px rgba(40, 89, 160, 0.08);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --sidebar-w: 280px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(111, 182, 255, 0.34), transparent 22%),
    radial-gradient(circle at bottom right, rgba(42, 111, 219, 0.12), transparent 28%),
    linear-gradient(180deg, #f9fcff 0%, var(--bg) 100%);
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
input,
select,
textarea,
.card,
.metric,
.mini,
.userbox,
.auth-card,
svg.chart,
td,
th {
  transition:
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease,
    box-shadow 220ms ease,
    transform 220ms ease,
    opacity 180ms ease;
}

button {
  appearance: none;
  border: 1px solid transparent;
  background: linear-gradient(180deg, #4d94ff 0%, var(--accent) 100%);
  color: #fff;
  border-radius: 999px;
  padding: 0.82rem 1.08rem;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: -0.01em;
  box-shadow: 0 10px 24px rgba(42, 111, 219, 0.18);
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(42, 111, 219, 0.2);
}

button:active {
  transform: translateY(0);
}

button.ghost {
  background: rgba(255, 255, 255, 0.9);
  color: var(--accent);
  border-color: var(--border);
  box-shadow: none;
}

button.ghost:hover {
  background: var(--surface-soft);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

button.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(209, 79, 93, 0.12);
  box-shadow: none;
}

button.danger:hover {
  background: rgba(209, 79, 93, 0.12);
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.92rem 1rem;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
}

input::placeholder,
textarea::placeholder {
  color: #91a0b5;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(42, 111, 219, 0.28);
  box-shadow: 0 0 0 4px rgba(42, 111, 219, 0.1);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.small {
  font-size: 0.88rem;
}

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

strong {
  font-weight: 760;
}

.hidden {
  display: none !important;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-card,
.card,
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-md);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  padding: 1.45rem;
  border-radius: 30px;
  animation: rise-in 280ms ease;
}

.auth-card h1 {
  margin: 0.5rem 0 0.35rem;
  font-size: clamp(1.8rem, 4vw, 2.35rem);
  line-height: 1.02;
  letter-spacing: -0.05em;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0.35rem 0.74rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
}

.form-grid {
  display: grid;
  gap: 0.9rem;
}

.form-grid label {
  display: grid;
  gap: 0.42rem;
  font-size: 0.93rem;
  color: var(--muted);
}

.tx-type-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.tx-type-switch button {
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  border-color: var(--border);
  box-shadow: none;
}

.tx-type-switch button.active {
  background: linear-gradient(180deg, #4d94ff 0%, var(--accent) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 14px 28px rgba(42, 111, 219, 0.16);
}

.inline-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
}

.compact-btn {
  padding-inline: 0.9rem;
  white-space: nowrap;
}

.checkbox-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.8rem;
  color: var(--text);
}

.checkbox-row input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--primary);
}

.flash {
  border-radius: 16px;
  padding: 0.92rem 1rem;
  line-height: 1.45;
}

.error {
  background: rgba(209, 79, 93, 0.05);
  color: #b03b4c;
  border: 1px solid rgba(209, 79, 93, 0.1);
}

.success {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid rgba(31, 143, 114, 0.12);
}

.demo {
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
}

.brand {
  font-size: 1.48rem;
  font-weight: 800;
  letter-spacing: -0.05em;
}

.nav {
  display: grid;
  gap: 0.32rem;
}

.nav button {
  text-align: left;
  justify-content: flex-start;
  padding: 0.88rem 0.95rem;
  background: transparent;
  color: var(--text);
  border-color: transparent;
  box-shadow: none;
}

.nav button:hover {
  background: rgba(42, 111, 219, 0.05);
}

.nav button.active {
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent);
  border-color: rgba(42, 111, 219, 0.1);
  box-shadow: var(--shadow-sm);
}

.userbox {
  margin-top: auto;
  padding: 1rem;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.84);
  box-shadow: var(--shadow-sm);
}

.main {
  min-width: 0;
  padding: 1rem;
  display: grid;
  gap: 0.95rem;
}

.header {
  padding: 0.32rem 0;
  animation: rise-in 260ms ease;
}

.header h2 {
  margin: 0;
  font-size: clamp(1.7rem, 3.6vw, 2.2rem);
  line-height: 1.02;
  letter-spacing: -0.06em;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
}

.metric {
  padding: 1.08rem;
  border-radius: var(--radius-md);
  animation: rise-in 300ms ease;
}

.metric:hover,
.card:hover {
  transform: translateY(-1px);
}

.metric.highlight {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(239, 247, 255, 0.98));
  border-color: rgba(42, 111, 219, 0.12);
}

.metric .value {
  margin-top: 0.28rem;
  font-size: clamp(1.45rem, 2.8vw, 1.9rem);
  line-height: 1.04;
  font-weight: 800;
  letter-spacing: -0.05em;
}

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

.grid-fixed {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 0.95rem;
}

.card {
  min-width: 0;
  padding: 1.08rem;
  border-radius: var(--radius-lg);
  animation: rise-in 320ms ease;
}

.card h3 {
  margin: 0 0 0.9rem;
  font-size: 1rem;
  letter-spacing: -0.03em;
}

.table-wrap {
  overflow: auto;
  margin: 0 -0.15rem -0.15rem;
  padding: 0 0.15rem 0.15rem;
  -webkit-overflow-scrolling: touch;
}

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

th,
td {
  text-align: left;
  border-bottom: 1px solid rgba(33, 92, 180, 0.08);
  padding: 0.88rem 0.68rem;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: rgba(244, 249, 255, 0.96);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tbody tr:hover td {
  background: rgba(42, 111, 219, 0.03);
}

.row-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.stack {
  display: grid;
  gap: 0.65rem;
}

.mini {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.88rem 0.95rem;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(244, 249, 255, 0.82);
}

.mini:hover {
  background: rgba(255, 255, 255, 0.95);
  border-color: var(--border-strong);
}

svg.chart {
  width: 100%;
  height: 280px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(244, 249, 255, 0.94));
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tabs button {
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  border-color: var(--border);
  box-shadow: none;
}

.tabs button.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(42, 111, 219, 0.08);
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.85rem;
  }

  .metrics,
  .grid-2,
  .grid-fixed {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 0.9rem;
  }
}

@media (max-width: 720px) {
  :root {
    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 12px;
  }

  html,
  body {
    min-height: 100%;
  }

  body {
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(238, 245, 255, 0.98)),
      var(--bg);
  }

  .auth-shell {
    padding: 0.75rem;
  }

  .auth-card,
  .card,
  .metric {
    border-radius: 22px;
    box-shadow: var(--shadow-sm);
  }

  .sidebar,
  .main,
  .card,
  .metric,
  .auth-card {
    padding-left: 0.95rem;
    padding-right: 0.95rem;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    top: auto;
    min-height: 0;
    padding: 0.7rem 0.75rem calc(0.7rem + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.92);
    border-top: 1px solid var(--border);
    border-bottom: 0;
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
  }

  .sidebar > :first-child,
  .userbox {
    display: none;
  }

  .nav {
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: 0.45rem;
  }

  .nav button {
    justify-content: center;
    text-align: center;
    min-height: 52px;
    border-radius: 18px;
    font-size: 0.82rem;
    line-height: 1.1;
    padding: 0.72rem 0.55rem;
  }

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

  .main {
    padding: 0.9rem 0.9rem calc(6.6rem + env(safe-area-inset-bottom));
    gap: 0.85rem;
  }

  .header {
    padding-top: 0.1rem;
  }

  .header h2 {
    font-size: 1.55rem;
  }

  .metric .value {
    font-size: 1.28rem;
  }

  .form-grid {
    gap: 0.78rem;
  }

  .form-grid label {
    gap: 0.36rem;
  }

  input,
  select,
  textarea,
  button {
    min-height: 52px;
  }

  textarea {
    min-height: 104px;
  }

  .inline-field {
    grid-template-columns: 1fr;
  }

  .compact-btn {
    width: 100%;
  }

  .row-actions {
    flex-direction: column;
  }

  .row-actions button {
    width: 100%;
  }

  .table-wrap {
    overflow: visible;
    margin: 0;
    padding: 0;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 0.72rem;
  }

  tbody tr {
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: minmax(88px, 110px) minmax(0, 1fr);
    gap: 0.7rem;
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid rgba(33, 92, 180, 0.07);
    word-break: break-word;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  td[data-label=""]::before {
    content: "";
  }

  td .row-actions {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .tabs {
    display: grid;
  }

  .nav,
  .metrics {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 0.78rem;
    gap: 0.78rem;
    padding-bottom: calc(6.9rem + env(safe-area-inset-bottom));
  }

  .sidebar,
  .auth-card,
  .card,
  .metric,
  .userbox {
    border-radius: 18px;
  }

  button,
  input,
  select,
  textarea {
    border-radius: 13px;
  }

  .metrics,
  .grid-2,
  .grid-fixed {
    gap: 0.72rem;
  }

  .metric,
  .card {
    padding: 0.95rem;
  }

  td {
    grid-template-columns: 1fr;
    gap: 0.3rem;
    padding: 0.72rem 0.82rem;
  }

  td::before {
    font-size: 0.72rem;
  }
}
