:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-2: #20232f;
  --accent: #4a7bff;
  --accent-hover: #3a6aef;
  --text: #e6e8ee;
  --text-dim: #9aa0b0;
  --border: #2a2e3c;
  --danger: #ff5a5a;
  --success: #3ecf8e;
  --warn: #e8b84b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
.container { max-width: 900px; margin: 0 auto; padding: 16px; }
.container.with-bottom-tabs { padding-bottom: 86px; }

/* top bar */
.topbar { background: var(--bg-card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.topbar-inner { max-width: 900px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; position: relative; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 1.1em; }
.brand img { height: 28px; width: 28px; border-radius: 6px; }
.nav-links { display: none; gap: 8px; }
.nav-links a {
  color: var(--text); background: var(--bg-card-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 14px; font-size: 0.9em; white-space: nowrap;
}
.nav-links a:hover { border-color: var(--accent); color: var(--accent); }
.nav-links a.logout:hover { border-color: var(--danger); color: var(--danger); }
.nav-toggle {
  background: var(--bg-card-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 12px; font-size: 1.1em; cursor: pointer;
}
@media (min-width: 720px) {
  .nav-links { display: flex; }
  .nav-toggle { display: none; }
}
@media (max-width: 719px) {
  .nav-links {
    display: none; position: absolute; top: 100%; right: 16px; left: 16px;
    flex-direction: column; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 10px; padding: 10px; gap: 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  }
  .nav-links.open { display: flex; }
  .nav-links a { width: 100%; text-align: left; }
}

/* bottom tabs (phone) */
.bottom-tabs {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--bg-card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
@media (max-width: 719px) {
  .bottom-tabs { display: flex; justify-content: space-around; }
  .bottom-tabs a { color: var(--text-dim); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; font-size: 1.3em; flex: 1; }
  .bottom-tabs a span { font-size: 0.5em; }
}

/* cards */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card h2, .card h3 { margin-top: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }

/* forms */
label { display: block; margin: 10px 0 4px; font-size: 0.9em; color: var(--text-dim); }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=time], input[type=tel], textarea, select {
  width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-card-2); color: var(--text); font-size: 1em;
}
input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
input[type=time]::-webkit-calendar-picker-indicator,
input[type=date]::-webkit-calendar-picker-indicator,
input[type=datetime-local]::-webkit-calendar-picker-indicator { filter: invert(1) brightness(1.5); cursor: pointer; }
button, .btn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 10px 18px; font-size: 1em; cursor: pointer; display: inline-block;
}
button:hover, .btn:hover { background: var(--accent-hover); }
button.secondary, .btn.secondary { background: var(--bg-card-2); border: 1px solid var(--border); color: var(--text); }
button.danger, .btn.danger { background: var(--danger); }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.6s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* flash / toast */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.flash-error { background: rgba(255,90,90,0.15); color: var(--danger); border: 1px solid var(--danger); }
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--bg-card-2); border: 1px solid var(--accent); color: var(--text);
  padding: 10px 18px; border-radius: 999px; z-index: 100; opacity: 0; transition: opacity 0.3s, transform 0.3s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* auth pages */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
@supports (height: 100svh) { .auth-wrap { min-height: 100svh; } }
.auth-box { max-width: 380px; width: 100%; background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px; padding: 28px; text-align: center; }
.auth-box img.logo { height: 64px; margin-bottom: 8px; }
.auth-box h1 { font-size: 1.3em; margin: 0 0 4px; }
.auth-box p.subtitle { color: var(--text-dim); margin: 0 0 20px; font-size: 0.9em; }
.auth-box form { text-align: left; }
.auth-box button { width: 100%; margin-top: 14px; }

/* status badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.78em; font-weight: 600; }
.badge-active { background: rgba(74,123,255,0.2); color: var(--accent); }
.badge-done { background: rgba(154,160,176,0.2); color: var(--text-dim); }
.badge-invoiced { background: rgba(232,184,75,0.2); color: var(--warn); }
.badge-paid { background: rgba(62,207,142,0.2); color: var(--success); }
.badge-overdue { background: rgba(255,90,90,0.2); color: var(--danger); }
.badge-draft { background: rgba(154,160,176,0.2); color: var(--text-dim); }
.badge-sent { background: rgba(74,123,255,0.2); color: var(--accent); }
.badge-credited { background: rgba(154,160,176,0.2); color: var(--text-dim); text-decoration: line-through; }
.badge-accepted { background: rgba(62,207,142,0.2); color: var(--success); }
.badge-declined { background: rgba(255,90,90,0.2); color: var(--danger); text-decoration: line-through; }

.color-chip { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; margin-right: 6px; }

.recovery-code-list { font-family: monospace; font-size: 1.1em; background: var(--bg-card-2); padding: 14px; border-radius: 8px; line-height: 1.8; }
.item-box { border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.item-box-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.photo-tile { border: 1px solid var(--border); border-radius: 10px; padding: 8px; background: var(--bg-card); }
.photo-tile img { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; display: block; }

/* ─── Buttons: one consistent size and alignment everywhere ───────────────
   <a class="btn"> and <button> render identically; rows of buttons line up;
   only a button that follows real form fields gets space above it. */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  box-sizing: border-box; min-height: 44px; line-height: 1.2;
  font-family: inherit; font-size: 1em; font-weight: 500;
  text-decoration: none; white-space: nowrap; vertical-align: middle; margin: 0;
}
/* space only when the button comes after actual inputs (not hidden-only action forms) */
form > :is(input:not([type=hidden]), select, textarea, label, div, p, fieldset, .grid-2) ~ :is(button, .btn) { margin-top: 16px; }
.card > :is(p, div, ul, form, h3) + :is(button, .btn) { margin-top: 12px; }
/* rows of actions: same height, centred, small forms don't add space */
.item-box-actions, .btn-row, .form-actions, div[style*="display:flex"], nav[style*="display:flex"] { align-items: center; }
:is(.item-box-actions, .btn-row, .form-actions, div[style*="display:flex"], nav[style*="display:flex"]) > form { margin: 0; display: flex; }
.btn-row, .form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
/* compact Edit / Delete etc. inside list items */
.item-box-actions :is(button, .btn) { min-height: 36px; padding: 7px 14px; font-size: 0.92em; }
.btn-sm, button.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 0.88em; }
@media (max-width: 480px) {
  .item-box-actions { flex-wrap: wrap; }
}

/* action rows: every button same size, grouped together, right side */
.item-box-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.item-box-actions :is(button, .btn) { min-width: 104px; }
.item-box-actions button[disabled] { opacity: 0.4; cursor: not-allowed; }
.item-disabled { opacity: 0.7; }
.muted-note { color: var(--text-dim); font-size: 0.85em; margin: 8px 0 0; }
.danger-card { border-color: rgba(255,90,90,0.45); }
