:root {
  color-scheme: dark;
  --bg: #050506;
  --bg-elevated: #101113;
  --panel: rgba(24, 25, 29, 0.82);
  --panel-solid: #17181b;
  --panel-soft: #202126;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f6f8;
  --muted: #9da2ad;
  --subtle: #6f7580;
  --blue: #58a6ff;
  --green: #42d783;
  --amber: #ffc95c;
  --red: #ff6b75;
  --violet: #9f8cff;
  --radius: 18px;
  --small-radius: 10px;
  --shadow: 0 20px 80px rgba(0, 0, 0, 0.4);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-width: 320px;
  letter-spacing: 0;
}

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

button {
  border: 0;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 330px;
  gap: 18px;
  padding: 18px;
  background:
    radial-gradient(circle at 55% -8%, rgba(88, 166, 255, 0.14), transparent 31%),
    radial-gradient(circle at 88% 18%, rgba(66, 215, 131, 0.08), transparent 24%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0) 34%),
    var(--bg);
}

.sidebar,
.context,
.panel,
.toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.sidebar {
  border-radius: 24px;
  padding: 18px;
  position: sticky;
  top: 18px;
  height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #272a30, #111316);
  border: 1px solid var(--line-strong);
  color: var(--green);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.05;
  font-weight: 700;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

.nav button,
.icon-button,
.segmented button,
.chip,
.primary,
.ghost,
.row-action {
  min-height: 36px;
  border-radius: var(--small-radius);
  color: var(--text);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.nav button {
  justify-content: flex-start;
  padding: 0 12px;
  color: var(--muted);
}

.nav button.active,
.nav button:hover,
.chip.active,
.segmented button.active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

.nav svg,
.icon-button svg,
.primary svg,
.ghost svg,
.row-action svg {
  width: 17px;
  height: 17px;
  stroke-width: 2;
}

.source-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
}

.source-card strong {
  display: block;
  font-size: 13px;
}

.source-card p {
  margin: 7px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.main {
  min-width: 0;
}

.toolbar {
  border-radius: 24px;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}

.title-block h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1;
}

.title-block p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(82px, 1fr));
  gap: 3px;
  padding: 4px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
}

.segmented button {
  min-height: 31px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.icon-button,
.ghost,
.primary,
.row-action {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.055);
}

.icon-button {
  width: 38px;
}

.icon-button:hover,
.ghost:hover,
.primary:hover,
.row-action:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.1);
}

.primary {
  background: rgba(88, 166, 255, 0.18);
  border-color: rgba(88, 166, 255, 0.35);
  color: #dbeafe;
  padding: 0 13px;
}

.ghost {
  color: var(--muted);
  padding: 0 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.metric {
  min-width: 0;
  min-height: 94px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035));
  padding: 14px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 23px;
  line-height: 1;
  white-space: nowrap;
}

.metric small {
  display: block;
  margin-top: 7px;
  color: var(--subtle);
  font-size: 11px;
}

.panel {
  border-radius: 24px;
  overflow: clip;
  margin-bottom: 18px;
}

.focus-panel {
  border-color: rgba(159, 140, 255, 0.22);
  background:
    linear-gradient(180deg, rgba(159, 140, 255, 0.08), rgba(255, 255, 255, 0.026)),
    var(--panel);
}

.panel-head {
  padding: 16px 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h3 {
  margin: 0;
  font-size: 16px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

.chip {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.rows {
  display: grid;
}

.credit-group {
  display: grid;
  border-bottom: 1px solid var(--line);
}

.credit-group:last-child {
  border-bottom: 0;
}

.credit-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 12px 16px 9px;
  background: rgba(255, 255, 255, 0.026);
  border-bottom: 1px solid var(--line);
  border-left: 0;
  border-right: 0;
  border-top: 0;
  border-radius: 0;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.credit-group.collapsed .credit-group-head {
  border-bottom: 0;
}

.credit-group-head:hover {
  background: rgba(255, 255, 255, 0.05);
}

.credit-group-title {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.credit-group-summary {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
}

.credit-group-head strong {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text);
  letter-spacing: 0;
}

.credit-group-head span {
  color: var(--muted);
  font-size: 12px;
}

.credit-group-summary svg {
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.credit-row,
.bonus-row,
.card-row,
.catalog-row,
.history-row {
  display: grid;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.credit-row {
  grid-template-columns: 32px minmax(0, 1.3fr) minmax(130px, 0.7fr) 88px 96px 82px;
}

.bonus-row {
  grid-template-columns: minmax(0, 1fr) minmax(160px, 0.8fr) 110px 92px;
}

.card-row {
  grid-template-columns: 11px minmax(0, 1fr) 90px 96px 120px 92px;
}

.catalog-row {
  grid-template-columns: 11px minmax(0, 1fr) 86px 92px 78px;
}

.history-row {
  grid-template-columns: minmax(0, 1fr) 82px;
}

.credit-row:last-child,
.bonus-row:last-child,
.card-row:last-child,
.catalog-row:last-child,
.history-row:last-child {
  border-bottom: 0;
}

.status-toggle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line-strong);
  color: var(--muted);
  cursor: pointer;
}

.status-toggle.used {
  color: #06120a;
  background: var(--green);
  border-color: var(--green);
}

.status-toggle.ignored {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  border-color: var(--line);
}

.credit-row.settled {
  background: rgba(255, 255, 255, 0.018);
}

.credit-row.settled .row-main,
.credit-row.settled .amount {
  opacity: 0.68;
}

.row-main {
  min-width: 0;
}

.row-main strong {
  display: block;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-main span,
.meta,
.card-meta {
  color: var(--muted);
  font-size: 12px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 5px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: var(--blue);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.12);
}

.status-pill,
.due-pill,
.source-pill {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 11px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.due-pill.soon,
.status-pill.warn {
  color: #ffe5a5;
  background: rgba(255, 201, 92, 0.12);
  border-color: rgba(255, 201, 92, 0.24);
}

.status-pill.good {
  color: #b5f7cb;
  background: rgba(66, 215, 131, 0.12);
  border-color: rgba(66, 215, 131, 0.24);
}

.status-pill.entry {
  color: #d7c7ff;
  background: rgba(125, 101, 255, 0.14);
  border-color: rgba(125, 101, 255, 0.25);
}

.status-pill.muted {
  color: #c3c8d2;
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.12);
}

.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 13px;
}

.amount small {
  color: var(--muted);
  font-weight: 500;
}

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

.bonus-slider {
  --progress: 0%;
  appearance: none;
  width: 100%;
  height: 22px;
  padding: 0;
  background: transparent;
  accent-color: var(--green);
  cursor: pointer;
}

.bonus-slider::-webkit-slider-runnable-track {
  height: 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--green)) 0 / var(--progress) 100% no-repeat, rgba(255, 255, 255, 0.09);
}

.bonus-slider::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--green);
  border: 3px solid #13231d;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35), 0 6px 14px rgba(0, 0, 0, 0.28);
}

.bonus-slider::-moz-range-track {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
}

.bonus-slider::-moz-range-progress {
  height: 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.bonus-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--green);
  border: 3px solid #13231d;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35), 0 6px 14px rgba(0, 0, 0, 0.28);
}

.bar {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  width: var(--progress);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.row-action {
  min-height: 31px;
  font-size: 12px;
  padding: 0 10px;
  color: var(--muted);
}

.row-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.row-action:disabled:hover {
  transform: none;
  background: rgba(255, 255, 255, 0.055);
}

.row-action.active-muted {
  color: #dbeafe;
  background: rgba(88, 166, 255, 0.14);
  border-color: rgba(88, 166, 255, 0.28);
}

.row-action.danger {
  color: #ffd0d4;
  border-color: rgba(255, 107, 117, 0.25);
  background: rgba(255, 107, 117, 0.09);
}

.input-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.enrollment-note {
  color: #ffe5a5;
}

.catalog-head {
  align-items: flex-start;
}

.catalog-controls {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(220px, 0.9fr) minmax(150px, 0.7fr);
  gap: 8px;
  width: min(690px, 100%);
}

.search {
  min-height: 34px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background-color: #202126;
  color: var(--text);
  padding: 7px 10px;
  font-size: 12px;
  color-scheme: dark;
}

.search option {
  background-color: #17181b;
  color: var(--text);
}

.catalog-segmented {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: 100%;
  min-width: 0;
}

.catalog-list {
  max-height: 680px;
  overflow: auto;
}

.portfolio-tools {
  background:
    linear-gradient(180deg, rgba(88, 166, 255, 0.08), rgba(66, 215, 131, 0.03)),
    var(--panel);
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.tool-card {
  min-width: 0;
  min-height: 122px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 18px;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.025)),
    rgba(255, 255, 255, 0.035);
  color: var(--text);
  text-align: left;
  display: grid;
  align-content: start;
  gap: 9px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.tool-card:hover,
.manual-card-button:hover {
  transform: translateY(-1px);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.078), rgba(255, 255, 255, 0.04)),
    rgba(255, 255, 255, 0.05);
  border-color: var(--line-strong);
}

.tool-card.quiet {
  color: var(--muted);
}

.tool-card strong,
.manual-card-button strong {
  font-size: 13px;
}

.tool-card span,
.manual-card-button small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.tool-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(88, 166, 255, 0.13);
  color: #cfe7ff;
  border: 1px solid rgba(88, 166, 255, 0.22);
}

.tool-icon svg {
  width: 17px;
  height: 17px;
}

.manual-card-anchor {
  padding: 2px 14px 14px;
}

.manual-card-button {
  width: 100%;
  min-height: 72px;
  border: 1px solid rgba(66, 215, 131, 0.28);
  border-radius: 20px;
  padding: 14px;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(66, 215, 131, 0.16), rgba(88, 166, 255, 0.1)),
    rgba(255, 255, 255, 0.045);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.manual-card-button > svg {
  width: 18px;
  height: 18px;
  color: #b5f7cb;
}

.context {
  border-radius: 24px;
  padding: 16px;
  position: sticky;
  top: 18px;
  height: calc(100vh - 36px);
  overflow: auto;
}

.context h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.mini-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 10px;
}

.mini-card strong {
  font-size: 13px;
}

.mini-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin: 8px 0 0;
}

.empty {
  padding: 42px 18px;
  color: var(--muted);
  text-align: center;
}

dialog {
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  width: min(520px, calc(100vw - 28px));
  padding: 0;
  background: #16171a;
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.66);
  backdrop-filter: blur(8px);
}

.dialog-body {
  padding: 18px;
}

.dialog-body h3 {
  margin: 0 0 14px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  min-height: 38px;
  padding: 8px 10px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
}

.hidden-file {
  display: none;
}

a {
  color: #a8d2ff;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 80px minmax(0, 1fr);
  }

  .sidebar {
    padding: 14px 10px;
    align-items: center;
  }

  .brand div:not(.brand-mark),
  .nav span,
  .source-card,
  .context {
    display: none;
  }

  .nav button {
    justify-content: center;
    width: 46px;
    padding: 0;
  }
}

@media (max-width: 1320px) {
  .credit-row {
    grid-template-columns: 30px minmax(0, 1fr) 82px;
    gap: 9px;
  }

  .credit-row .row-main {
    grid-column: 2 / 4;
  }

  .credit-row .due-pill {
    grid-column: 2;
    justify-self: start;
  }

  .credit-row .status-pill {
    grid-column: 3;
  }

  .credit-row .amount {
    grid-column: 2;
    text-align: left;
  }

  .credit-row .row-action {
    grid-column: 3;
  }
}

@media (max-width: 820px) {
  .shell {
    display: block;
    padding: 10px;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    justify-content: space-between;
    border-radius: 20px;
    margin-bottom: 10px;
  }

  .nav {
    grid-auto-flow: column;
  }

  .toolbar {
    grid-template-columns: 1fr;
    border-radius: 20px;
  }

  .segmented {
    width: 100%;
  }

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

  .panel {
    border-radius: 20px;
  }

  .credit-row {
    grid-template-columns: 30px minmax(0, 1fr) 82px;
    gap: 9px;
  }

  .credit-row .due-pill {
    display: none;
  }

  .credit-row .status-pill {
    grid-column: 3;
  }

  .credit-row .amount {
    grid-column: 2;
  }

  .credit-row .row-action {
    grid-column: 3;
  }

  .bonus-row,
  .card-row,
  .catalog-row,
  .input-row {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .credit-group-head {
    display: grid;
  }

  .catalog-head,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .catalog-controls {
    grid-template-columns: 1fr;
  }

  .amount {
    text-align: left;
  }

  .manual-card-button {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .manual-card-button > svg:last-child {
    display: none;
  }
}

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

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
