* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f0f0f;
  color: #fff;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}
body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.view { display: none; }
.view.active { display: block; }

/* LOGIN */
#loginView {
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#loginView.active { display: flex; }
.login-box {
  width: 100%;
  max-width: 360px;
  background: #1a1a1a;
  padding: 32px 24px;
  border-radius: 16px;
  border: 1px solid #2a2a2a;
  text-align: center;
}
.login-box .logo { font-size: 56px; margin-bottom: 8px; }
.login-box h1 {
  font-size: 26px;
  margin-bottom: 8px;
  background: linear-gradient(90deg, #ff6b35, #f7931e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.login-box .sub { color: #888; margin-bottom: 20px; }
.login-box input {
  width: 100%;
  padding: 16px;
  font-size: 24px;
  text-align: center;
  letter-spacing: 8px;
  background: #0f0f0f;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  color: #fff;
  margin-bottom: 16px;
}
.login-box input:focus { outline: none; border-color: #ff6b35; }
.error { color: #ff6b6b; margin-top: 12px; min-height: 20px; font-size: 14px; }

/* MAIN */
header {
  position: sticky;
  top: 0;
  background: rgba(15,15,15,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid #1a1a1a;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 50;
}
.brand {
  font-weight: 700;
  font-size: 17px;
  background: linear-gradient(90deg, #ff6b35, #f7931e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.header-actions { display: flex; gap: 6px; }
.icon-btn {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn.active { border-color: #ff6b35; background: #2a1a10; }

main {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 100px;
}
.tab { display: none; }
.tab.active { display: block; }

h1 { font-size: 26px; }
h2 { font-size: 17px; margin-bottom: 12px; color: #fff; }
h3 { font-size: 15px; margin-bottom: 8px; color: #aaa; }
.muted { color: #888; font-size: 13px; margin-bottom: 12px; }

.card {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 12px;
  color: #888;
  margin: 12px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
label:first-child, .card > label:first-of-type { margin-top: 0; }

input[type="date"], input[type="number"], input[type="text"], input[type="password"] {
  width: 100%;
  padding: 13px;
  background: #0f0f0f;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  color: #fff;
  font-size: 16px;
  font-family: inherit;
}
input[type="color"] {
  width: 60px;
  height: 40px;
  padding: 4px;
  background: #0f0f0f;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  cursor: pointer;
}
input:focus { outline: none; border-color: #ff6b35; }
input::placeholder { color: #555; }

button {
  width: 100%;
  padding: 14px;
  background: linear-gradient(90deg, #ff6b35, #f7931e);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 14px;
  font-family: inherit;
}
button:active { transform: scale(0.98); }
.btn-secondary { background: #2a2a2a; color: #fff; }
.btn-danger { background: #4a1a1a; color: #ff6b6b; }

.suma {
  background: linear-gradient(135deg, #ff6b35, #f7931e);
  color: #000;
  padding: 14px;
  border-radius: 10px;
  margin-top: 14px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
}

/* CAT INPUTS */
.cat-input {
  display: grid;
  grid-template-columns: 4px 1fr 130px;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.cat-input .swatch {
  width: 4px;
  height: 100%;
  min-height: 44px;
  border-radius: 2px;
}
.cat-input .name { font-size: 14px; color: #ccc; }
.cat-input input { padding: 11px; font-size: 16px; }

/* STATS */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.stat {
  background: #1a1a1a;
  padding: 12px 10px;
  border-radius: 12px;
  border: 1px solid #2a2a2a;
}
.stat-label { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 17px; font-weight: 700; color: #ff6b35; margin-top: 4px; }

/* HISTORY ENTRY */
.entry {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}
.entry-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.entry-date { font-weight: 600; font-size: 15px; }
.entry-total { color: #ff6b35; font-weight: 700; font-size: 17px; }
.entry-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: #bbb;
  padding: 3px 0;
}
.entry-row .name { display: flex; align-items: center; gap: 6px; }
.entry-row .swatch { width: 8px; height: 8px; border-radius: 2px; }
.entry-note { font-size: 12px; color: #888; font-style: italic; margin-top: 6px; }
.entry-actions { margin-top: 10px; display: flex; gap: 8px; }
.entry-actions button { padding: 8px; margin: 0; font-size: 13px; }

.empty { text-align: center; color: #666; padding: 30px 10px; }

.export-bar { margin-top: 8px; }

/* CATEGORIES LIST */
.cat-row {
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #0f0f0f;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  margin-bottom: 8px;
}
.cat-row.inactive { opacity: 0.5; }
.cat-row .swatch-big {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}
.cat-row .name-input {
  background: transparent;
  border: none;
  padding: 6px;
  font-size: 14px;
}
.cat-row .name-input:focus { background: #1a1a1a; }
.cat-row button {
  width: auto;
  padding: 6px 10px;
  font-size: 12px;
  margin: 0;
  background: #2a2a2a;
}
.cat-row button.del { background: #4a1a1a; color: #ff6b6b; }

/* MONTH BREAKDOWN */
.breakdown-row {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #2a2a2a;
}
.breakdown-row:last-child { border-bottom: none; }
.breakdown-row .swatch { width: 8px; height: 8px; border-radius: 2px; }
.breakdown-row .name { font-size: 14px; color: #ccc; }
.breakdown-row .val { font-weight: 600; color: #ff6b35; }

/* TOAST */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1a1a1a;
  border: 1px solid #ff6b35;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 100;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
