:root {
  --bg: #faf9f6;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --accent: #2d5fb8;
  --border: #d8d4cd;
  --success: #1b6e3d;
  --warn: #b76e00;
  --error: #b00020;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: white;
}

.brand { font-weight: 600; color: var(--fg); text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar nav a { color: var(--muted); text-decoration: none; }
.topbar nav a:hover { color: var(--fg); }
.inline { display: inline; }
.linklike {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font: inherit; padding: 0;
}
.linklike:hover { color: var(--fg); }

main { max-width: 64rem; margin: 0 auto; padding: 1.5rem; }

h1 { margin: 0 0 1rem; font-size: 1.5rem; }
h2 { margin: 1.5rem 0 0.5rem; font-size: 1.125rem; }

button, .button {
  background: var(--accent); color: white; border: 0;
  padding: 0.5rem 1rem; border-radius: 0.375rem;
  font: inherit; cursor: pointer; text-decoration: none;
  display: inline-block;
}
button:hover, .button:hover { filter: brightness(1.05); }
button.secondary, .button.secondary { background: white; color: var(--fg); border: 1px solid var(--border); }

input[type="text"], input[type="password"], input[type="url"], input[type="number"], select {
  font: inherit; padding: 0.5rem; border: 1px solid var(--border);
  border-radius: 0.375rem; background: white;
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.5rem; border-bottom: 1px solid var(--border); text-align: left; }
th { font-size: 0.875rem; color: var(--muted); font-weight: 500; }

.muted { color: var(--muted); }
.success { color: var(--success); }
.warn { color: var(--warn); }
.error { color: var(--error); }

.card {
  background: white; border: 1px solid var(--border);
  border-radius: 0.5rem; padding: 1rem; margin-bottom: 1rem;
}

.login-card {
  max-width: 22rem; margin: 4rem auto; padding: 2rem;
}

.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.875rem; margin-bottom: 0.25rem; }
.field input { width: 100%; }

.item-card { padding: 1rem 1.25rem; }
.item-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem;
}
.item-title { margin: 0; font-size: 1.125rem; }
.item-meta { margin: 0.25rem 0 0; font-size: 0.875rem; }
.item-actions { display: flex; gap: 0.5rem; }
.account-table { margin-top: 0.5rem; }
.account-table th, .account-table td { padding: 0.4rem 0.5rem; }
.account-cell { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }

.sync-actions { padding: 1rem 1.25rem; }

.pending-toggle {
  display: inline-flex; align-items: center; gap: 0.25rem;
  margin-left: 0.75rem; font-size: 0.875rem; cursor: help;
  user-select: none;
}
.pending-toggle input { margin: 0; cursor: pointer; }

.card.warn { border-left: 4px solid var(--warn); }

/* sync-scheduling: trigger badges in history */
.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge-manual { background: #e2e8f0; color: #1f2937; }
.badge-scheduled { background: #dbeafe; color: #1e40af; }

/* schedules-page-ux: enabled/disabled status badges */
.badge-active { background: #d6f0e0; color: #1b6e3d; }
.badge-paused { background: #e2e8f0; color: #4b5563; }

/* schedules-page-ux: de-emphasize disabled schedule rows */
.list-row.is-disabled { opacity: 0.6; border-left: 4px solid var(--border); }
.list-row.is-disabled:hover, .list-row.is-disabled:focus-within { opacity: 1; }

/* schedule-naming-and-layout: name + status on one line, recurrence/meta below */
.schedule-title-row {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
.schedule-recurrence { margin: 0.25rem 0 0; font-size: 0.875rem; }
.schedule-meta { margin: 0.15rem 0 0; font-size: 0.875rem; }

/* flatten-nav-dashboard: landing dashboard status cards */
.dash-grid {
  display: flex; flex-wrap: wrap; gap: 1rem;
}
.dash-card {
  display: flex; flex-direction: column; gap: 0.35rem;
  flex: 1 1 14rem; min-width: 0;
  text-decoration: none; color: inherit;
  align-items: center; text-align: center;
}
a.dash-card:hover { border-color: var(--accent); filter: none; }
.dash-label { color: var(--muted); font-size: 0.875rem; }
.dash-value { font-size: 2rem; font-weight: 600; line-height: 1.1; }
.dash-value-sm { font-size: 1.1rem; font-weight: 600; }
.dash-empty { font-size: 1rem; }
.dash-alert { font-size: 0.875rem; }

/* dashboard-sync-stats: windowed import totals */
.dash-windows { display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: center; margin-top: 0.15rem; }
.dash-window { display: flex; flex-direction: column; }
.dash-window-val { font-size: 1.15rem; font-weight: 600; line-height: 1.1; }
.dash-window-label { font-size: 0.7rem; }

/* dashboard-sync-stats: per-connection last/next sync */
.dash-sync { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.dash-sync-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.dash-sync-table th, .dash-sync-table td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); }
.dash-sync-table th { color: var(--muted); font-weight: 600; }

/* history-row-expand: run row is the disclosure toggle */
.history-row.is-expandable { cursor: pointer; }
.history-row.is-expandable:hover { background: var(--code); }
.history-caret { font-size: 0.75rem; color: var(--muted); transition: transform 0.15s ease; }
.history-row[aria-expanded="true"] .history-caret { transform: rotate(90deg); }

/* ui-polish: larger, higher-contrast checkboxes */
input[type="checkbox"].bigcheck {
  width: 1.2rem; height: 1.2rem; accent-color: var(--accent);
  cursor: pointer; vertical-align: middle;
}
.check-label { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.conn-toolbar { padding: 0.6rem 1rem; }

/* ui-polish: aligned mapping columns */
.mapping-table .col-mapped { width: 16rem; }
.mapping-table .col-pending { width: 8rem; text-align: center; }
.mapping-table .col-pending .pending-na { display: inline-block; }
.mapping-table .mapping-select { width: 100%; }

/* ui-polish: spacing around the profiles header / New profile button */
.profiles-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin: 0 0 1rem;
}

/* ui-polish: settings secret reveal */
.reveal-row { display: flex; gap: 0.5rem; align-items: stretch; }
.reveal-row input { flex: 1; }
.reveal-btn { padding: 0.4rem 0.6rem; }

/* ui-polish: icon buttons */
.icon-btn {
  background: none; border: 1px solid transparent; color: var(--muted);
  padding: 0.35rem; border-radius: 0.375rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  line-height: 0; text-decoration: none;
}
.icon-btn:hover { color: var(--fg); border-color: var(--border); background: white; filter: none; }
.icon-btn svg { display: block; }

/* ui-polish: sync action layout */
.sync-actions-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.sync-result { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }

/* connections-sync-feedback: per-connection + total sync messages */
.conn-messages { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }
.conn-messages:empty { margin-top: 0; }
.sync-msg {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.4rem 0.6rem; border-radius: 0.4rem; font-size: 0.875rem;
  border: 1px solid var(--border); background: var(--card);
}
.sync-msg.success { border-left: 4px solid var(--success); }
.sync-msg.warn { border-left: 4px solid var(--warn); }
.sync-msg.error { border-left: 4px solid var(--error); }
.sync-msg-close { flex: 0 0 auto; }

/* ui-polish: calm-at-rest list rows — actions revealed on hover/focus,
   but always visible on touch devices (no hover) for accessibility. */
.row-actions { transition: opacity 0.12s ease; }
@media (hover: hover) and (pointer: fine) {
  .list-row .row-actions { opacity: 0; }
  .list-row:hover .row-actions,
  .list-row:focus-within .row-actions { opacity: 1; }
}

/* ui-polish: mobile-first responsiveness */
main { padding: 1rem; }
.mapping-table .col-mapped { width: auto; }
.account-table { display: block; overflow-x: auto; }

@media (min-width: 40rem) {
  main { padding: 1.5rem; }
  .account-table { display: table; overflow-x: visible; }
  .mapping-table .col-mapped { width: 16rem; }
}

/* brand sub-label "for Actual Budget" */
.brand-sub { color: var(--muted); font-weight: 400; font-style: italic; }

/* profile form: side-by-side server fields + budget loader */
.server-fieldset { border: 1px solid var(--border); border-radius: 0.5rem; padding: 0.75rem 1rem; margin: 0 0 1rem; }
.server-fieldset legend { font-size: 0.875rem; color: var(--muted); padding: 0 0.35rem; }
.field-row { display: flex; flex-direction: column; gap: 1rem; }
.field-row .field { flex: 1; margin-bottom: 0; }
.budget-row { display: flex; gap: 0.5rem; align-items: center; }
.budget-row select { flex: 1; }
@media (min-width: 40rem) {
  .field-row { flex-direction: row; }
}

/* section headers with a description line */
.section-header { margin: 0 0 1rem; }
.section-header h1 { margin: 0 0 0.25rem; }
.section-header p { margin: 0; }
.profiles-header { align-items: flex-start; }
.profiles-header h1 { margin: 0 0 0.25rem; }
.profiles-header p { margin: 0; }

/* icon spacing inside text buttons (not the icon-only .icon-btn) */
button:not(.icon-btn) > i, .button:not(.icon-btn) > i { margin-right: 0.4rem; }

/* profiles header: keep the New-profile button intact; let the description wrap
   within its column (and the whole button drop below only if space is tight). */
.profiles-header { flex-wrap: wrap; }
.profiles-header > div { flex: 1 1 18rem; min-width: 0; }
.profiles-header > div p { max-width: 60ch; }
.profiles-header > a { flex: 0 0 auto; }
.profiles-header button { white-space: nowrap; }

/* info icon for column-header tooltips */
.info-icon { color: var(--muted); cursor: help; font-size: 0.85em; }

/* profiles: per-connection group: muted heading with its own table below */
.conn-group { margin-top: 0.75rem; }
.conn-name { font-size: 1rem; font-weight: 600; margin: 0 0 0.35rem; }

/* schedule: day-of-week picker */
.day-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.25rem; }
.day-btn { display: inline-flex; cursor: pointer; }
.day-btn input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; }
.day-btn span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.5rem; height: 2.5rem; border-radius: 50%;
  border: 1px solid var(--border); background: white;
  font-size: 0.8rem; font-weight: 500; color: var(--muted);
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  user-select: none;
}
.day-btn input[type="checkbox"]:checked + span {
  background: var(--accent); color: white; border-color: var(--accent);
}
.day-btn:hover span { border-color: var(--accent); color: var(--fg); }

/* schedule: repeat row (every N weeks) */
.repeat-row { display: inline-flex; align-items: center; gap: 0.5rem; margin-top: 0.25rem; }
.repeat-input { width: 4rem; text-align: center; }

/* schedule: form actions row */
.form-actions { display: flex; gap: 0.75rem; align-items: center; margin-top: 0.5rem; }

/* schedule: legacy warning inline */
.legacy-warning { display: flex; flex-direction: column; gap: 0.15rem; margin-bottom: 0.5rem; }

/* app-wide banners */
.app-banners { display: flex; flex-direction: column; gap: 0; }
.app-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.6rem 1.5rem; font-size: 0.875rem; font-weight: 500;
  border-bottom: 1px solid var(--border);
}
.app-banner-warn { background: #fffbf0; color: #92500a; border-left: 3px solid var(--warn); }
.app-banner-info { background: #f0f5ff; color: #1a4ea6; border-left: 3px solid #1a4ea6; }
.app-banner-error { background: #fff0f0; color: var(--error); border-left: 3px solid var(--error); }
.app-banner .banner-dismiss {
  background: none !important; border: none !important; box-shadow: none !important;
  cursor: pointer; font-size: 1rem; line-height: 1; border-radius: 50%;
  color: inherit; opacity: 0.5; padding: 0.2rem 0.4rem; flex-shrink: 0;
  font-weight: 400;
}
.app-banner .banner-dismiss:hover { opacity: 1; background: rgba(0,0,0,0.07) !important; }

/* time input: constrain to content width */
input[type="time"] { width: auto; min-width: 9rem; }

/* schedule form: stronger field labels */
.schedule-form .field > label:first-child,
.schedule-form .field > label:first-of-type {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.schedule-form .field > label:first-child .muted,
.schedule-form .field > label:first-of-type .muted {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  font-size: 0.8rem;
}
.schedule-form .field { margin-bottom: 1.25rem; }

/* schedule form: combined time + repeat sentence row */
.time-repeat-row { display: inline-flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.time-repeat-row input[type="time"] { width: auto; min-width: 8rem; }

/* prevent the global ".field input { width:100% }" from stretching inline inputs */
.time-repeat-row input { width: auto; }

/* no top margin when h2 is the first element in a card */
.card > h2:first-child { margin-top: 0; }
