/* Base reset + shared component styles. Everything here reads from tokens.css variables —
   no hardcoded colors, spacing, or font sizes. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Any element can carry both the `hidden` attribute and a class that sets `display` (e.g.
   `.stack` for flex layout) — without this, the class wins the cascade and the element stays
   visible despite `hidden`. Keep this ahead of every other rule in the file. */
[hidden] {
  display: none !important;
}

/* App-wide brand mark — top-left on every page except login.html (which gets a larger
   above-the-card treatment instead, in login.css). Height is fixed and known
   (--brand-bar-height) so pages that need to compensate for it (the full-viewport-centered
   auth pages) can do the math instead of guessing. */
:root {
  --brand-bar-height: 5.5rem;
}

.brand-bar {
  display: flex;
  align-items: center;
  /* Two slots: identity link on the left, an optional Log out button on the right (pages with
     no session yet — recover/totp-setup — just omit the second child; space-between still
     leaves the identity link flush left with one child). */
  justify-content: space-between;
  height: var(--brand-bar-height);
  padding: 0 var(--space-4);
}

.brand-bar-identity {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
}

.brand-bar img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

.brand-bar span {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  white-space: nowrap;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--line-height-normal);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0 0 var(--space-3) 0;
}

h1 {
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--color-accent);
}

h2 {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
}

h3 {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-medium);
}

.text-muted {
  color: var(--color-text-muted);
}

a {
  color: var(--color-accent);
}

/* ---- Layout ---- */

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-8);
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

/* ---- Buttons ---- */

.btn {
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

.btn-primary:hover {
  background: var(--color-accent-hover);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  border-color: var(--color-accent);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-2);
}

.btn-ghost:hover {
  color: var(--color-text);
}

/* Boxed accent button — Import debts, Log out. Same shape as .btn-secondary, but the border
   and text pick up the brand blue instead of staying neutral. */
.btn-accent {
  background: var(--color-surface);
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.btn-accent:hover {
  background: var(--color-accent-muted);
  border-color: var(--color-accent-hover);
}

/* Unboxed accent link — Transactions, Security nav items. Same shape as .btn-ghost, blue
   instead of muted, since these are navigation, not a quiet/secondary action. */
.btn-ghost-accent {
  background: transparent;
  color: var(--color-accent);
  padding: var(--space-1) var(--space-2);
}

.btn-ghost-accent:hover {
  color: var(--color-accent-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Form controls ---- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field label {
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* Editable-in-place value: looks like plain text until focused/hovered. */
.editable-value {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  background: transparent;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  width: 100%;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.editable-value:hover {
  border-color: var(--color-border);
  background: var(--color-surface);
}

.editable-value:focus {
  border-color: var(--color-accent);
  background: var(--color-surface);
  outline: none;
}

.editable-value.is-saving {
  opacity: 0.6;
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  padding: 2px var(--space-2);
  border-radius: 999px;
}

.badge-accent {
  background: var(--color-accent-muted);
  color: var(--color-accent);
}

.badge-success {
  background: var(--color-success-muted);
  color: var(--color-success);
}

.badge-warning {
  background: var(--color-warning-muted);
  color: var(--color-warning);
}

.badge-danger {
  background: var(--color-danger-muted);
  color: var(--color-danger);
}

/* ---- Utility ---- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 600px) {
  .page {
    padding: var(--space-4) var(--space-3) var(--space-7);
  }

  .card {
    padding: var(--space-4);
    border-radius: var(--radius-md);
  }
}
