* { box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; margin: 0; color: #1f2937; background: #f7f7f8; }
a { color: #1d4ed8; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar: same per-tenant gradient on EVERY page (login, signup, AND
   the authenticated app pages like /projects). Background fades left-
   to-right from pure white to a 32%-tint of --tenant-accent (the
   tenant's chosen color, exposed via base.html). The dark slate topbar
   the app used to ship with is gone — every tenant's app reflects their
   brand. color-mix() is supported in all modern browsers (Chrome 111+,
   Safari 16.2+, Firefox 113+). */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(
    180deg,
    #ffffff 0%,
    color-mix(in srgb, var(--tenant-accent, #d97a1f) var(--tenant-mix, 32%), white) 100%
  );
  color: #1f1d1b;
  border-bottom: 1px solid color-mix(in srgb, var(--tenant-accent, #d97a1f) calc(var(--tenant-mix, 32%) * 0.8), white);
  padding: 8px 20px;
}
.topbar .brand a { color: #1f1d1b; font-weight: 600; font-size: 16px; display: inline-flex; align-items: center; gap: 10px; }
.topbar .brand .logo { height: 63px; width: auto; display: block; margin-left: 12px; }
.topbar .brand span { color: #78624a; font-weight: 500; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.topbar nav { display: flex; align-items: center; gap: 16px; }
.topbar nav a { color: #57534e; text-decoration: none; }
.topbar nav a:hover { color: #1f1d1b; }
/* Active route — uses the darker tenant-color variant so it stands out
   against the soft gradient header but stays on-brand. For Threshold
   (primary_color=#000000) this is pure black; for orange tenants it's
   a deep burnt orange; for any new tenant it's roughly 82% of their
   chosen color's brightness. */
.topbar nav a.active {
  color: var(--tenant-accent-hover, #b8631a);
  font-weight: 700;
}
.topbar nav .who { color: #78624a; font-size: 13px; }
.topbar nav .link { background: none; border: 0; color: #57534e; cursor: pointer; padding: 0; font-size: 14px; }
.topbar nav .link:hover { color: #1f1d1b; text-decoration: underline; }

/* Public-shell pages (login, signup) inherit the same topbar — kept as
   an empty hook in case we want to specialize either pre/post-auth
   later. */
body.public-shell .topbar { /* identical to the base rules above */ }

/* Tenant name shown in the topbar next to the logo. Rendered only when
   the request has a resolved tenant (apex pages hide it since the
   marketing logo already carries the brand wordmark). The selector is
   specific enough to override the generic `.topbar .brand span` rule. */
.topbar .brand .tenant-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: #1f1d1b;
  margin-left: 4px;
}
@media (max-width: 540px) {
  .topbar .brand .tenant-name { font-size: 15px; }
}

/* Tenant name shown prominently inside the login card */
.login-card .tenant-name-display {
  font-size: 22px;
  font-weight: 700;
  color: #f8fafc;
  margin: 16px 0 2px;
  letter-spacing: -0.01em;
}
body.public-shell .login-card .tenant-name-display {
  color: #1f1d1b;
}

/* Login card under the public shell — flip from dark slate to a clean
   white card with the brand orange CTA. */
body.public-shell .login-card {
  background: #fff;
  color: #1f1d1b;
  border: 1px solid #e9bd87;
  box-shadow: 0 4px 18px rgba(217, 122, 31, 0.08);
}
body.public-shell .login-card h1 {
  color: #1f1d1b;
}
body.public-shell .login-card form label { color: #57534e; }
body.public-shell .login-card form input { color: #1f1d1b; }
body.public-shell .login-card button.primary {
  /* Tenant-supplied accent (set via base.html); falls back to brand orange. */
  background: var(--tenant-accent, #d97a1f);
  border-color: var(--tenant-accent, #d97a1f);
  box-shadow: 0 1px 0 rgba(0,0,0,0.04), 0 2px 8px rgba(0, 0, 0, 0.12);
}
body.public-shell .login-card button.primary:hover {
  background: var(--tenant-accent-hover, #b8631a);
  border-color: var(--tenant-accent-hover, #b8631a);
}

main { padding: 20px; max-width: 1200px; margin: 0 auto; }
h1 { margin: 0 0 8px; }
h2 { margin: 28px 0 10px; }
.muted { color: #6b7280; }
.error { background: #fee2e2; color: #991b1b; padding: 8px 12px; border-radius: 6px; margin: 10px 0; }
.warn { color: #b45309; font-weight: 600; }
.over { color: #b91c1c; font-weight: 600; }
.small { font-size: 12px; display: inline-block; margin-top: 4px; }
.ok { color: #047857; font-weight: 600; }

.card { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; margin: 16px 0; }
.card.centered { max-width: 420px; margin: 80px auto; }
.login-card { background: #0f172a; color: #e2e8f0; text-align: center; padding: 28px; }
.login-card h1 { color: #f8fafc; font-weight: 500; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; margin: 14px 0 18px; }
.login-card .login-logo { width: 100%; max-width: 220px; height: auto; }
.login-card form label { color: #cbd5e1; text-align: left; }
.login-card form input { color: #0f172a; }

.actions { display: flex; gap: 10px; margin: 14px 0; }

.summary { display: flex; gap: 12px; margin: 14px 0; flex-wrap: wrap; }
.summary > div { background: #fff; border: 1px solid #e5e7eb; padding: 10px 16px; border-radius: 6px; min-width: 160px; }
.summary > div span { display: block; color: #6b7280; font-size: 12px; }
.summary > div strong { font-size: 20px; }

.btn { display: inline-block; padding: 6px 12px; border: 1px solid #d1d5db; background: #fff; border-radius: 6px; color: #1f2937; cursor: pointer; }
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary, button.primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn.primary:hover, button.primary:hover { background: #1d4ed8; }
.btn.small, button.small { padding: 3px 8px; font-size: 12px; }
.btn.big, button.big { padding: 10px 18px; font-size: 16px; }
button.danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

table.data { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #e5e7eb; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid #f1f5f9; text-align: left; vertical-align: top; }
table.data th { background: #f1f5f9; font-size: 13px; }
table.data .right { text-align: right; font-variant-numeric: tabular-nums; }
table.data .center { text-align: center; }

form.stack { display: flex; flex-direction: column; gap: 12px; }
form.stack label { display: flex; flex-direction: column; font-size: 14px; gap: 4px; }
form.stack input { padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; }
form.stack button { padding: 10px; }

form.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; align-items: end; }
form.grid label { display: flex; flex-direction: column; font-size: 13px; gap: 4px; }
form.grid label.wide { grid-column: 1 / -1; }
form.grid input, form.grid select { padding: 7px 9px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; }
form.grid button { grid-column: 1 / -1; justify-self: start; padding: 8px 14px; }

form.inline-grid { display: grid; grid-template-columns: repeat(5, auto) auto; gap: 6px; margin: 4px 0; align-items: center; }
form.inline-grid input, form.inline-grid select { padding: 4px 6px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 12px; }
form.inline { display: inline; }

button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

details summary { cursor: pointer; color: #2563eb; font-size: 12px; }

#long-upload-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.65);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
  animation: lu-fade 0.15s ease-out;
}
#long-upload-overlay[hidden] { display: none; }
@keyframes lu-fade { from { opacity: 0; } to { opacity: 1; } }
.lu-card {
  background: #fff; padding: 32px 40px; border-radius: 12px; max-width: 420px;
  text-align: center; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
.lu-spinner {
  width: 44px; height: 44px; margin: 0 auto 18px;
  border: 4px solid #e5e7eb; border-top-color: #2563eb; border-radius: 50%;
  animation: lu-spin 0.8s linear infinite;
}
@keyframes lu-spin { to { transform: rotate(360deg); } }
.lu-title { font-size: 16px; font-weight: 600; color: #0f172a; }
.lu-step { color: #2563eb; font-size: 14px; margin-top: 8px; min-height: 1.4em; }
.lu-timer { color: #6b7280; font-size: 12px; margin-top: 14px; }

.addr-wrap { position: relative; }
.addr-wrap input { width: 100%; box-sizing: border-box; }
.addr-suggest {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 100;
  background: #fff; border: 1px solid #d1d5db; border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  max-height: 260px; overflow-y: auto; margin-top: 2px;
}
.addr-item {
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid #f3f4f6; line-height: 1.4;
}
.addr-item:hover { background: #eff6ff; }
.addr-item:last-child { border-bottom: 0; }

.splits-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 2px; }
.splits-table th { background: #f1f5f9; padding: 6px 8px; text-align: left; font-size: 12px; }
.splits-table td { padding: 4px 6px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.splits-table tfoot td { border-bottom: 0; padding-top: 8px; }
.splits-table input[type="number"] { width: 110px; padding: 5px 7px; border: 1px solid #d1d5db; border-radius: 4px; text-align: right; font-variant-numeric: tabular-nums; }
.splits-table input[readonly] { background: #f9fafb; color: #6b7280; }
.splits-table select { width: 100%; padding: 5px 7px; border: 1px solid #d1d5db; border-radius: 4px; max-width: 360px; }
.splits-table .split-avail { color: #6b7280; font-variant-numeric: tabular-nums; }
.splits-table .split-del { padding: 2px 8px; }

.progress-bar {
  height: 8px; background: #e5e7eb; border-radius: 4px;
  margin: 6px 0 4px; overflow: hidden; position: relative;
}
.progress-bar[hidden] { display: none; }
.progress-fill {
  height: 100%; width: 0%; background: #2563eb;
  transition: width 0.18s ease-out; border-radius: 4px;
}
.progress-bar.indeterminate .progress-fill {
  width: 35%;
  animation: progress-indeterminate 1.3s ease-in-out infinite;
}

.drop-zone {
  display: block; border: 2px dashed #cbd5e1; border-radius: 10px;
  padding: 22px 18px; text-align: center; cursor: pointer;
  background: #f8fafc; transition: background 0.12s, border-color 0.12s;
}
.drop-zone:hover { background: #eff6ff; border-color: #93c5fd; }
.drop-zone.dragging { background: #dbeafe; border-color: #2563eb; border-style: solid; }
.drop-zone input[type="file"] {
  position: absolute; left: -9999px; opacity: 0; width: 1px; height: 1px;
}
.drop-zone-icon { font-size: 32px; line-height: 1; }
.drop-zone-text { font-size: 14px; color: #0f172a; margin-top: 6px; }
.drop-zone-sub { font-size: 12px; color: #6b7280; margin-top: 4px; }
.drop-zone-files { margin-top: 10px; }
.drop-zone-chip {
  display: inline-block; background: #2563eb; color: #fff; padding: 4px 10px;
  border-radius: 999px; font-size: 12px; margin: 2px;
}

/* ===== Mobile-friendly layout (≤ 700px) ===== */
@media (max-width: 700px) {
  body { -webkit-text-size-adjust: 100%; }
  main { padding: 14px 12px; }

  /* Topbar reflows; hide low-priority text */
  .topbar {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px 14px;
    row-gap: 6px;
  }
  .topbar nav { gap: 12px; flex-wrap: wrap; font-size: 13px; }
  .topbar nav .who { display: none; }
  .topbar .brand a { font-size: 14px; gap: 8px; }
  .topbar .brand .logo { height: 34px; }
  .topbar .brand span { display: none; }

  h1 { font-size: 20px; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.25; }
  h2 { font-size: 17px; word-wrap: break-word; }
  .muted { word-wrap: break-word; overflow-wrap: anywhere; }

  /* Summary tiles stack to one column */
  .summary { gap: 8px; }
  .summary > div { min-width: 0; flex: 1 1 100%; padding: 12px 14px; }
  .summary > div strong { font-size: 18px; }

  /* Tables scroll horizontally instead of overflowing the page */
  table.data {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  table.data th, table.data td { padding: 7px 8px; font-size: 13px; }

  /* Cards / action bar / forms */
  .card { padding: 14px; }
  .actions { flex-wrap: wrap; gap: 8px; }
  .actions .btn { flex: 0 1 auto; }
  form.grid { grid-template-columns: 1fr; gap: 10px; }

  /* Login card */
  .card.centered { margin: 24px auto; max-width: 100%; }
}
@keyframes progress-indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(290%); }
}
