/* Buttons, forms, choices, tables, cards, modals, toasts, badges, loaders. One control height (40px, small 32px). */

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 40px; padding: 0 18px; border: 1px solid transparent; border-radius: var(--radius-sm);
  font-weight: 600; font-size: .9rem; line-height: 1; cursor: pointer; white-space: nowrap;
  background: var(--primary); color: var(--primary-ink);
  transition: background-color .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease),
              box-shadow .18s var(--ease), transform .12s var(--ease);
}
.btn:hover { background: var(--primary-hover); color: var(--primary-ink); text-decoration: none; }
.btn:active { transform: translateY(1px) scale(.985); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-sun { background: var(--primary); color: var(--primary-ink); }
.btn-sun:hover { background: var(--primary-hover); color: var(--primary-ink); }
.btn-sun:not(.loading)::after {
  content: ""; width: 15px; height: 15px; background: currentColor; flex: none; transition: transform .25s var(--ease);
  -webkit-mask: var(--arrow) center / contain no-repeat; mask: var(--arrow) center / contain no-repeat;
}
.btn-sun:not(.loading):hover::after { transform: translateX(5px); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); border-color: var(--faint); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); color: #fff; filter: brightness(.9); }
:root[data-theme="dark"] .btn-danger { color: #1b0a09; }
:root[data-theme="dark"] .btn-danger:hover { color: #1b0a09; filter: brightness(1.1); }
.btn-sm { height: 32px; padding: 0 12px; font-size: .82rem; }
.btn-block { width: 100%; }
.btn.loading { pointer-events: none; }
.btn.loading::after {
  content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { background: transparent; border: 0; font-size: 1.4rem; line-height: 1; cursor: pointer; width: 34px; height: 34px; border-radius: var(--radius-sm); color: var(--ink-soft); transition: background-color .16s var(--ease), color .16s var(--ease); }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Hover cues: remove / delete turns red, add turns green, so the action is obvious before the click */
[data-rm], [data-act="delete"], [data-idel], [data-cdel], [data-remove] { transition: background-color .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease); }
[data-rm]:hover, [data-rm]:focus-visible, [data-act="delete"]:hover, [data-act="delete"]:focus-visible,
[data-idel]:hover, [data-idel]:focus-visible, [data-cdel]:hover, [data-cdel]:focus-visible,
[data-remove]:hover, [data-remove]:focus-visible { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); text-decoration: none; }
[data-add], #custom, #add-item, #add-cat, #new-client, #invite { transition: background-color .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease), transform .16s var(--ease); }
[data-add]:hover, [data-add]:focus-visible, #custom:hover, #custom:focus-visible, #add-item:hover, #add-item:focus-visible,
#add-cat:hover, #add-cat:focus-visible, #new-client:hover, #new-client:focus-visible, #invite:hover, #invite:focus-visible { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); text-decoration: none; }

/* ---- light / dark switch (top banner and sign-in header, both on the brand colour) ---- */
.theme-toggle {
  position: relative; width: 36px; height: 36px; padding: 0; display: grid; place-items: center; overflow: hidden;
  background: transparent; border: 1px solid rgba(255, 255, 255, .28); border-radius: var(--radius-sm); color: var(--brand-ink); cursor: pointer;
  transition: background-color .18s var(--ease), border-color .18s var(--ease), transform .12s var(--ease);
}
.theme-toggle:hover { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .5); }
.theme-toggle:active { transform: scale(.94); }
.theme-toggle:focus-visible { box-shadow: 0 0 0 3px rgba(255, 255, 255, .45); }
.theme-toggle svg { position: absolute; transition: transform .45s var(--ease), opacity .3s var(--ease); }
.theme-toggle .ico-moon { opacity: 0; transform: rotate(-90deg) scale(.5); }
:root[data-theme="dark"] .theme-toggle .ico-sun { opacity: 0; transform: rotate(90deg) scale(.5); }
:root[data-theme="dark"] .theme-toggle .ico-moon { opacity: 1; transform: none; }

/* ---- cards ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s-4); min-width: 0; transition: border-color .2s var(--ease); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .label { color: var(--ink-soft); font-size: .85rem; }
.stat .value { font-size: 1.75rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

/* ---- fields ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s-3); min-width: 0; }
.field label, .field .label { font-weight: 550; font-size: .85rem; color: var(--ink); }
.field .hint { color: var(--ink-soft); font-size: .85rem; line-height: 1.45; }
.field .error { color: var(--danger); font-size: .8rem; }
.field .error:empty { display: none; }

.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 12px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease), background-color .16s var(--ease);
}
.textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--faint); opacity: .85; font-style: normal; }
.input:focus::placeholder, .textarea:focus::placeholder { opacity: .5; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-bg); }
.input[aria-invalid="true"]:focus, .select[aria-invalid="true"]:focus, .textarea[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--ink-soft); cursor: not-allowed; }
.input.num, .input[inputmode="decimal"] { text-align: right; font-variant-numeric: tabular-nums; }
.input.changed, .select.changed { background: var(--sun-100); border-color: var(--sun-hover); }
input[type="search"]::-webkit-search-cancel-button { cursor: pointer; }

/* dropdowns: one arrow we control, so it matches in both themes */
.select {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 36px;
  background-image: var(--chev); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}
.select option { background: var(--surface); color: var(--ink); }
.select:disabled { cursor: not-allowed; }

.form-grid { display: grid; gap: 0 var(--s-4); grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid.two { grid-template-columns: 1fr 1fr; } .form-grid .span-2 { grid-column: span 2; } }
.form-error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-line); border-radius: var(--radius-sm); padding: var(--s-3); margin-bottom: var(--s-3); animation: rise .25s var(--ease) both; }

/* ---- choices ---- */
/* option cards (system type, new or existing client): the radio dot is drawn by the card itself */
.radio-cards { display: grid; gap: var(--s-3); grid-template-columns: 1fr; }
@media (min-width: 640px) { .radio-cards { grid-template-columns: 1fr 1fr; } }
.radio-card {
  position: relative; display: block; cursor: pointer; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: var(--s-4) 52px var(--s-4) var(--s-4);
  transition: border-color .18s var(--ease), background-color .18s var(--ease), box-shadow .18s var(--ease), transform .12s var(--ease);
}
.radio-card:hover { border-color: var(--primary); }
.radio-card:active { transform: scale(.992); }
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card::before {
  content: ""; position: absolute; right: 16px; top: 16px; width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--line-strong); background: var(--surface); transition: border-color .18s var(--ease), background-color .18s var(--ease);
}
.radio-card::after {
  content: ""; position: absolute; right: 22px; top: 22px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary-ink); transform: scale(0); transition: transform .22s var(--ease);
}
.radio-card:has(input:checked) { border-color: var(--primary); background: var(--tint); box-shadow: inset 0 0 0 1px var(--primary); }
.radio-card:has(input:checked)::before { border-color: var(--primary); background: var(--primary); }
.radio-card:has(input:checked)::after { transform: scale(1); }
.radio-card:has(input:focus-visible) { box-shadow: var(--ring); }
.radio-card strong { display: block; color: var(--ink); margin-bottom: 2px; }
.radio-card span { color: var(--ink-soft); font-size: .875rem; }

/* toggle switch (replaces plain checkboxes) */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; user-select: none; }
.switch input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 38px; height: 22px; margin: 0;
  border-radius: 999px; background: var(--line-strong); cursor: pointer; transition: background-color .22s var(--ease), box-shadow .16s var(--ease);
}
.switch input[type="checkbox"]::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .24s var(--ease), width .16s var(--ease);
}
.switch:hover input[type="checkbox"]:not(:checked) { background: var(--faint); }
.switch input[type="checkbox"]:active::before { width: 20px; }
.switch input[type="checkbox"]:checked { background: var(--primary); }
.switch input[type="checkbox"]:checked::before { transform: translateX(16px); }
.switch input[type="checkbox"]:checked:active::before { transform: translateX(12px); }
.switch input[type="checkbox"]:focus-visible { box-shadow: var(--ring); }
.switch input[type="checkbox"]:disabled { opacity: .5; cursor: not-allowed; }

/* ---- tables ---- */
.table-wrap { position: relative; /* contains the absolutely-positioned .sr-only labels so they cannot widen the page */ overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { min-width: 560px; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { background: var(--surface-2); font-size: .78rem; font-weight: 600; color: var(--ink-soft); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; }
.table tbody tr { transition: background-color .15s var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table .actions { white-space: nowrap; text-align: right; }
.pager { display: flex; gap: var(--s-2); align-items: center; justify-content: space-between; margin-top: var(--s-3); flex-wrap: wrap; color: var(--ink-soft); font-size: .875rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s-3); margin-bottom: var(--s-3); align-items: center; }
.toolbar .input, .toolbar .select { width: auto; flex: 1 1 200px; max-width: 360px; }

/* ---- badges / alerts ---- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--tint-2); color: var(--tint-ink); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.alert { border-radius: var(--radius-sm); padding: var(--s-3) var(--s-4); margin-bottom: var(--s-3); border: 1px solid; animation: rise .28s var(--ease) both; }
.alert.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.alert.info { background: var(--tint); border-color: var(--info-line); color: var(--tint-ink); }
.alert.danger { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger); }

/* ---- empty / loading ---- */
.empty { text-align: center; padding: var(--s-6) var(--s-4); color: var(--ink-soft); }
.empty strong { display: block; color: var(--ink); margin-bottom: var(--s-1); }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: var(--radius-sm); min-height: 18px; margin: 8px 0; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.page-loader { display: grid; place-items: center; min-height: 40vh; color: var(--ink-soft); gap: var(--s-3); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--tint-2); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }

/* ---- loading screen: one random photo covering the window, a soft shade, logo and a progress bar ---- */
.loader { position: relative; display: grid; align-content: end; justify-items: center; overflow: hidden; color: #fff; background: #00213a; isolation: isolate; }
.loader.full { position: fixed; inset: 0; z-index: 90; padding: var(--s-5) var(--s-4) clamp(28px, 7vh, 64px); animation: loaderIn .35s .15s both; }   /* quick loads never show it */
.loader.inline { min-height: min(70vh, 560px); border-radius: var(--radius); padding: var(--s-5) var(--s-4) var(--s-5); }
@keyframes loaderIn { from { opacity: 0; } to { opacity: 1; } }
.loader-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -2; animation: lzoom 14s ease-out both; }
@keyframes lzoom { from { transform: scale(1.02); } to { transform: scale(1.12); } }
.loader-shade { position: absolute; inset: 0; z-index: -1; background: linear-gradient(to top, rgba(0, 24, 44, .88) 0%, rgba(0, 24, 44, .45) 32%, rgba(0, 24, 44, 0) 58%); }
.loader-foot { display: grid; justify-items: center; gap: 12px; }
.loader-logo { height: 52px; width: auto; }
.loader-bar { width: min(100%, 360px); height: 3px; border-radius: 2px; background: rgba(255, 255, 255, .28); overflow: hidden; }
.loader-bar span { display: block; width: 40%; height: 100%; border-radius: 2px; background: var(--accent); animation: lbar 1.4s ease-in-out infinite; }
@keyframes lbar { from { transform: translateX(-110%); } to { transform: translateX(260%); } }
.loader-text { margin: 0; font-size: .9rem; letter-spacing: .04em; color: rgba(255, 255, 255, .92); text-shadow: 0 1px 8px rgba(0, 0, 0, .5); }
@media (prefers-reduced-motion: reduce) {
  .loader-bg, .loader-bar span, .loader.full { animation: none; }
  .loader-bar span { width: 100%; }
}

/* ---- modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: flex-start; justify-content: center; padding: var(--s-4); overflow-y: auto; overscroll-behavior: contain; z-index: 60; animation: fade .18s var(--ease) both; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-pop); width: 100%; max-width: 640px; margin: 5vh auto; animation: pop .24s var(--ease) both; }
.modal.sm { max-width: 440px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s-4) var(--s-4) var(--s-3); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 0 var(--s-4) var(--s-4); }
.modal-foot { padding: var(--s-3) var(--s-4); border-top: 1px solid var(--line); display: flex; gap: var(--s-2); justify-content: flex-end; flex-wrap: wrap; background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }

/* ---- toasts ---- */
.toasts { position: fixed; right: max(var(--s-4), env(safe-area-inset-right)); bottom: max(var(--s-4), env(safe-area-inset-bottom)); left: max(var(--s-4), env(safe-area-inset-left)); display: flex; flex-direction: column; gap: var(--s-2); align-items: flex-end; z-index: 80; pointer-events: none; }
.toast { pointer-events: auto; background: var(--brand); color: var(--brand-ink); padding: 12px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow-pop); max-width: 420px; border-left: 4px solid var(--sun); animation: toast-in .3s var(--ease) both; }
.toast.ok { border-left-color: #35c07d; } .toast.error { border-left-color: #ff6b61; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
:root[data-theme="dark"] .toast { background: var(--surface-2); border: 1px solid var(--line-strong); border-left-width: 4px; color: var(--ink); }


/* ---------- cards with a soft light that follows the pointer ---------- */
.fx { position: relative; overflow: hidden; transition: transform .35s var(--ease), box-shadow .35s var(--ease), border-color .35s var(--ease); }
.fx::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .35s var(--ease);
  background: radial-gradient(300px circle at var(--mx, 50%) var(--my, 0%), color-mix(in srgb, var(--link) 16%, transparent), transparent 62%);
}
.fx:hover { transform: translateY(-4px); box-shadow: var(--shadow-lift); border-color: var(--line-strong); }
.fx:hover::before { opacity: 1; }
.card { box-shadow: var(--shadow-card); }

/* ---------- navy tiles with a white icon square (system choices, quick actions) ---------- */
.icon-tile { display: inline-grid; place-items: center; width: 54px; height: 54px; border-radius: 14px; background: #fff; color: var(--accent); flex: none; box-shadow: 0 6px 16px rgba(0, 20, 36, .22); transition: transform .35s var(--ease); }
.icon-tile .ic { width: 26px; height: 26px; }
.tile {
  --tile: #003153; position: relative; display: block; border-radius: 20px; padding: 26px; background: var(--tile); color: #fff; overflow: hidden;
  border: 1px solid transparent; transition: transform .4s var(--ease), box-shadow .4s var(--ease), background-color .3s var(--ease), border-color .3s var(--ease);
}
:root[data-theme="dark"] .tile { --tile: #0f3858; border-color: rgba(255, 255, 255, .08); }
.tile:hover { transform: translateY(-8px); box-shadow: var(--shadow-lift); background: color-mix(in srgb, var(--tile) 82%, #1b6aa8); }
.tile:hover .icon-tile { transform: rotate(-6deg) scale(1.08); }
.tile:focus-visible { outline: none; box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--link); }
.tile h2, .tile h3 { color: #fff; font-size: 1.1rem; font-weight: 700; font-size: 1.1rem; margin: 18px 0 6px; }
.tile p, .tile span.desc { color: #bcd0e0; font-size: .9rem; margin: 0; }
.tile a, .tile a:hover { color: #fff; }
a.tile:hover { text-decoration: none; }
.tile::after { content: ""; position: absolute; right: -40px; bottom: -40px; width: 140px; height: 140px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 150, 90, .22), transparent 70%); transition: transform .5s var(--ease); }
.tile:hover::after { transform: scale(1.6); }

/* option cards that behave as radio buttons, dressed as tiles */
.radio-card.tile { padding: 26px; border: 1px solid transparent; }
.radio-card.tile::before { right: 18px; top: 18px; border-color: rgba(255, 255, 255, .5); background: transparent; }
.radio-card.tile::after { right: 24px; top: 24px; left: auto; bottom: auto; width: 8px; height: 8px; background: #fff; transform: scale(0); border-radius: 50%; }
.radio-card.tile:has(input:checked) { background: color-mix(in srgb, var(--tile) 80%, #1b6aa8); border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent), var(--shadow-lift); }
.radio-card.tile:has(input:checked)::before { border-color: var(--accent); background: var(--accent); }
.radio-card.tile:has(input:checked)::after { transform: scale(1); }
.radio-card.tile strong { color: #fff; font-family: var(--font-display); font-size: 1.1rem; margin: 18px 0 6px; display: block; }
.radio-card.tile .desc { color: #bcd0e0; display: block; }
.radio-card.tile .icon-tile { color: var(--accent); }
.radio-card.tile .badge { background: rgba(255, 255, 255, .16); color: #fff; margin-left: 6px; }
.radio-card.tile:has(input:focus-visible) { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--link); }

/* quiet underlined link with an arrow, as used on the Sai Constructions site */
.link-arrow { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; color: var(--ink); border-bottom: 2px solid var(--ink); padding-bottom: 3px; }
.link-arrow:hover { color: var(--link); border-color: var(--link); text-decoration: none; }
.link-arrow::after { content: ""; width: 14px; height: 14px; background: currentColor; flex: none; -webkit-mask: var(--arrow) center / contain no-repeat; mask: var(--arrow) center / contain no-repeat; transition: transform .25s var(--ease); }
.link-arrow:hover::after { transform: translateX(5px); }

/* numbers on the dashboard */
.stat-card { display: flex; align-items: center; gap: 16px; padding: 22px; }
.stat-card .icon-sq { display: grid; place-items: center; width: 50px; height: 50px; border-radius: 14px; background: var(--tint); color: var(--link); flex: none; }
.stat-card .value { font-family: var(--font-display); font-size: 2rem; font-weight: 700; letter-spacing: -.03em; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-card .label { color: var(--ink-soft); font-size: .86rem; margin-top: 6px; }
