/* ===================== FONT ===================== */
@font-face {
  font-family: 'ChicagoFLF';
  src: url('/fonts/ChicagoFLF.ttf') format('truetype'),
       url('/fonts/ChicagoFLF.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --face: #e8e6e1;
  --face-dark: #d3d0c8;
  --border: #4a4238;
  --border-light: #ffffff;
  --shadow: rgba(0,0,0,0.35);
  --select-brown: #5b4636;
  --close-red: #c94a3b;
  --text: #2b2620;
  --check-a: #ffd9ec;
  --check-b: #cfe7ff;
  --titlebar-a: #efeaff;
  --titlebar-b: #cdbdf7;
  --font-main: 'ChicagoFLF', 'Geneva', 'Helvetica Neue', 'Tahoma', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;             /* outer page never scrolls */
  position: fixed;
  font-family: var(--font-main);
  font-size: 13px;
  color: var(--text);
}

button, input, select, textarea { font-family: var(--font-main); font-size: 13px; }

/* ===================== STAGE / DESKTOP ===================== */
#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background-image:
    linear-gradient(45deg, var(--check-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--check-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--check-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--check-a) 75%);
  background-size: 46px 46px;
  background-position: 0 0, 0 23px, 23px -23px, -23px 0;
  background-color: var(--check-b);
}

#desktop {
  position: absolute;
  inset: 0;
  padding: 18px 10px 10px;
}
#desktop.hidden { display: none; }

.icon-grid {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px 4px;
  max-width: 320px;
}

.desktop-icon {
  width: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 6px 2px;
  user-select: none;
  /* slight organic scatter */
}
.desktop-icon:nth-child(1) { margin-top: 2px; }
.desktop-icon:nth-child(2) { margin-top: 22px; }
.desktop-icon:nth-child(3) { margin-top: 6px; }
.desktop-icon:nth-child(4) { margin-top: 26px; }
.desktop-icon:nth-child(5) { margin-top: 4px; }
.desktop-icon:nth-child(6) { margin-top: 20px; }

.desktop-icon img {
  width: 52px; height: 52px;
  image-rendering: pixelated;
  filter: drop-shadow(1px 2px 2px rgba(0,0,0,0.35));
}
.desktop-icon .icon-label {
  margin-top: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: bold;
  color: #fff;
  text-shadow: 1px 1px 1px rgba(0,0,0,0.5);
  border-radius: 3px;
  text-align: center;
}
.desktop-icon.selected .icon-label {
  background: var(--select-brown);
  color: #fff;
}

/* ===================== WINDOWS ===================== */
#windows-layer { position: absolute; inset: 0; pointer-events: none; }
#windows-layer .window { pointer-events: auto; }

.window {
  position: absolute;
  left: 50%;
  top: 13%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 420px;
  height: 76%;
  max-height: 660px;
  background: var(--face);
  border: 2px solid var(--border);
  border-radius: 8px;
  box-shadow: 3px 4px 0 var(--shadow), 0 12px 30px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: filter 0.15s ease;
  animation: winIn 0.16s ease;
}
@keyframes winIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.window.window-popup {
  top: calc(13% + (18px * var(--depth, 1)));
  left: calc(50% + (10px * var(--depth, 1)));
  width: 84%;
  height: 62%;
  max-height: 520px;
}

.window.window-inert {
  pointer-events: none;
  filter: brightness(0.82) saturate(0.85);
}

.win-titlebar {
  flex: 0 0 auto;
  background: repeating-linear-gradient(
    0deg, var(--titlebar-a) 0px, var(--titlebar-a) 3px,
    var(--titlebar-b) 3px, var(--titlebar-b) 6px
  );
  border-bottom: 2px solid var(--border);
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 30px;
}
.win-title {
  background: var(--face);
  padding: 1px 10px;
  font-weight: bold;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 3px;
  letter-spacing: 0.5px;
}
.win-close {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px; height: 20px;
  background: var(--face);
  border: 2px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.win-close.flash-red { background: var(--close-red); color: #fff; border-color: #7a2318; }

.window-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
}
/* visible chunky scrollbar, Mac OS 9 style */
.window-body::-webkit-scrollbar { width: 14px; }
.window-body::-webkit-scrollbar-track { background: var(--face-dark); border-left: 2px solid var(--border); }
.window-body::-webkit-scrollbar-thumb { background: var(--face); border: 2px solid var(--border); }
.window-body::-webkit-scrollbar-button { background: var(--face); border: 2px solid var(--border); height: 14px; }

/* ===================== FIELDSET / GROUP BOX ===================== */
.group-box {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 4px;
  padding: 14px 10px 10px;
  margin: 14px 0 12px;
}
.group-box .legend {
  position: absolute;
  top: -9px;
  left: 10px;
  background: var(--face);
  padding: 0 6px;
  font-weight: bold;
  font-size: 11px;
}

/* ===================== BUTTONS ===================== */
.btn {
  background: var(--face);
  border: 2px solid var(--border);
  border-radius: 5px;
  padding: 7px 14px;
  cursor: pointer;
  color: var(--text);
  min-height: 36px;
  font-weight: bold;
  box-shadow: 1px 1px 0 var(--shadow);
}
.btn:active { transform: translate(1px,1px); box-shadow: none; }
.btn:disabled { color: #999; cursor: default; box-shadow:none; }
.btn-primary { background: var(--select-brown); color: #fff; border-color: #2f241c; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.btn-tile {
  background: var(--face);
  border: 2px solid var(--border);
  border-radius: 5px;
  padding: 9px 8px;
  cursor: pointer;
  text-align: center;
  font-weight: bold;
  min-width: 84px;
  box-shadow: 1px 1px 0 var(--shadow);
}
.btn-tile.selected { background: var(--select-brown); color: #fff; }

/* ===================== FIELDS ===================== */
.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-weight: bold;
  margin-bottom: 4px;
  font-size: 12px;
}
.field input[type=text],
.field input[type=number],
.field input[type=date],
.field input[type=password],
.field textarea {
  width: 100%;
  padding: 7px 8px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: #fff;
}
.field textarea { resize: vertical; min-height: 56px; }

.select-wrap { position: relative; }
.select-wrap select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 7px 26px 7px 8px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: #fff;
}
.select-wrap::after {
  content: '\25B2\A\25BC';
  white-space: pre;
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  font-size: 7px; line-height: 7px;
  pointer-events: none;
  color: var(--border);
}

.inset-panel {
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 4px;
  padding: 8px;
}

/* ===================== DASHBOARD BITS ===================== */
.wallet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.wallet-card {
  background: var(--face);
  border: 2px solid var(--border);
  border-radius: 5px;
  padding: 8px;
}
.wallet-card .name { font-weight: bold; font-size: 12px; }
.wallet-card .type { font-size: 10px; color: #6b6259; }
.wallet-card .bal { font-size: 14px; margin-top: 4px; }

.tx-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid var(--face-dark);
  cursor: pointer;
}
.tx-item:hover { background: #f3eefc; }
.tx-item .left .n { font-weight: bold; }
.tx-item .left .sub { font-size: 11px; color: #6b6259; }
.tx-item .right { font-weight: bold; text-align: right; }
.tx-item .right.expense { color: #8a2e22; }
.tx-item .right.income { color: #2e6b3a; }
.tx-item .right.transfer { color: #3a4a8a; }

.collapse-detail summary {
  cursor: pointer;
  font-weight: bold;
  padding: 8px;
  background: var(--face);
  border: 2px solid var(--border);
  border-radius: 4px;
  list-style: none;
  margin-bottom: 8px;
}
.collapse-detail summary::-webkit-details-marker { display: none; }

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px;
  border-bottom: 1px solid var(--face-dark);
}
.list-row button.small { min-height: 26px; padding: 2px 8px; font-weight: normal; font-size: 11px; }

.badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  background: var(--face);
  border-radius: 3px;
  margin-left: 6px;
}

.progress-bar-outer {
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 4px;
  height: 18px; width: 100%; margin-top: 4px; overflow: hidden;
}
.progress-bar-inner { background: repeating-linear-gradient(45deg, var(--select-brown), var(--select-brown) 8px, #7a604c 8px, #7a604c 16px); height: 100%; }

.toast {
  position: fixed;
  bottom: 16px; left: 50%;
  transform: translateX(-50%);
  z-index: 5000;
  padding: 10px 16px;
  min-width: 200px;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--face);
  box-shadow: 2px 3px 0 var(--shadow);
}

.chart-wrap { text-align: center; margin-bottom: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; font-size: 11px; }
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-swatch { width: 10px; height: 10px; border: 1px solid var(--border); display: inline-block; border-radius: 2px; }

.help-text { font-size: 11px; color: #6b6259; margin-top: -4px; margin-bottom: 8px; }
.section-title { font-weight: bold; font-size: 13px; margin: 14px 0 8px; }

.hidden { display: none !important; }

/* login/setup full screen (before desktop) */
.fullscreen-center {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
