/* ============================================================
   MacLeod Services v4 — Components
   Shared component layer built ONLY on tokens.css variables.
   Load order on every page: tokens.css, then components.css,
   then the app's own app.css for page/tool-specific rules.
   Class names are contractual — later v4 phases re-skin their
   apps by keeping this markup and swapping only app.css.
   ============================================================ */

/* ---- Base ---- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-sans); font-size: var(--fs-base); line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: var(--lh-tight); margin: 0 0 var(--sp-3); font-weight: var(--fw-bold); }
h1 { font-size: var(--fs-2xl); letter-spacing: -0.01em; }
h2 { font-size: var(--fs-xl); color: var(--text); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p { margin: 0 0 var(--sp-4); }
a { color: var(--gold-deep); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-sm); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.gold-text { color: var(--gold-deep); }
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 var(--sp-5); }
.wrap.narrow { max-width: var(--wrap-narrow); }
section.block { padding: var(--sp-7) 0; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--gold); color: var(--ink-on-gold); padding: var(--sp-2) var(--sp-4); z-index: 200; }
.skip-link:focus { left: var(--sp-3); top: var(--sp-3); }

/* ---- Header / nav ---- */
.site-header {
  background: rgba(255, 255, 255, .97); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 60;
}
.nav-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); padding-top: var(--sp-3); padding-bottom: var(--sp-3); }
.brand { display: inline-flex; align-items: center; gap: var(--sp-3); font-weight: var(--fw-bold); font-size: var(--fs-md); color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-logo { height: 36px; width: 36px; border-radius: var(--r-sm); }
.brand .brand-sub { display: block; font-size: var(--fs-xs); color: var(--muted); font-weight: var(--fw-normal); letter-spacing: var(--ls-label); text-transform: uppercase; }
.site-nav { display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; }
.site-nav a { color: var(--text-2); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.site-nav a:hover { color: var(--gold-deep); text-decoration: none; }
.site-nav a[aria-current="page"] { color: var(--gold-deep); }
.nav-toggle { display: none; background: var(--surface); border: 1px solid var(--line); color: var(--text); border-radius: var(--r-sm); padding: 6px 12px; font-size: 1.15rem; cursor: pointer; }

/* ---- Buttons ---- */
.btn {
  display: inline-block; background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: var(--ink-on-gold); border: 1px solid var(--gold-deep);
  border-radius: var(--r-sm); padding: 12px 24px; min-height: 44px; font-size: var(--fs-base); font-weight: var(--fw-medium);
  cursor: pointer; line-height: 1.3; transition: filter var(--dur) var(--ease), background var(--dur) var(--ease);
}
.btn:hover { filter: brightness(1.06); text-decoration: none; color: var(--ink-on-gold); }
.btn.gold { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: var(--ink-on-gold); }
.btn.gold:hover { color: var(--ink-on-gold); }
.btn.ghost { background: #ffffff; border-color: var(--line-strong); color: var(--text); }
.btn.ghost:hover { color: var(--gold-deep); border-color: var(--gold); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { color: #fff; }
.btn.small { padding: 7px 14px; font-size: var(--fs-sm); }
.btn:disabled { opacity: .5; cursor: default; filter: none; }

/* ---- Hero ---- */
.hero { background: radial-gradient(900px 420px at 50% -90px, rgba(201,151,0,.13) 0%, var(--bg) 62%); padding: var(--sp-8) 0 var(--sp-7); text-align: center; }
.hero h1 { font-size: var(--fs-3xl); margin-bottom: var(--sp-3); }
.hero h1 .gold { color: var(--gold-deep); }
.hero .lead { font-size: var(--fs-md); color: var(--muted); max-width: 660px; margin: 0 auto var(--sp-6); }
.hero-cta { display: flex; gap: var(--sp-3); justify-content: center; flex-wrap: wrap; }
.badges { display: flex; gap: var(--sp-5); justify-content: center; flex-wrap: wrap; margin-top: var(--sp-6); color: var(--muted); font-size: var(--fs-sm); }
.badges b { color: var(--gold-deep); }
.hero-img { width: 100%; border-radius: var(--r-lg); margin-top: var(--sp-6); border: 1px solid var(--line); display: block; }

/* ---- Layout grids & cards ---- */
.grid { display: grid; gap: var(--sp-5); }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-5); box-shadow: var(--shadow-card); }
.card h3 { color: var(--gold-deep); margin-top: 0; }
.card.flat { box-shadow: none; }

/* ---- Badges / tiers ---- */
.tier { display: inline-block; font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: var(--ls-label); text-transform: uppercase; padding: 3px 10px; border-radius: var(--r-pill); margin-bottom: var(--sp-2); }
.tier.free { background: var(--ok-tint); color: var(--ok); }
.tier.pro { background: var(--gold-tint); color: var(--gold-deep); border: 1px solid var(--gold-line); }
.tier.admin { background: var(--accent-tint); color: var(--accent-2); }
.tier.off { background: var(--danger-tint); color: var(--danger); }
.badge { display: inline-block; font-size: var(--fs-xs); font-weight: var(--fw-bold); padding: 2px 9px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-2); border: 1px solid var(--line); }
.badge.gold { background: var(--gold-tint); color: var(--gold-deep); border-color: var(--gold-line); }
.pro-badge { display: inline-block; background: linear-gradient(180deg, var(--gold-2), var(--gold-deep)); color: var(--ink-on-gold); font-weight: var(--fw-black); letter-spacing: .1em; font-size: var(--fs-sm); padding: 6px 16px; border-radius: var(--r-sm); margin-bottom: var(--sp-4); }

/* ---- Alerts / flash ---- */
.flash, .alert { border-radius: var(--r-sm); padding: var(--sp-3) var(--sp-4); margin: var(--sp-4) 0; border: 1px solid var(--line); background: var(--surface); }
.flash.ok, .alert.ok { background: var(--ok-tint); border-color: var(--ok); }
.flash.warn, .alert.warn { background: var(--warn-tint); border-color: var(--gold-deep); }
.flash.info, .alert.info { background: var(--info-tint); border-color: var(--info); }
.flash.error, .alert.error { background: var(--danger-tint); border-color: var(--danger); }

/* ---- Forms — v4.5 shared field component (ONE spec, no exceptions) ---- */
label { display: block; margin: var(--sp-3) 0 var(--sp-1); font-weight: var(--fw-medium); color: var(--text); }
.field label { margin-top: 0; }
input:not([type]), input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="tel"], input[type="search"], input[type="date"], input[type="month"], input[type="url"],
input[type="file"], select, textarea {
  width: 100%; background: var(--field-bg); color: var(--text); border: 1.5px solid var(--field-line);
  border-radius: var(--field-radius); padding: var(--field-pad); font-size: var(--field-fs); font-family: inherit;
}
input::placeholder, textarea::placeholder { color: var(--placeholder); opacity: 1; }
input[type="color"] { height: 46px; padding: 4px; cursor: pointer; background: var(--field-bg); border: 1.5px solid var(--field-line); border-radius: var(--field-radius); }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); box-shadow: var(--field-ring); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.form label { display: block; margin: var(--sp-3) 0; font-weight: var(--fw-medium); }
.form input, .form select, .form textarea { margin-top: 6px; }
fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-4); margin: var(--sp-4) 0; }
legend { color: var(--gold-deep); font-weight: var(--fw-bold); padding: 0 var(--sp-2); }
.save-msg { color: var(--muted); font-size: var(--fs-sm); margin-left: var(--sp-2); }

/* ---- Tables ---- */
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; color: var(--muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; padding: var(--sp-2); border-bottom: 1px solid var(--line); }
table.data td { padding: 10px var(--sp-2); border-bottom: 1px solid var(--line); vertical-align: top; }

/* ---- Pricing plans ---- */
.plan-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-5); align-items: stretch; }
.plan { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-6); text-align: center; display: flex; flex-direction: column; box-shadow: var(--shadow-card); }
.plan.featured { border: 2px solid var(--gold); }
.plan .price { font-size: 2.4rem; font-weight: var(--fw-black); color: var(--gold-deep); margin: var(--sp-2) 0; }
.plan ul { list-style: none; padding: 0; margin: var(--sp-4) 0; text-align: left; }
.plan li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.plan li::before { content: "✓ "; color: var(--ok); font-weight: var(--fw-bold); }
.plan .btn { margin-top: auto; }

/* ---- Lock / upgrade panel (paywall) ---- */
.lock-panel { background: var(--surface); border: 1px solid var(--gold-deep); border-radius: var(--r-md); padding: var(--sp-7) var(--sp-6); text-align: center; margin: var(--sp-7) 0; box-shadow: var(--shadow-card); }
.lock-panel p { color: var(--muted); }
.lock-panel .btn { margin: 6px; }
.lock-features { list-style: none; padding: 0; margin: var(--sp-5) auto; max-width: 460px; text-align: left; }
.lock-features li { padding: var(--sp-2) 0 var(--sp-2) 28px; border-bottom: 1px solid var(--line); position: relative; }
.lock-features li::before { content: "✓"; color: var(--gold-deep); font-weight: var(--fw-black); position: absolute; left: 4px; }

/* ---- Tool-window chrome (shared by floating windows + framed pages) ---- */
.ms-win-bar { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--r-md) var(--r-md) 0 0; background: linear-gradient(180deg, #ffffff, var(--bg-2)); border-bottom: 1px solid var(--line); user-select: none; touch-action: none; }
.ms-win-bar.static { touch-action: auto; }
.ms-dots { display: inline-flex; gap: 7px; }
.ms-dots .dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; cursor: pointer; }
.ms-dots .dot.r { background: #ff5f57; } .ms-dots .dot.y { background: #febc2e; } .ms-dots .dot.g { background: #28c840; }
.ms-win-title { font-weight: var(--fw-bold); letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ms-win-btns { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; }
.ms-win-btn { background: #ffffff; color: var(--text); border: 1px solid var(--line-strong); border-radius: 7px; padding: 3px 10px; font-size: var(--fs-sm); cursor: pointer; line-height: 1.5; }
.ms-win-btn:hover { background: var(--gold-tint); text-decoration: none; }
.ms-win-btn.danger:hover { background: var(--danger-tint); }
.tool-window-frame { border: 1px solid var(--line-strong); border-radius: var(--r-md); overflow: hidden; background: var(--surface); box-shadow: var(--shadow-bar); }
.tool-window-frame #tool-app, .tool-window-frame .tool-app { padding: var(--sp-4); }

/* ---- Footer ---- */
.site-footer { border-top: 1px solid var(--line); margin-top: var(--sp-7); padding: var(--sp-7) 0 var(--sp-5); background: var(--bg-2); }
.foot-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: var(--sp-6); }
.foot-grid h4 { color: var(--gold-deep); font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: var(--ls-label); }
.foot-grid a { color: var(--text-2); }
.foot-grid a:hover { color: var(--gold-deep); }
.foot-grid p { color: var(--muted); font-size: var(--fs-sm); }
.foot-base { color: var(--faint); font-size: var(--fs-sm); margin-top: var(--sp-6); padding-top: var(--sp-4); border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .grid.c4 { grid-template-columns: repeat(2, 1fr); }
  .plan-cards { grid-template-columns: 1fr; }
  .foot-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .grid.c3 { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 1.8rem; }
  .hero h1 { font-size: var(--fs-2xl); }
  .site-nav { display: none; flex-direction: column; align-items: stretch; position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); padding: var(--sp-3) var(--sp-5) var(--sp-5); border-bottom: 1px solid var(--line); }
  body.nav-open .site-nav { display: flex; }
  .nav-toggle { display: block; }
  .site-header { position: sticky; }
  .nav-row { position: relative; }
  .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .foot-grid { grid-template-columns: 1fr; }
}

/* ---- Print ---- */
@media print {
  .site-header, .site-footer, .no-print, .flash { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 1px solid #999; background: #fff; color: #000; box-shadow: none; }
}
