/* =========================================================
   Accountant Pro — hand-written CSS, dark SaaS theme
   Palette: base #0f172a, surface #151f38, accent #3B82F6
   ========================================================= */

:root{
  --bg: #0b1222;
  --sidebar-bg: #0d1526;
  --surface: #131e35;
  --surface-2: #17233d;
  --border: rgba(148, 163, 184, 0.12);
  --border-strong: rgba(148, 163, 184, 0.22);
  --text: #e8ecf6;
  --text-dim: #93a0bd;
  --text-faint: #5c6889;
  --accent: #3B82F6;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --accent-strong: #60a5fa;
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.14);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.14);
  --purple: #a78bfa;
  --orange: #fb923c;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px -12px rgba(0,0,0,0.55);
  --font-display: 'Space Grotesk', Inter, sans-serif;
  --font-body: 'Inter', sans-serif;
}

body.light{
  --bg: #f3f5fa;
  --sidebar-bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.14);
  --text: #0f172a;
  --text-dim: #5c6889;
  --text-faint: #94a0bd;
  --shadow: 0 10px 30px -14px rgba(15,23,42,0.18);
}

*{ box-sizing: border-box; }
html,body{ height: 100%; }
body{
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}

button, input, select, textarea{ font-family: inherit; color: inherit; }
::selection{ background: var(--accent-soft); }

.app{
  display: flex;
  min-height: 100vh;
}

/* ================= SIDEBAR ================= */
.sidebar{
  width: 264px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand{ display:flex; align-items:center; gap:10px; padding: 4px 8px 8px; }
.brand-mark{
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(145deg, var(--accent), #2563eb);
  display:flex; align-items:center; justify-content:center;
  box-shadow: 0 6px 16px -4px rgba(59,130,246,.55);
  flex-shrink:0;
}
.brand-mark svg{ width:20px; height:20px; }
.brand-text{ display:flex; flex-direction:column; line-height:1.15; }
.brand-name{ font-family: var(--font-display); font-weight:700; font-size:16px; }
.brand-sub{ font-size:12px; color: var(--accent-strong); font-weight:600; }

.sidebar-section{ display:flex; flex-direction:column; gap:6px; }
.sidebar-label{
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint); font-weight:600; padding: 4px 10px 2px;
}

.account-list{ display:flex; flex-direction:column; gap:4px; }
.account-item{
  display:flex; align-items:center; gap:10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  cursor:pointer; border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease;
}
.account-item:hover{ background: var(--surface-2); }
.account-item.active{ background: var(--accent-soft); border-color: rgba(59,130,246,.35); }
.account-swatch{
  width: 34px; height:34px; border-radius: 9px; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  font-size:14px; font-weight:700; color:#fff;
}
.account-item-text{ display:flex; flex-direction:column; overflow:hidden; }
.account-item-name{ font-size: 13.5px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.account-item-balance{ font-size: 12px; color: var(--text-dim); }

.account-add-btn{
  margin-top: 4px; display:flex; align-items:center; gap:8px;
  background:none; border: 1px dashed var(--border-strong); color: var(--text-dim);
  padding: 8px 10px; border-radius: var(--radius-sm); font-size: 13px; cursor:pointer;
  transition: border-color .15s ease, color .15s ease;
}
.account-add-btn:hover{ border-color: var(--accent); color: var(--accent-strong); }

.nav-list{ display:flex; flex-direction:column; gap:2px; }
.nav-item{
  display:flex; align-items:center; gap:11px;
  background:none; border:none; text-align:left;
  padding: 10px 10px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; color: var(--text-dim);
  cursor:pointer; transition: background .15s ease, color .15s ease;
}
.nav-icon{ font-size:15px; width:18px; text-align:center; }
.nav-item:hover{ background: var(--surface-2); color: var(--text); }
.nav-item.active{ background: var(--accent-soft); color: var(--accent-strong); font-weight:600; }

.sidebar-footer{ margin-top:auto; padding-top: 12px; border-top: 1px solid var(--border); display:flex; flex-direction:column; gap:8px; }
.nav-item.logout:hover{ background: var(--red-soft); color: var(--red); }
.auth-status{
  font-size: 11.5px; font-weight:600; letter-spacing:.03em; text-transform: uppercase;
  color: var(--text-faint); padding: 0 10px;
}
body.is-authenticated .auth-status{ color: var(--accent-strong); }
.admin-only{ display: none; }
body.can-edit .nav-item.admin-only{ display: flex; }
body.can-edit .account-add-btn.admin-only{ display: flex; }
body.can-edit #newAccountBtn.admin-only{ display: inline-block; }
body.can-edit .setting-row.admin-only{ display: flex; }
body.can-edit .txn-actions.admin-only,
body.can-edit .account-tile-actions .admin-only{ display: inline-block; }

.owner-only{ display: none; }
body.is-owner .owner-only{ display: block; }

.auth-only{ display: none; }
body.is-authenticated .auth-only{ display: block; }

.account-scope-banner{
  font-size: 12.5px; font-weight:600; color: var(--text-dim);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 999px; display:inline-flex; gap:6px;
  margin-bottom: 18px;
}
.account-scope-banner strong{ color: var(--accent-strong); font-weight:700; }

/* Accounts page tiles use the opposite (standard) convention from the
   rest of the app: negative = red, positive = green. */
.account-tile-row .amount.standard-neg{ color: var(--red); }
.account-tile-row .amount.standard-pos{ color: var(--green); }

.type-badge{
  font-size: 10.5px; font-weight:700; letter-spacing:.03em; text-transform:uppercase;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border); flex-shrink:0;
}
.type-badge.normal{ color: var(--text-dim); background: var(--surface-2); }
.type-badge.expense{ color: var(--red); background: var(--red-soft); border-color: rgba(248,113,113,.35); }

.add-user-row{ display:flex; gap:10px; flex-wrap:wrap; margin-top:16px; align-items:center; }
.role-badge{
  font-size: 11px; font-weight:700; letter-spacing:.03em; text-transform:uppercase;
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border);
}
.role-badge.owner{ color: var(--accent-strong); background: var(--accent-soft); border-color: rgba(59,130,246,.35); }
.role-badge.editor{ color: var(--green); background: var(--green-soft); border-color: rgba(52,211,153,.35); }
.role-badge.viewer{ color: var(--text-dim); background: var(--surface-2); }

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

.topbar{
  display:flex; align-items:flex-start; justify-content:space-between;
  padding: 26px 36px 18px;
}
.topbar-title h1{
  font-family: var(--font-display);
  font-size: 26px; margin:0 0 4px; font-weight:700; letter-spacing:-.01em;
}
.topbar-title p{ margin:0; color: var(--text-dim); font-size: 13.5px; }
.topbar-actions{ display:flex; align-items:center; gap:12px; }

.icon-btn{
  width:38px; height:38px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface); cursor:pointer; font-size:15px;
  display:flex; align-items:center; justify-content:center;
}
.user-chip{
  display:flex; align-items:center; gap:9px; background: var(--surface);
  border: 1px solid var(--border); padding: 6px 14px 6px 6px; border-radius: 999px;
  font-size: 13.5px; font-weight:600;
}
.avatar{
  width:28px; height:28px; border-radius:50%; background: linear-gradient(145deg,var(--accent),#2563eb);
  display:flex; align-items:center; justify-content:center; font-size:11px; font-weight:700; color:#fff;
}

.page-body{ padding: 6px 36px 48px; flex:1; }
.page{ display:none; flex-direction:column; gap:20px; animation: fadeIn .25s ease; }
.page.active{ display:flex; }
@keyframes fadeIn{ from{ opacity:0; transform: translateY(4px);} to{opacity:1; transform:none;} }

/* ================= CARDS ================= */
.card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 26px;
  box-shadow: var(--shadow);
}

.hero-card{ position:relative; overflow:hidden; }
.hero-top{ display:flex; align-items:center; justify-content:space-between; }
.hero-label{ display:flex; align-items:center; gap:8px; color: var(--text-dim); font-size: 14px; }
.info-dot{
  width:16px; height:16px; border-radius:50%; border:1px solid var(--border-strong);
  font-size:10px; display:flex; align-items:center; justify-content:center; color:var(--text-faint);
}
.hero-value{
  font-family: var(--font-display); font-size: 46px; font-weight:700; margin-top: 10px; letter-spacing:-.01em;
}
.hero-sub{ margin-top:8px; font-size: 13.5px; color: var(--text-dim); display:flex; align-items:center; gap:6px; }
.hero-sub .up{ color: var(--green); font-weight:700; }

.grid-2{ display:grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.balance-layout{ align-items: stretch; }
.balance-column{ display:flex; flex-direction:column; gap:20px; }
.balance-column .balance-card{ flex:1; display:flex; flex-direction:column; justify-content:center; }

.balance-card-head{ display:flex; align-items:center; gap:10px; margin-bottom: 16px; }
.balance-icon{
  width:34px; height:34px; border-radius:10px; display:flex; align-items:center; justify-content:center;
  font-weight:700; color:#fff; font-size:15px; flex-shrink:0;
}
.balance-icon.eur{ background: linear-gradient(145deg,#3B82F6,#2563eb); }
.balance-icon.usd{ background: linear-gradient(145deg,#a855f7,#7e22ce); }
.balance-title{ font-weight:600; font-size:14.5px; flex:1; }
.pill{
  font-size: 11px; font-weight:700; letter-spacing:.04em; color: var(--text-dim);
  background: var(--surface-2); border:1px solid var(--border); padding: 3px 9px; border-radius: 999px;
}
.balance-value{ font-family: var(--font-display); font-size: 30px; font-weight:700; }

.section-title{ font-weight:700; font-size: 15px; margin-bottom: 16px; }

.stat-row{ display:grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.stat-item{ background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; }
.stat-item-label{ font-size:12px; color: var(--text-dim); margin-bottom:6px; }
.stat-item-value{ font-size:17px; font-weight:700; font-family: var(--font-display); }

/* ================= ACCOUNTS PAGE ================= */
.toolbar{ display:flex; gap:12px; margin-bottom: 18px; flex-wrap:wrap; }
.search-input{ flex:1; min-width:200px; }

.accounts-grid{ display:grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap:16px; }
.account-tile{
  background: var(--surface-2); border:1px solid var(--border); border-radius: var(--radius-sm);
  padding: 18px; cursor:pointer; transition: border-color .15s ease, transform .15s ease;
}
.account-tile:hover{ border-color: var(--accent); transform: translateY(-2px); }
.account-tile-head{ display:flex; align-items:center; gap:10px; margin-bottom:14px; }
.account-tile-name{ font-weight:700; font-size:15px; flex:1; }
.account-tile-row{ display:flex; justify-content:space-between; font-size:13px; color:var(--text-dim); margin-top:4px; }
.account-tile-row span:last-child{ color: var(--text); font-weight:600; }
.account-tile-actions{ display:flex; gap:8px; margin-top:14px; }
.account-tile-actions button{
  flex:1; padding:7px 0; border-radius:8px; border:1px solid var(--border); background: var(--surface);
  color: var(--text-dim); font-size:12.5px; cursor:pointer;
}
.account-tile-actions button:hover{ color: var(--text); border-color: var(--border-strong); }
.account-tile-actions button.danger:hover{ color: var(--red); border-color: rgba(248,113,113,.4); }

/* ================= FORMS ================= */
.form-card{ max-width: 640px; }
.form-row{ display:flex; flex-direction:column; gap:7px; margin-bottom:16px; }
.form-row label{ font-size:12.5px; font-weight:600; color: var(--text-dim); }
.optional-tag{ font-weight:500; color: var(--text-faint); text-transform:none; letter-spacing:0; margin-left:6px; }
.form-grid{ display:grid; grid-template-columns: repeat(3, 1fr); gap:14px; }
.form-grid.two{ grid-template-columns: repeat(2, 1fr); }

.input{
  width:100%; background: var(--surface-2); border:1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 13px; font-size: 14px; color: var(--text);
  outline:none; transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus{ border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input{ resize: vertical; }
.hint{ font-size:12.5px; color: var(--text-faint); margin: -6px 0 16px; }

.form-actions{ display:flex; justify-content:flex-end; gap:10px; margin-top: 6px; }

.btn{
  padding: 10px 18px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight:600;
  cursor:pointer; border: 1px solid transparent; transition: transform .1s ease, filter .15s ease, background .15s ease;
}
.btn:active{ transform: scale(.97); }
.btn.primary{ background: linear-gradient(145deg,var(--accent),#2563eb); color:#fff; box-shadow: 0 8px 20px -8px rgba(59,130,246,.6); }
.btn.primary:hover{ filter: brightness(1.08); }
.btn.ghost{ background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn.ghost:hover{ border-color: var(--border-strong); }
.file-btn{ display:inline-flex; align-items:center; justify-content:center; }

/* ================= SUMMARY PAGE ================= */
.stat-grid{ display:grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card{ background: var(--surface); border:1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-card-label{ font-size:12.5px; color: var(--text-dim); margin-bottom: 10px; }
.stat-card-value{ font-family: var(--font-display); font-size: 22px; font-weight:700; }
.stat-card-value.pos{ color: var(--text); }
.stat-card-value.neg{ color: var(--green); }
.stat-card-value.standard-pos{ color: var(--green); }
.stat-card-value.standard-neg{ color: var(--red); }
.balance-value.pos{ color: var(--text); }
.balance-value.neg{ color: var(--green); }
.balance-value.standard-pos{ color: var(--green); }
.balance-value.standard-neg{ color: var(--red); }
.hero-value.pos{ color: var(--text); }
.hero-value.neg{ color: var(--green); }
.account-tile-row .amount.neg{ color: var(--green); }

/* ================= TRANSACTIONS TABLE ================= */
.table-wrap{ overflow-x:auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.txn-table{ width:100%; border-collapse: collapse; font-size: 13.5px; }
.txn-table th{
  text-align:left; padding: 12px 14px; background: var(--surface-2); color: var(--text-dim);
  font-weight:600; font-size: 12px; text-transform:uppercase; letter-spacing:.03em;
  border-bottom: 1px solid var(--border);
}
.txn-table td{ padding: 12px 14px; border-bottom: 1px solid var(--border); }
.txn-table tbody tr:last-child td{ border-bottom:none; }
.txn-table tbody tr:hover{ background: var(--surface-2); }
.txn-table .amt-pos{ color: var(--text); font-weight:600; }
.txn-actions{ display:flex; gap:8px; }
.txn-actions button{
  border:none; background:none; cursor:pointer; color: var(--text-dim); font-size:13px;
  padding: 4px 8px; border-radius:6px;
}
.txn-actions button:hover{ background: var(--surface-2); color: var(--text); }
.txn-actions button.danger:hover{ color: var(--red); }
.empty-row td{ text-align:center; color: var(--text-faint); padding: 34px 14px; }

.pagination{ display:flex; align-items:center; justify-content:flex-end; gap:8px; margin-top:16px; }
.pagination button{
  width:32px; height:32px; border-radius:8px; border:1px solid var(--border); background: var(--surface-2);
  color: var(--text-dim); cursor:pointer; font-size:13px;
}
.pagination button.active{ background: var(--accent); color:#fff; border-color: var(--accent); }
.pagination button:disabled{ opacity:.4; cursor:not-allowed; }

/* ================= SETTINGS ================= */
.setting-row{
  display:flex; align-items:center; justify-content:space-between; gap: 16px;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.setting-row:last-child{ border-bottom:none; padding-bottom:0; }
.setting-name{ font-size:14px; font-weight:600; }
.setting-desc{ font-size:12.5px; color: var(--text-dim); margin-top:2px; }

.switch{ position:relative; display:inline-block; width:42px; height:24px; flex-shrink:0; }
.switch input{ opacity:0; width:0; height:0; }
.slider{
  position:absolute; cursor:pointer; inset:0; background: var(--surface-2);
  border: 1px solid var(--border-strong); transition:.2s; border-radius: 999px;
}
.slider:before{
  content:""; position:absolute; height:16px; width:16px; left:3px; top:2px;
  background: var(--text-dim); border-radius:50%; transition:.2s;
}
.switch input:checked + .slider{ background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider:before{ transform: translateX(18px); background:#fff; }

/* ================= MODAL ================= */
.modal-overlay{
  position:fixed; inset:0; background: rgba(5,9,20,.6); backdrop-filter: blur(3px);
  display:none; align-items:center; justify-content:center; z-index: 100; padding: 20px;
}
.modal-overlay.open{ display:flex; }
.modal{
  background: var(--surface); border:1px solid var(--border-strong); border-radius: var(--radius);
  padding: 26px; width: 100%; max-width: 420px; box-shadow: 0 24px 60px -16px rgba(0,0,0,.6);
  animation: pop .18s ease;
}
@keyframes pop{ from{ opacity:0; transform: scale(.96);} to{ opacity:1; transform:none; } }
.modal h3{ margin: 0 0 16px; font-family: var(--font-display); font-size:18px; }
.modal-actions{ display:flex; justify-content:flex-end; gap:10px; margin-top:20px; }

/* ================= TOASTS ================= */
.toast-stack{ position:fixed; bottom: 22px; right: 22px; display:flex; flex-direction:column; gap:10px; z-index: 200; }
.toast{
  background: var(--surface); border:1px solid var(--border-strong); border-radius: 12px;
  padding: 12px 16px; font-size: 13.5px; box-shadow: var(--shadow); min-width: 220px;
  animation: toastIn .2s ease;
  border-left: 3px solid var(--accent);
}
.toast.error{ border-left-color: var(--red); }
.toast.success{ border-left-color: var(--green); }
@keyframes toastIn{ from{ opacity:0; transform: translateX(20px);} to{ opacity:1; transform:none; } }

/* ================= RESPONSIVE ================= */
@media (max-width: 980px){
  .sidebar{ display:none; }
  .grid-2{ grid-template-columns: 1fr; }
  .stat-row{ grid-template-columns: repeat(2,1fr); }
  .stat-grid{ grid-template-columns: repeat(2,1fr); }
  .form-grid{ grid-template-columns: 1fr; }
  .page-body{ padding: 6px 18px 40px; }
  .topbar{ padding: 20px 18px 14px; }
}

/* Focus visibility for keyboard nav */
button:focus-visible, .input:focus-visible, .account-item:focus-visible{
  outline: 2px solid var(--accent-strong); outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce){
  *{ animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
