:root {
  --bg: #0f1419;
  --bg-card: #171d25;
  --bg-elevated: #1f2731;
  --text: #e8edf2;
  --text-muted: #8b98a5;
  --accent: #2dd4bf;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --danger: #f87171;
  --warning: #fbbf24;
  --success: #34d399;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, #16202a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

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

.app-shell {
  --shell-max: 520px;
  max-width: var(--shell-max);
  margin: 0 auto;
  min-height: 100vh;
  padding: 16px 16px calc(92px + env(safe-area-inset-bottom, 0px));
  width: 100%;
}

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

.topbar-nav {
  display: none;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  margin-right: 8px;
}

.topbar-nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.topbar-nav-link:hover,
.topbar-nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(45, 212, 191, 0.25);
}

.topbar-nav-link-accent {
  background: rgba(20, 184, 166, 0.12);
  color: var(--accent);
}

.topbar-nav-link-accent.active,
.topbar-nav-link-accent:hover {
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.28), rgba(13, 148, 136, 0.22));
}

.brand {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand span {
  color: var(--accent);
}

.page-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  padding: 8px 12px 8px 4px;
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 600;
  transition: color 0.15s, background 0.15s;
}

.page-back:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.card {
  background: linear-gradient(180deg, var(--bg-card) 0%, rgba(23, 29, 37, 0.92) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 14px; }

.card-title {
  margin: 0 0 14px;
  font-size: 1.15rem;
  font-weight: 650;
}

.muted { color: var(--text-muted); font-size: 0.92rem; }

.input, select.input, textarea.input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 12px;
  padding: 14px 14px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: rgba(45, 212, 191, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-otp {
  letter-spacing: 0.35em;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 700;
}

.textarea { resize: vertical; min-height: 88px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
}

.btn-primary {
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  color: #042f2e;
  flex: 1;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.35);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding-left: 0;
  padding-right: 0;
  min-height: auto;
}

.messages { list-style: none; padding: 0; margin: 0 0 14px; }
.message {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  font-size: 0.92rem;
}
.message.success { background: rgba(52, 211, 153, 0.12); color: var(--success); }
.message.warning { background: rgba(251, 191, 36, 0.12); color: var(--warning); }
.message.error { background: rgba(248, 113, 113, 0.12); color: var(--danger); }
.message.info { background: rgba(45, 212, 191, 0.12); color: var(--accent); }

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.chip.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(45, 212, 191, 0.35);
}

.entry-list {
  display: grid;
  gap: 16px;
  margin-top: 8px;
}

.entry-item {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  padding-top: 42px;
  border-radius: 16px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--bg-elevated);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.entry-item--in {
  border-left-color: var(--success);
  background: linear-gradient(105deg, rgba(52, 211, 153, 0.1) 0%, var(--bg-elevated) 42%);
}

.entry-item--out {
  border-left-color: var(--danger);
  background: linear-gradient(105deg, rgba(248, 113, 113, 0.1) 0%, var(--bg-elevated) 42%);
}

.entry-item:hover {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

.entry-item--in:hover {
  border-color: rgba(52, 211, 153, 0.45);
  border-left-color: var(--success);
}

.entry-item--out:hover {
  border-color: rgba(248, 113, 113, 0.45);
  border-left-color: var(--danger);
}

.entry-col-ref { min-width: 0; }

.entry-ref {
  font-weight: 700;
  font-size: 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.entry-party { color: var(--text); font-weight: 500; }

.entry-wallet {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  word-break: break-all;
}

.entry-role {
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 600;
}

.entry-comment {
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.entry-invoice {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.entry-meta { color: var(--text-muted); font-size: 0.86rem; margin-top: 6px; }
.entry-meta:first-child { margin-top: 0; }

.empty-state { grid-column: 1 / -1; }

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-in { background: rgba(52, 211, 153, 0.18); color: #34d399; }
.badge-out { background: rgba(248, 113, 113, 0.18); color: var(--danger); }
.badge-direction {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
}

.entry-item > .badge-direction {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1;
}
.badge-blocked { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.badge-active { background: var(--accent-soft); color: var(--accent); }

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  width: calc(min(var(--shell-max, 520px), 100vw) - 32px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 6px;
  border-radius: 22px;
  background: rgba(12, 17, 22, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 16px 48px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(18px);
  z-index: 20;
}

.bottom-nav-link {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 10px 16px;
  border-radius: 16px;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.12s;
}

.bottom-nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 1rem;
  line-height: 1;
}

.bottom-nav-link.active,
.bottom-nav-link:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(45, 212, 191, 0.2);
}

.bottom-nav-link.active .bottom-nav-icon,
.bottom-nav-link:hover .bottom-nav-icon {
  background: rgba(45, 212, 191, 0.16);
}

.bottom-nav-link-accent {
  background: rgba(20, 184, 166, 0.08);
  color: var(--accent);
}

.bottom-nav-link-accent .bottom-nav-icon {
  background: rgba(20, 184, 166, 0.18);
  font-weight: 700;
}

.bottom-nav-link-accent.active,
.bottom-nav-link-accent:hover {
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.26), rgba(13, 148, 136, 0.2));
  border-color: rgba(45, 212, 191, 0.28);
}

.detail-grid {
  display: grid;
  gap: 10px;
}

.detail-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}

.detail-title {
  margin: 0;
}

.card-detail--in {
  border-left: 4px solid var(--success);
}

.card-detail--out {
  border-left: 4px solid var(--danger);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child { border-bottom: none; }

.detail-label { color: var(--text-muted); font-size: 0.86rem; }
.detail-value { text-align: right; word-break: break-all; font-weight: 600; }

.wallet-action {
  position: relative;
  flex: 1;
  min-width: 0;
  text-align: right;
}

.wallet-trigger {
  appearance: none;
  background: transparent;
  border: none;
  padding: 4px 6px;
  margin: -4px -6px;
  color: inherit;
  font: inherit;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92rem;
  text-align: right;
  word-break: break-all;
  cursor: pointer;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}

.wallet-trigger:hover,
.wallet-trigger[aria-expanded="true"] {
  color: var(--accent);
  background: var(--accent-soft);
}

.wallet-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 196px;
  padding: 6px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 40;
}

.wallet-menu[hidden] {
  display: none;
}

.wallet-menu-item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.wallet-menu-item:hover,
.wallet-menu-item:focus-visible {
  background: var(--accent-soft);
  color: var(--accent);
  outline: none;
}

.wallet-toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(15, 20, 25, 0.96);
  border: 1px solid rgba(45, 212, 191, 0.35);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 50;
  pointer-events: none;
}

.wallet-toast[hidden] {
  display: none;
}

@media (min-width: 1024px) {
  .wallet-toast {
    bottom: 32px;
  }
}

.errorlist {
  margin: 6px 0 0;
  padding-left: 18px;
  color: var(--danger);
  font-size: 0.86rem;
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card { width: min(420px, 100%); }

.auth-logo {
  text-align: center;
  margin-bottom: 18px;
  font-size: 1.35rem;
  font-weight: 800;
}

.master-form {
  display: grid;
  gap: 0;
}

.card-form {
  max-width: 100%;
}

.page-header-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header-title {
  margin: 0;
}

.search-field {
  display: block;
  width: 100%;
  max-width: none;
  margin: 0;
}

.page-header-card .input-search {
  width: 100%;
  max-width: none;
  min-height: 48px;
}

@media (min-width: 720px) {
  .app-shell {
    --shell-max: 720px;
    padding: 24px 24px 96px;
  }

  .card {
    padding: 22px 24px;
  }

  .card-title {
    font-size: 1.35rem;
  }

  .entry-item {
    grid-template-columns: 120px minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    padding: 42px 20px 18px;
  }

  .entry-list {
    gap: 20px;
    margin-top: 12px;
  }

  .page-header-card {
    gap: 18px;
    margin-bottom: 32px;
  }

  .detail-row {
    padding: 12px 0;
  }

  .detail-label {
    min-width: 140px;
  }

  .master-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 20px;
  }

  .master-form .field:last-of-type,
  .master-form .btn-row {
    grid-column: 1 / -1;
  }

  .master-form .field:has(textarea) {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1024px) {
  .app-shell {
    --shell-max: 980px;
    padding: 28px 32px 48px;
  }

  .topbar {
    margin-bottom: 32px;
  }

  .topbar-nav {
    display: flex;
  }

  .bottom-nav {
    display: none;
  }

  .brand {
    font-size: 1.2rem;
  }

  .entry-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 32px;
    row-gap: 28px;
    margin-top: 4px;
  }

  .entry-item {
    grid-template-columns: 1fr;
    gap: 14px;
    min-height: 176px;
    padding: 44px 24px 22px;
  }

  .entry-item > .badge-direction {
    top: 18px;
    right: 18px;
  }

  .entry-ref {
    font-size: 1.08rem;
  }

  .entry-wallet {
    font-size: 0.78rem;
    line-height: 1.45;
  }

  .page-header-card {
    padding: 26px 30px;
    gap: 20px;
    margin-bottom: 44px;
  }

  .card-form {
    max-width: 760px;
    margin: 0 auto;
  }

  .card-detail {
    max-width: 820px;
    margin: 0 auto;
  }

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

  .auth-card {
    width: min(460px, 100%);
    padding: 4px;
  }
}

@media (min-width: 1280px) {
  .app-shell {
    --shell-max: 1140px;
    padding-bottom: 48px;
  }

  .entry-list {
    column-gap: 40px;
    row-gap: 32px;
  }

  .page-header-card {
    margin-bottom: 48px;
    padding: 28px 32px;
    gap: 22px;
  }

  .entry-item {
    min-height: 188px;
    padding: 46px 28px 24px;
  }
}

@media (min-width: 520px) {
  .app-shell { padding-top: 24px; }
}
