:root {
  --bg: #0b0d10;
  --bg-2: #12161b;
  --bg-3: #1a1f26;
  --border: #232a33;
  --text: #e6edf3;
  --text-muted: #8b96a3;
  --text-dim: #5d6873;
  --accent: #4f8eff;
  --accent-2: #7aa9ff;
  --green: #3ec06b;
  --red: #ff6464;
  --yellow: #ffc857;
  --purple: #a78bfa;
  --pink: #ff8fb1;
  --shadow: 0 4px 12px rgba(0,0,0,.35);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, button { font-size: 14px; }

.hidden { display: none !important; }

/* ---------------- LOGIN ---------------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at top, #1a1f26 0%, #0b0d10 60%);
}
.login-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  width: min(380px, 92vw);
  text-align: center;
  box-shadow: var(--shadow);
}
.login-emoji { font-size: 44px; margin-bottom: 8px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { color: var(--text-muted); margin: 0 0 20px; font-size: 13px; }
.login-card input {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  margin-bottom: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background .15s;
}
.login-card button:hover { background: var(--accent-2); }
.login-error { color: var(--red); font-size: 12px; margin-top: 10px; min-height: 16px; }

/* ---------------- APP LAYOUT ---------------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---------------- SIDEBAR ---------------- */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.logo-emoji { font-size: 22px; }
.logo-text { font-weight: 700; letter-spacing: .2px; }

.nav { padding: 10px 8px; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 14px;
  transition: background .12s, color .12s;
}
.nav-item::before {
  content: attr(data-icon);
  width: 18px;
  text-align: center;
}
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--bg-3); color: var(--text); font-weight: 600; }
.nav-item.active::after {
  content: "";
  position: absolute;
  left: 0; top: 7px; bottom: 7px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.badge {
  margin-left: auto;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 500;
}
.badge:empty { display: none; }
.nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-dim);
  padding: 14px 12px 6px;
}
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.logout-btn {
  width: 100%;
  padding: 8px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.logout-btn:hover { background: var(--bg-3); color: var(--text); }

/* ---------------- MAIN ---------------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h2 { margin: 0; font-size: 17px; font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.topbar-actions button {
  width: 32px; height: 32px;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.topbar-actions button:hover { background: var(--bg-3); }
.menu-toggle {
  display: none;
  background: transparent;
  color: var(--text);
  border: none;
  font-size: 22px;
  padding: 0;
}

.content {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}

/* ---------------- ENTRY CARDS ---------------- */
.entry-list { display: flex; flex-direction: column; gap: 10px; }
.entry {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  align-items: start;
  transition: border-color .12s;
}
.entry:hover { border-color: #2c3540; }
.entry-icon {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: var(--bg-3);
  border-radius: 8px;
  font-size: 16px;
}
.entry-body { min-width: 0; }
.entry-content {
  font-weight: 500;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.entry-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.entry-meta .chip {
  background: var(--bg-3);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
}
.entry-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}
.entry-actions .id { color: var(--text-dim); font-family: ui-monospace, monospace; font-size: 11px; }
.entry-actions .btn-row { display: flex; gap: 4px; margin-top: 4px; }
.icon-btn {
  background: var(--bg-3);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  font-size: 13px;
}
.icon-btn:hover { color: var(--text); background: #232a33; }
.icon-btn.danger:hover { color: var(--red); border-color: #4a2528; background: #2a1518; }
.icon-btn.success:hover { color: var(--green); border-color: #1f3d2a; background: #142a1d; }

.entry.status-done .entry-content { text-decoration: line-through; color: var(--text-muted); }
.entry.status-cancelled .entry-content { color: var(--text-dim); text-decoration: line-through; }

/* type colors on icon */
.entry[data-type="task"]    .entry-icon { background: rgba(79,142,255,.12); }
.entry[data-type="meal"]    .entry-icon { background: rgba(255,200,87,.12); }
.entry[data-type="social"]  .entry-icon { background: rgba(167,139,250,.14); }
.entry[data-type="health"]  .entry-icon { background: rgba(62,192,107,.14); }
.entry[data-type="expense"] .entry-icon { background: rgba(255,143,177,.14); }
.entry[data-type="note"]    .entry-icon { background: rgba(139,150,163,.14); }
.entry[data-type="reminder"].entry-icon { background: rgba(255,100,100,.14); }

/* ---------------- EMPTY / LOADING ---------------- */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty .emoji { font-size: 36px; margin-bottom: 10px; }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
}
.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
  margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- SEARCH ---------------- */
.search-box {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.search-box input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-box button {
  padding: 10px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

/* ---------------- STATS ---------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-card .label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.stat-card .sub { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

.stat-section {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.stat-section h3 { margin: 0 0 14px; font-size: 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }

.bar-row {
  display: grid;
  grid-template-columns: minmax(140px, 220px) 1fr minmax(110px, auto);
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
}
.bar-row .name {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-row .bar {
  background: var(--bg-3);
  border-radius: 4px;
  height: 8px;
  position: relative;
  overflow: hidden;
}
.bar-row .bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 4px;
}
.bar-row .count { text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------------- COST TABLE ---------------- */
.cost-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.cost-table th, .cost-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.cost-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.cost-table td.num, .cost-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.cost-table td.bold { font-weight: 600; color: var(--text); }
.cost-table tbody tr:last-child td { border-bottom: none; }
.cost-table tbody tr:hover { background: var(--bg-3); }

.spark { display: flex; gap: 3px; align-items: flex-end; height: 80px; padding: 4px 0; }
.spark-bar { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; opacity: .85; }
.spark-bar:hover { opacity: 1; }
.spark-labels { display: flex; gap: 3px; margin-top: 4px; font-size: 10px; color: var(--text-dim); }
.spark-labels span { flex: 1; text-align: center; }

/* ---------------- SETTINGS ---------------- */
.settings-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.settings-card h3 { margin: 0 0 12px; font-size: 14px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border); }
.kv:first-of-type { border-top: none; }
.kv .k { color: var(--text-muted); font-size: 13px; }
.kv .v { font-family: ui-monospace, monospace; font-size: 13px; word-break: break-all; }

/* ---------------- TOAST ---------------- */
.toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-3);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 100;
  font-size: 13px;
}
.toast.error { border-color: #4a2528; }
.toast.success { border-color: #1f3d2a; }

/* ---------------- OVERLAY ---------------- */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 20;
}
.overlay.active { display: block; }

/* ---------------- RESPONSIVE ---------------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    z-index: 30;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
  .content { padding: 16px; }
  .entry { grid-template-columns: auto 1fr; }
  .entry-actions { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
}
