:root {
  color-scheme: dark;
  --bg: #08111f;
  --surface: #0f1b2d;
  --surface-2: #16243a;
  --text: #eff6ff;
  --muted: #93a4bd;
  --line: rgba(255,255,255,.10);
  --accent: #7c3aed;
  --accent-2: #a78bfa;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --shadow: 0 16px 45px rgba(0,0,0,.24);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #101827;
  --muted: #667085;
  --line: rgba(15,23,42,.10);
  --accent: #6d28d9;
  --accent-2: #8b5cf6;
  --shadow: 0 16px 45px rgba(15,23,42,.08);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(124,58,237,.14), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { max-width: 1120px; margin: 0 auto; padding: 18px 16px 90px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.topbar h1 { margin: 2px 0 0; font-size: clamp(1.65rem, 4vw, 2.3rem); }
.eyebrow { color: var(--accent-2); font-size: .82rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.topbar-actions { display: flex; gap: 8px; }

.card { background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.month-toolbar { display: flex; justify-content: space-between; gap: 14px; align-items: end; padding: 16px; }
.month-toolbar > div { min-width: min(360px, 60vw); }
label { display: block; margin-bottom: 7px; color: var(--muted); font-weight: 700; font-size: .86rem; }
input, select {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 13px; padding: 12px 13px; outline: none;
}
input:focus, select:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(124,58,237,.12); }

.primary, .ghost, .danger, .icon-btn, .chip-btn {
  border: 0; border-radius: 13px; padding: 11px 14px; font-weight: 800; color: var(--text);
}
.primary { background: linear-gradient(135deg, var(--accent), #9333ea); color: white; }
.ghost { background: var(--surface-2); border: 1px solid var(--line); }
.danger { background: rgba(239,68,68,.14); color: #fca5a5; border: 1px solid rgba(239,68,68,.22); }
.icon-btn { width: 42px; height: 42px; padding: 0; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); }
.chip-btn { padding: 7px 10px; background: var(--surface-2); border: 1px solid var(--line); font-size: .8rem; }

.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.tab { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 14px; padding: 11px 8px; font-weight: 800; }
.tab.active { color: white; background: var(--accent); border-color: transparent; }
.view { display: none; }
.view.active { display: block; }

.grid { display: grid; gap: 14px; }
.grid.metrics { grid-template-columns: repeat(4, 1fr); }
.metric { padding: 16px; }
.metric .label { color: var(--muted); font-size: .84rem; font-weight: 700; }
.metric .value { margin-top: 8px; font-size: clamp(1.35rem, 3vw, 2rem); font-weight: 900; }
.metric .sub { margin-top: 4px; color: var(--muted); font-size: .78rem; }

.section { margin-top: 14px; padding: 17px; }
.section-head { display:flex; justify-content:space-between; gap:12px; align-items:center; margin-bottom: 14px; }
.section-head h2, .section-head h3 { margin: 0; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: .86rem; }

.category-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.category-card { padding: 15px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 18px; }
.category-top { display:flex; justify-content:space-between; align-items:flex-start; gap:10px; }
.category-name { font-weight: 900; font-size: 1rem; }
.category-meta { color: var(--muted); font-size: .79rem; margin-top: 3px; }
.category-value { font-size: 1.3rem; font-weight: 900; margin-top: 12px; }
.progress { height: 8px; border-radius: 999px; background: rgba(127,127,127,.15); overflow: hidden; margin-top: 10px; }
.progress > span { display:block; height:100%; border-radius:inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.mini-row { display:flex; justify-content:space-between; gap:12px; margin-top: 8px; color: var(--muted); font-size: .78rem; }
.actions { display:flex; gap:8px; flex-wrap:wrap; margin-top: 12px; }

.split { display:grid; grid-template-columns: 1.05fr .95fr; gap:14px; }
.chart-wrap { min-height: 320px; display:grid; place-items:center; }
.chart-wrap canvas { max-height: 290px; }

.list { display: grid; gap: 9px; }
.list-item { display:flex; justify-content:space-between; gap:14px; align-items:center; background: var(--surface-2); border:1px solid var(--line); border-radius:14px; padding:12px 13px; }
.list-item strong { display:block; }
.list-item small { color:var(--muted); }
.amount-pos { color: #86efac; font-weight:900; }
.amount-neg { color: #fca5a5; font-weight:900; }

.form-grid { display:grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap:12px; }
.form-grid .full { grid-column: 1 / -1; }
.switch-row { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 0; border-bottom:1px solid var(--line); }
.switch-row:last-child { border-bottom:0; }
.switch { width:48px; height:28px; appearance:none; background:#475569; border-radius:999px; position:relative; transition:.2s; }
.switch::after { content:""; position:absolute; width:22px; height:22px; top:3px; left:3px; background:white; border-radius:50%; transition:.2s; }
.switch:checked { background:var(--accent); }
.switch:checked::after { transform:translateX(20px); }

.badge { display:inline-flex; align-items:center; gap:6px; padding:5px 8px; border-radius:999px; background:rgba(124,58,237,.13); color:var(--accent-2); border:1px solid rgba(124,58,237,.20); font-size:.74rem; font-weight:800; }
.empty { padding: 30px 14px; text-align:center; color:var(--muted); border:1px dashed var(--line); border-radius:16px; }

.rule-row { display:grid; grid-template-columns: 1.5fr .7fr .7fr auto; gap:8px; align-items:end; padding:12px; border:1px solid var(--line); background:var(--surface-2); border-radius:16px; }
.rule-row + .rule-row { margin-top:8px; }
.month-allocation-row { grid-template-columns: 1.35fr .55fr .75fr 1fr .9fr; }

.subcat { margin-top:9px; padding:10px; border-left:3px solid rgba(124,58,237,.45); background:rgba(127,127,127,.06); border-radius:10px; }
.subcat-head { display:flex; justify-content:space-between; gap:10px; align-items:center; }

.history-month { padding:14px; }
.history-head { display:flex; justify-content:space-between; gap:12px; }
.history-stats { display:grid; grid-template-columns: repeat(3,1fr); gap:8px; margin-top:12px; }
.history-stat { padding:10px; background:var(--surface-2); border-radius:12px; }
.history-stat small { color:var(--muted); display:block; margin-bottom:4px; }

#modal { width:min(860px, calc(100vw - 28px)); border:1px solid var(--line); background:var(--surface); color:var(--text); border-radius:22px; padding:0; box-shadow:var(--shadow); }
#modal::backdrop { background:rgba(2,6,23,.72); backdrop-filter:blur(4px); }
#modalForm { padding:18px; }
.modal-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:16px; }
.modal-head h2 { margin:0; }
.modal-actions { display:flex; justify-content:flex-end; gap:8px; margin-top:18px; }

.toast { position:fixed; left:50%; bottom:24px; transform:translate(-50%, 18px); background:#111827; color:#fff; border:1px solid rgba(255,255,255,.12); padding:11px 14px; border-radius:12px; opacity:0; pointer-events:none; transition:.2s; z-index:999; box-shadow:var(--shadow); }
.toast.show { opacity:1; transform:translate(-50%,0); }

@media (max-width: 800px) {
  .grid.metrics { grid-template-columns: repeat(2,1fr); }
  .split, .category-grid { grid-template-columns: 1fr; }
  .rule-row, .month-allocation-row { grid-template-columns: 1fr 1fr; }
  .rule-row .name-field { grid-column:1/-1; }
  .rule-row .rule-actions { grid-column:1/-1; }
}
@media (max-width: 520px) {
  .app-shell { padding-inline: 11px; }
  .month-toolbar { align-items:stretch; flex-direction:column; }
  .month-toolbar > div { min-width:0; }
  .tabs { gap:5px; }
  .tab { padding:10px 4px; font-size:.78rem; }
  .form-grid { grid-template-columns:1fr; }
  .form-grid .full { grid-column:auto; }
  .history-stats { grid-template-columns:1fr; }
}

/* Authentication */
[hidden] { display: none !important; }
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card { width: min(460px, 100%); padding: 24px; }
.auth-brand { margin-bottom: 20px; }
.auth-brand h1 { margin: 4px 0 8px; font-size: 2rem; }
.auth-brand p, .auth-help { margin: 0; color: var(--muted); line-height: 1.55; }
.auth-tabs { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-bottom:16px; }
.auth-tab { border:1px solid var(--line); background:var(--surface-2); color:var(--muted); border-radius:13px; padding:10px; font-weight:800; }
.auth-tab.active { background:var(--accent); color:white; border-color:transparent; }
.auth-form { display:grid; gap:13px; }
.auth-form > .primary { width:100%; margin-top:4px; }
.auth-form h2 { margin:0; }
.link-btn { border:0; background:transparent; color:var(--accent-2); padding:4px 0; text-align:left; font-weight:800; }
.auth-message { min-height:22px; margin-top:12px; color:var(--muted); font-size:.88rem; }
.auth-message.error { color:#fca5a5; }
.auth-message.success { color:#86efac; }
.setup-warning { margin:14px 0; padding:12px 13px; border-radius:14px; border:1px solid rgba(245,158,11,.28); background:rgba(245,158,11,.10); color:#fcd34d; line-height:1.45; }
.user-chip { max-width:240px; padding:9px 11px; border-radius:12px; background:var(--surface); border:1px solid var(--line); color:var(--muted); font-size:.8rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.logout-btn { white-space:nowrap; }

@media (max-width: 640px) {
  .auth-card { padding:18px; }
  .topbar { align-items:flex-start; }
  .topbar-actions { flex-wrap:wrap; justify-content:flex-end; }
  .user-chip { order:3; max-width:100%; width:100%; text-align:right; }
  .logout-btn { padding-inline:10px; }
}


/* ===== v5: πλήρες CRUD + πιο βολικό UI ===== */
.tabs {
  grid-template-columns: repeat(5, 1fr);
  position: sticky;
  top: 8px;
  z-index: 20;
  padding: 6px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-radius: 18px;
}
.tab { display:flex; align-items:center; justify-content:center; gap:7px; min-height:46px; }
.tab-icon { font-size:1rem; line-height:1; }

.quick-panel {
  margin-bottom:14px;
  padding:16px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:16px;
}
.quick-copy { color:var(--muted); margin-top:4px; font-size:.86rem; }
.quick-actions { display:flex; flex-wrap:wrap; justify-content:flex-end; gap:8px; }

.small-btn { padding:9px 11px; }
.stat-strip {
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:7px;
  margin-top:13px;
}
.stat-strip > div {
  padding:9px 10px;
  background:color-mix(in srgb, var(--surface) 70%, transparent);
  border:1px solid var(--line);
  border-radius:12px;
  min-width:0;
}
.stat-strip small { display:block; color:var(--muted); font-size:.7rem; margin-bottom:3px; }
.stat-strip strong { display:block; font-size:.82rem; overflow:hidden; text-overflow:ellipsis; }

.toolbar-actions, .row-actions { display:flex; flex-wrap:wrap; gap:7px; align-items:center; }
.compact-danger { padding:7px 10px; font-size:.8rem; }

.manage-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
.manage-card {
  border:1px solid var(--line);
  background:var(--surface-2);
  border-radius:18px;
  padding:15px;
  scroll-margin-top:90px;
}
.manage-head { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; }
.manage-head h3 { margin:0 0 4px; font-size:1.05rem; }
.manage-summary {
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:8px;
  margin:13px 0;
}
.manage-summary > div {
  padding:9px;
  border:1px solid var(--line);
  border-radius:12px;
  background:color-mix(in srgb, var(--surface) 72%, transparent);
}
.manage-summary small { display:block; color:var(--muted); font-size:.7rem; }
.manage-summary strong { display:block; margin-top:3px; }

.subsection-head {
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  padding-top:10px;
  border-top:1px solid var(--line);
}
.subsection-head > div { display:flex; gap:7px; align-items:center; }
.subsection-head span {
  display:inline-grid;
  place-items:center;
  min-width:24px;
  height:24px;
  padding:0 6px;
  border-radius:999px;
  background:rgba(124,58,237,.14);
  color:var(--accent-2);
  font-size:.72rem;
  font-weight:900;
}
.subcat-list { display:grid; gap:7px; margin-top:8px; }
.subcat-row {
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  padding:10px;
  border:1px solid var(--line);
  border-radius:12px;
  background:color-mix(in srgb, var(--surface) 72%, transparent);
}
.subcat-row small { display:block; color:var(--muted); margin-top:2px; }
.compact-empty { padding:14px 10px; }
.manage-footer { display:flex; gap:8px; margin-top:12px; }

.editable-item .item-right { display:flex; align-items:center; gap:12px; }
.item-right > span { white-space:nowrap; }

.filter-bar {
  display:flex;
  justify-content:space-between;
  align-items:end;
  gap:12px;
  margin-bottom:12px;
  padding:12px;
  border:1px solid var(--line);
  background:var(--surface-2);
  border-radius:14px;
}
.filter-bar > div:first-child { min-width:min(360px, 70%); }
.filter-count { color:var(--muted); font-size:.84rem; font-weight:800; padding-bottom:11px; }

.tx-item { align-items:flex-start; }

@media (max-width: 900px) {
  .manage-grid { grid-template-columns:1fr; }
  .quick-panel { align-items:flex-start; flex-direction:column; }
  .quick-actions { justify-content:flex-start; width:100%; }
}

@media (max-width: 640px) {
  .app-shell { padding-bottom:100px; }
  .tabs {
    position:fixed;
    left:8px;
    right:8px;
    bottom:8px;
    top:auto;
    margin:0;
    z-index:100;
    border:1px solid var(--line);
    box-shadow:var(--shadow);
    border-radius:20px;
    padding:6px;
    grid-template-columns:repeat(5,1fr);
  }
  .tab {
    min-width:0;
    min-height:54px;
    padding:6px 3px;
    flex-direction:column;
    gap:3px;
    border-radius:14px;
    font-size:.66rem;
  }
  .tab-icon { font-size:1.05rem; }
  .quick-actions { display:grid; grid-template-columns:1fr 1fr; }
  .quick-actions button { width:100%; }
  .grid.metrics { grid-template-columns:1fr 1fr; }
  .category-card { padding:13px; }
  .stat-strip { grid-template-columns:1fr; }
  .editable-item { align-items:flex-start; flex-direction:column; }
  .editable-item .item-right { width:100%; justify-content:space-between; flex-wrap:wrap; }
  .subcat-row { align-items:flex-start; flex-direction:column; }
  .subcat-row .row-actions { width:100%; }
  .manage-head { flex-direction:column; }
  .manage-summary { grid-template-columns:1fr 1fr 1fr; }
  .filter-bar { align-items:stretch; flex-direction:column; }
  .filter-bar > div:first-child { min-width:0; }
  .filter-count { padding-bottom:0; }
  .history-head { flex-direction:column; }
}


/* ===== v6: ξεκάθαρη επεξεργασία/διαγραφή κατηγοριών & υποκατηγοριών ===== */
.bulk-toolbar {
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  padding:12px 14px;
  margin-bottom:12px;
  border:1px dashed var(--line);
  border-radius:14px;
  background:color-mix(in srgb, var(--surface-2) 82%, transparent);
}
.bulk-toolbar small { display:block; color:var(--muted); margin-top:3px; }

.manage-title-with-check,
.subcat-name-with-check {
  display:flex;
  align-items:flex-start;
  gap:10px;
  min-width:0;
}
.bulk-check {
  width:18px;
  height:18px;
  margin-top:2px;
  flex:0 0 auto;
  accent-color:var(--accent);
}
.manage-title-with-check > div,
.subcat-name-with-check > div { min-width:0; }

@media (max-width: 640px) {
  .bulk-toolbar {
    align-items:flex-start;
    flex-direction:column;
  }
  .bulk-toolbar .row-actions {
    width:100%;
    display:grid;
    grid-template-columns:1fr;
  }
  .bulk-toolbar .row-actions button { width:100%; }
}
