:root {
  color-scheme: dark;
  --ink: #ece9f6;
  --muted: #9993a9;
  --faint: #6e687c;
  --void: #09080d;
  --surface: #111017;
  --surface-2: #181620;
  --surface-3: #211e2a;
  --line: #2c2837;
  --gold: #d7b56d;
  --gold-bright: #f3d893;
  --violet: #8c6be8;
  --discord: #5865f2;
  --danger: #d96272;
  --success: #56b98a;
  --radius: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--void); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.login-page {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 25%, rgba(112, 78, 181, .2), transparent 33rem),
    linear-gradient(rgba(9, 8, 13, .91), rgba(9, 8, 13, .98)),
    repeating-linear-gradient(45deg, #15121b 0 1px, transparent 1px 18px);
}
.login-shell { width: min(92vw, 470px); padding: 40px 0; }
.login-card {
  position: relative;
  overflow: hidden;
  padding: 48px;
  text-align: center;
  border: 1px solid #3a3047;
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(28, 24, 35, .98), rgba(14, 13, 19, .98));
  box-shadow: 0 24px 80px #000a, inset 0 1px rgba(255,255,255,.04);
}
.login-card::before { content: ""; position: absolute; inset: 0 15%; height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); }
.brand-mark, .topbar-brand span {
  display: grid; place-items: center; margin: 0 auto 20px; width: 68px; height: 68px;
  border: 1px solid var(--gold); border-radius: 14px; color: var(--gold-bright);
  font: 700 22px Georgia, serif; letter-spacing: .08em; background: #19151f;
  box-shadow: inset 0 0 22px #d7b56d12, 0 0 30px #a8853c16;
}
.eyebrow { margin: 0 0 8px; color: var(--gold); font-size: 11px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; }
.login-card h1 { margin: 0; font-size: clamp(36px, 9vw, 52px); font-weight: 500; letter-spacing: -.03em; }
.login-copy { margin: 18px auto 28px; color: var(--muted); line-height: 1.65; }
.discord-button { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 52px; border-radius: 8px; background: var(--discord); color: white; text-decoration: none; font-weight: 700; box-shadow: 0 8px 28px #5865f233; transition: .18s ease; }
.discord-button:hover { background: #6874f7; transform: translateY(-1px); }
.discord-glyph { font-size: 22px; }
.login-footnote { margin: 20px 0 0; color: var(--faint); font-size: 12px; }

.app-page { min-height: 100vh; overflow-x: hidden; background: var(--void); }
.topbar { position: fixed; z-index: 30; inset: 0 0 auto; height: 64px; display: grid; grid-template-columns: 230px 1fr auto; align-items: center; border-bottom: 1px solid var(--line); background: rgba(13, 12, 18, .96); backdrop-filter: blur(16px); }
.topbar-brand { display: flex; align-items: center; gap: 11px; padding-left: 18px; color: var(--ink); text-decoration: none; font: 600 19px Georgia, serif; }
.topbar-brand span { width: 34px; height: 34px; margin: 0; border-radius: 8px; font-size: 12px; }
.top-nav { height: 100%; display: flex; align-items: stretch; gap: 6px; }
.nav-button { position: relative; padding: 0 18px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-weight: 650; }
.nav-button:hover { color: var(--ink); }
.nav-button.active { color: var(--gold-bright); }
.nav-button.active::after { content: ""; position: absolute; inset: auto 14px 0; height: 2px; background: var(--gold); box-shadow: 0 0 12px var(--gold); }
.user-menu { display: flex; align-items: center; gap: 10px; padding-right: 16px; color: var(--muted); font-size: 13px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.icon-button { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); color: var(--muted); cursor: pointer; }
.icon-button:hover { color: var(--ink); border-color: #4b435b; }

.app-layout { min-height: 100vh; padding-top: 64px; }
.category-rail { position: fixed; z-index: 20; inset: 64px auto 0 0; width: 74px; padding: 14px 10px; overflow: hidden auto; border-right: 1px solid var(--line); background: #0e0d12; transition: width .2s ease; }
.category-rail:hover, .category-rail:focus-within { width: 240px; box-shadow: 18px 0 40px #0009; }
.category-tab { display: grid; grid-template-columns: 48px 1fr; align-items: center; gap: 12px; width: 218px; min-height: 52px; margin-bottom: 9px; padding: 2px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; text-align: left; cursor: pointer; }
.category-tab:hover, .category-tab.active { background: var(--surface-2); color: var(--ink); }
.category-icon { display: grid; place-items: center; width: 48px; height: 48px; overflow: hidden; border: 2px solid var(--tab-color, var(--violet)); border-radius: 10px; background: var(--surface-3); color: var(--gold-bright); font: 600 18px Georgia, serif; box-shadow: inset 0 0 18px #0008; }
.category-icon img { width: 100%; height: 100%; object-fit: cover; }
.category-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.content { min-height: calc(100vh - 64px); margin-left: 74px; padding: 30px clamp(20px, 4vw, 56px) 60px; }
.content-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.content-header h1 { margin: 0; font-size: 34px; font-weight: 500; }
.content-header p { margin: 7px 0 0; color: var(--muted); }

.subsection { margin: 0 0 26px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.subsection-heading { position: relative; min-height: 50px; display: flex; align-items: center; justify-content: center; padding: 10px 54px; border-bottom: 1px solid var(--line); background: linear-gradient(90deg, transparent, #211c2a, transparent); }
.subsection-heading h2 { margin: 0; font-size: 17px; font-weight: 500; letter-spacing: .03em; }
.subsection-heading .add-button { position: absolute; right: 12px; }
.listing-head, .listing-row { display: grid; grid-template-columns: minmax(210px, 2.2fr) minmax(110px, .8fr) minmax(110px, .8fr) minmax(150px, 1fr) minmax(120px, 1fr) 38px; gap: 16px; align-items: center; }
.listing-head { padding: 11px 16px; color: var(--faint); font-size: 10px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.listing-row { min-height: 64px; padding: 8px 16px; border-top: 1px solid #24212c; }
.listing-row:hover { background: #18151e; }
.item-cell, .user-cell { display: flex; align-items: center; gap: 11px; min-width: 0; }
.item-image { flex: 0 0 auto; width: 42px; height: 42px; object-fit: cover; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-3); }
.item-placeholder { display: grid; place-items: center; color: var(--faint); }
.item-name, .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.price { color: var(--gold-bright); font-variant-numeric: tabular-nums; }
.amount { font-variant-numeric: tabular-nums; }
.user-cell .avatar { width: 25px; height: 25px; }
.empty-state, .loading-state { display: grid; place-items: center; min-height: 240px; color: var(--muted); text-align: center; }
.subsection .empty-state { min-height: 90px; }
.spinner { width: 20px; height: 20px; margin-bottom: 12px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.button { min-height: 40px; padding: 0 17px; border: 1px solid transparent; border-radius: 7px; cursor: pointer; font-weight: 700; }
.button.primary { background: var(--gold); color: #17120b; }
.button.primary:hover { background: var(--gold-bright); }
.button.secondary { border-color: var(--line); background: var(--surface-2); color: var(--ink); }
.add-button { width: 30px; height: 30px; min-height: 0; padding: 0; border: 1px solid #5a4a2d; border-radius: 6px; background: #261f15; color: var(--gold-bright); cursor: pointer; font-size: 20px; line-height: 1; }
.record-button { width: 30px; height: 30px; padding: 0; border: 1px solid #3a614d; border-radius: 6px; background: #14251d; color: var(--success); cursor: pointer; }

.history-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(320px, .75fr); gap: 24px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.panel-heading { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 0; font-size: 18px; font-weight: 500; }
.transaction-row, .summary-row { display: grid; align-items: center; gap: 12px; padding: 13px 18px; border-bottom: 1px solid #24212c; }
.transaction-row { grid-template-columns: 1.5fr .7fr .7fr 1fr; }
.summary-row { grid-template-columns: 1.4fr .7fr .8fr; }
.side-pill { display: inline-flex; width: fit-content; padding: 4px 7px; border-radius: 20px; background: #27202f; color: #c7b3e9; font-size: 10px; font-weight: 800; text-transform: uppercase; }

.config-tabs { display: flex; gap: 8px; margin: -8px 0 20px; }
.config-tab { padding: 9px 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--muted); cursor: pointer; }
.config-tab.active { border-color: #725e35; color: var(--gold-bright); background: #211b12; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 20px; }
.field { display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field label { color: var(--muted); font-size: 12px; font-weight: 650; }
.field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 7px; outline: none; background: #0d0c11; color: var(--ink); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #765f94; box-shadow: 0 0 0 3px #765f941f; }
.permissions-table { width: 100%; border-collapse: collapse; }
.permissions-table th, .permissions-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: center; font-size: 12px; }
.permissions-table th:first-child, .permissions-table td:first-child { text-align: left; }
.permissions-table th { color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }
.permissions-table input { accent-color: var(--gold); }

.modal { width: min(92vw, 520px); padding: 0; border: 1px solid #443a50; border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: 0 30px 100px #000d; }
.modal::backdrop { background: #030205c9; backdrop-filter: blur(3px); }
.modal form { padding: 24px; }
.modal-heading { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.modal-heading h2 { margin: 0; font-size: 23px; font-weight: 500; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.notice { padding: 10px 12px; border-radius: 7px; font-size: 13px; }
.notice.error { border: 1px solid #693743; background: #2b151b; color: #ef9dad; }
.toast { position: fixed; z-index: 100; right: 22px; bottom: 22px; padding: 12px 16px; border: 1px solid #3b614d; border-radius: 8px; background: #14231b; color: #a5e2c2; box-shadow: 0 16px 40px #0008; }

@media (max-width: 900px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .topbar-brand { width: 62px; overflow: hidden; padding-left: 13px; color: transparent; gap: 0; }
  .topbar-brand span { flex: 0 0 34px; color: var(--gold-bright); }
  .user-menu #user-name { display: none; }
  .nav-button { padding: 0 10px; font-size: 12px; }
  .listing-head { display: none; }
  .listing-row { grid-template-columns: 1.5fr .7fr .7fr 34px; gap: 9px; }
  .listing-row .user-cell, .listing-row .location-cell { display: none; }
  .history-grid { grid-template-columns: 1fr; }
}

@media (max-width: 580px) {
  .topbar { height: 58px; }
  .top-nav { overflow-x: auto; }
  .nav-button { padding: 0 8px; }
  .user-menu { padding-right: 8px; }
  .category-rail { inset-block-start: 58px; width: 60px; padding-inline: 6px; }
  .category-rail:hover, .category-rail:focus-within { width: 220px; }
  .category-tab { grid-template-columns: 46px 1fr; width: 204px; }
  .category-icon { width: 46px; height: 46px; }
  .app-layout { padding-top: 58px; }
  .content { margin-left: 60px; padding: 22px 12px 50px; }
  .content-header h1 { font-size: 27px; }
  .listing-row { grid-template-columns: 1.4fr .75fr 30px; padding-inline: 10px; }
  .listing-row .amount { display: none; }
  .item-image { width: 36px; height: 36px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .permissions-table { min-width: 780px; }
  .panel.table-scroll { overflow-x: auto; }
}
