:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #252836;
  --text: #e4e4e7;
  --text-muted: #9ca3af;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --blue: #3b82f6;
  --border: #2e3141;
  --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Nav */
#nav {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.nav-brand { font-weight: 700; font-size: 18px; white-space: nowrap; }
.nav-links { display: flex; gap: 4px; }
.nav-links a {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: var(--radius);
  color: var(--text-muted); text-decoration: none; font-size: 14px;
  white-space: nowrap; transition: all .15s;
}
.nav-links a:hover { background: var(--bg-input); color: var(--text); }
.nav-links a.active { background: var(--primary); color: #fff; }
.nav-links a i { font-size: 18px; }

@media (max-width: 640px) {
  .nav-links a span { display: none; }
  .nav-links a { padding: 8px; }
}

/* Main */
#main { max-width: 960px; margin: 0 auto; padding: 20px; }
.page { display: none; }
.page.active { display: block; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 24px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

.section { margin-top: 24px; }
.section h2 { font-size: 18px; margin-bottom: 12px; color: var(--text-muted); }

/* Cards grid */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  transition: border-color .15s;
}
.card:hover { border-color: var(--primary); }
.card-title { font-size: 14px; color: var(--text-muted); margin-bottom: 4px; }
.card-value { font-size: 24px; font-weight: 700; }
.card-value.positive { color: var(--green); }
.card-value.negative { color: var(--red); }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; }

.color-dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; margin-right: 6px; vertical-align: middle;
}

/* List */
.list { display: flex; flex-direction: column; gap: 8px; }

.list-item {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; gap: 12px;
}
.list-item-left { flex: 1; min-width: 0; }
.list-item-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.list-item-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.list-item-amount { font-size: 16px; font-weight: 600; white-space: nowrap; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.badge-green { background: rgba(34,197,94,.15); color: var(--green); }
.badge-red { background: rgba(239,68,68,.15); color: var(--red); }
.badge-blue { background: rgba(59,130,246,.15); color: var(--blue); }
.badge-yellow { background: rgba(234,179,8,.15); color: var(--yellow); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  border: none; cursor: pointer; font-size: 14px; font-weight: 500;
  transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 20px; }
.btn-icon:hover { color: var(--text); }
.btn-pay { background: rgba(34,197,94,.15); color: var(--green); border: 1px solid transparent; }
.btn-pay:hover { border-color: var(--green); }
.btn-pay.paid { background: var(--green); color: #fff; }

/* Filters */
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

/* Forms */
input, select, textarea {
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; font-size: 14px; width: 100%;
  outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
select { cursor: pointer; }
input[type="month"] { width: auto; }
input[type="color"] { width: 40px; height: 36px; padding: 2px; cursor: pointer; }
label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 100;
  justify-content: center; align-items: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; }
#modal-body { padding: 20px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 20px; border-top: 1px solid var(--border);
}

/* Empty state */
.empty { text-align: center; color: var(--text-muted); padding: 40px; font-size: 14px; }

/* Debt analysis */
.ai-analysis {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-top: 8px;
  font-size: 13px; line-height: 1.6; white-space: pre-wrap;
}

/* Loading */
.loading { text-align: center; padding: 20px; color: var(--text-muted); }

/* Toggle */
.toggle {
  position: relative; width: 40px; height: 22px;
  background: var(--border); border-radius: 11px;
  cursor: pointer; transition: background .2s;
}
.toggle.on { background: var(--green); }
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform .2s;
}
.toggle.on::after { transform: translateX(18px); }

/* Cron */
.cron-disabled { opacity: 0.5; }
.cron-disabled .list-item-title { color: var(--text-muted); }
code { background: var(--bg-input); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

.cron-tutorial {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 16px;
}
.cron-tutorial summary {
  padding: 12px 16px; cursor: pointer; font-size: 14px;
  color: var(--text-muted); display: flex; align-items: center; gap: 6px;
}
.cron-tutorial summary:hover { color: var(--text); }
.cron-tutorial-body {
  padding: 0 16px 16px; font-size: 13px; line-height: 1.7;
}
.cron-tutorial-body pre {
  background: var(--bg-input); padding: 12px; border-radius: var(--radius);
  font-size: 12px; overflow-x: auto; margin: 8px 0;
}
.cron-tutorial-body table { width: 100%; margin: 8px 0; }
.cron-tutorial-body td {
  padding: 4px 8px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.cron-tutorial-body td:first-child { white-space: nowrap; }

/* Login */
.login-page {
  display: flex; justify-content: center; align-items: center;
  min-height: 100vh; padding: 20px;
}
.login-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px; width: 100%; max-width: 380px;
  text-align: center;
}
.login-logo { font-size: 48px; margin-bottom: 8px; }
.login-card h1 { font-size: 24px; margin-bottom: 4px; }
.login-sub { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.login-card .form-group { text-align: left; }
.login-error {
  color: var(--red); font-size: 13px; min-height: 20px;
  margin-bottom: 8px; text-align: left;
}
.btn-block { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }

/* Logout */
.nav-logout { margin-left: auto; }
.nav-logout:hover { color: var(--red) !important; }
