/* ============================================================
   Ten Habits Interactive Toolkit
   Shared stylesheet for every fillable tool.
   Design note: the tools are built to read like a working
   ledger. Hairline rules, a numbered gutter, and a single
   status rail that reports what the sheet currently holds.
   ============================================================ */

.tk {
  --tk-paper: #fdfcfa;
  --tk-card: #ffffff;
  --tk-ink: #1b1f27;
  --tk-mut: #5f6875;
  --tk-rule: #e3e0e6;
  --tk-rule-soft: #f0eef2;
  --tk-accent: #5a2a84;
  --tk-accent-lt: #7b3f9e;
  --tk-accent-wash: #f6f2fa;
  --tk-ok: #2f7d4f;
  --tk-warn: #b9792b;
  --tk-stop: #a3402f;
  --tk-serif: "EB Garamond", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --tk-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --tk-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --tk-radius: 12px;

  font-family: var(--tk-serif);
  color: var(--tk-ink);
  max-width: 900px;
  margin: 0 auto;
  padding: 0 4px 96px;
  line-height: 1.5;
}
.tk--data { --tk-accent: #24555a; --tk-accent-lt: #3c7d84; --tk-accent-wash: #eef4f4; }

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

/* ---------- masthead ---------- */
.tk-back { font-family: var(--tk-sans); font-size: .86rem; }
.tk-back a { color: var(--tk-accent); text-decoration: none; }
.tk-back a:hover { text-decoration: underline; }

.tk-eyebrow {
  font-family: var(--tk-sans); font-size: .68rem; font-weight: 700;
  letter-spacing: .16em; text-transform: uppercase; color: var(--tk-accent);
  margin: 1.2rem 0 .35rem;
}
.tk h1 { font-size: 2.1rem; line-height: 1.12; margin: 0 0 .3rem; font-weight: 600; }
.tk-sub { color: var(--tk-mut); font-size: 1.08rem; margin: 0 0 .6rem; max-width: 46em; }
.tk-habit {
  display: inline-block; font-family: var(--tk-sans); font-size: .72rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
  background: var(--tk-accent-wash); color: var(--tk-accent);
  border-radius: 999px; padding: .25em .8em; margin-bottom: 1.4rem;
}

.tk-lead {
  font-size: 1.06rem; line-height: 1.55; margin: .2rem 0 0; max-width: 44em;
  border-left: 3px solid var(--tk-accent); padding-left: 14px;
}

/* ---------- cards ---------- */
.tk-card {
  background: var(--tk-card); border: 1px solid var(--tk-rule);
  border-radius: var(--tk-radius); padding: 18px 20px 20px; margin: 16px 0;
}
.tk-card > h2 {
  font-size: 1.18rem; margin: 0 0 .15em; color: var(--tk-accent); font-weight: 600;
  display: flex; align-items: baseline; gap: .5em;
}
.tk-card > h2 .tk-num {
  font-family: var(--tk-mono); font-size: .72rem; color: var(--tk-mut);
  border: 1px solid var(--tk-rule); border-radius: 5px; padding: .1em .45em; flex: none;
}
.tk-hint { color: var(--tk-mut); font-size: .96rem; margin: .15em 0 .9rem; }
.tk-example {
  background: var(--tk-accent-wash); border-left: 3px solid var(--tk-accent-lt);
  border-radius: 0 8px 8px 0; padding: 9px 14px; font-size: .95rem; margin: .5rem 0 .9rem;
}
.tk-example b { font-family: var(--tk-sans); font-size: .7rem; letter-spacing: .1em;
  text-transform: uppercase; display: block; color: var(--tk-accent); margin-bottom: .15em; }

/* ---------- fields ---------- */
.tk-field { margin: 0 0 .95rem; }
.tk-label { display: block; font-weight: 600; margin: 0 0 .25rem; }
.tk-label .tk-aside { font-weight: 400; color: var(--tk-mut); font-size: .93rem; }
.tk input[type=text], .tk input[type=date], .tk input[type=number],
.tk textarea, .tk select {
  width: 100%; font-family: inherit; font-size: 1rem; color: var(--tk-ink);
  background: var(--tk-paper); border: 1px solid var(--tk-rule);
  border-radius: 9px; padding: 9px 11px;
}
.tk textarea { min-height: 68px; resize: vertical; line-height: 1.45; }
.tk select { font-family: var(--tk-sans); font-size: .93rem; }
.tk input:focus, .tk textarea:focus, .tk select:focus,
.tk [contenteditable]:focus, .tk button:focus-visible {
  outline: 2px solid var(--tk-accent-lt); outline-offset: 1px; border-color: var(--tk-accent-lt);
}
.tk-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tk-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 620px) { .tk-grid2, .tk-grid3 { grid-template-columns: 1fr; } }

/* ---------- checklists ---------- */
.tk-check { border-top: 1px solid var(--tk-rule-soft); padding: 9px 0; display: flex; gap: 11px; align-items: flex-start; }
.tk-check:first-of-type { border-top: none; }
.tk-check input[type=checkbox] { width: 18px; height: 18px; margin-top: 5px; accent-color: var(--tk-accent); flex: none; }
.tk-check-body { flex: 1; min-width: 0; }
.tk-check-body label { cursor: pointer; display: block; }
.tk-check-note { margin-top: 6px; }
.tk-check.done .tk-check-body > label { color: var(--tk-mut); text-decoration: line-through; text-decoration-thickness: 1px; }
.tk-check .tk-x { flex: none; }

/* ---------- ledger tables ---------- */
.tk-tablewrap { overflow-x: auto; margin: .2rem -4px .6rem; padding: 0 4px 4px; }
.tk-table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .95rem; }
.tk-table th, .tk-table td { border-bottom: 1px solid var(--tk-rule-soft); border-right: 1px solid var(--tk-rule-soft); padding: 0; vertical-align: top; }
.tk-table th:last-child, .tk-table td:last-child { border-right: none; }
.tk-table thead th {
  background: var(--tk-accent-wash); border-bottom: 1px solid var(--tk-rule);
  font-family: var(--tk-sans); font-size: .74rem; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--tk-accent); text-align: left; white-space: nowrap;
}
.tk-th-inner { display: flex; align-items: center; gap: 4px; padding: 7px 8px; }
.tk-th-name { flex: 1; min-width: 4em; outline: none; cursor: text; }
.tk-th-name:hover { text-decoration: underline dotted; }
.tk-table td input, .tk-table td textarea, .tk-table td select {
  border: none; border-radius: 0; background: transparent; padding: 7px 8px; font-size: .95rem;
}
.tk-table td textarea { min-height: 38px; }
.tk-table td select { font-size: .85rem; }
.tk-table td input:focus, .tk-table td textarea:focus, .tk-table td select:focus { background: var(--tk-card); outline-offset: -2px; }
.tk-table td.tk-num-cell input { font-family: var(--tk-mono); font-size: .88rem; text-align: right; }
.tk-gutter { width: 34px; text-align: right; }
.tk-table tbody td.tk-gutter {
  font-family: var(--tk-mono); font-size: .72rem; color: var(--tk-mut);
  background: var(--tk-rule-soft); padding: 9px 6px 0 0; user-select: none;
}
.tk-rowtools { width: 1%; white-space: nowrap; padding: 5px 4px !important; }
.tk-table tfoot td {
  background: var(--tk-accent-wash); font-family: var(--tk-mono); font-size: .84rem;
  padding: 7px 8px; text-align: right; border-top: 1px solid var(--tk-rule); border-bottom: none;
}
.tk-table tfoot td.tk-foot-label { text-align: left; font-family: var(--tk-sans); font-weight: 700;
  font-size: .72rem; letter-spacing: .07em; text-transform: uppercase; color: var(--tk-accent); }
.tk-tablebar { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin-top: .3rem; }
.tk-count { font-family: var(--tk-mono); font-size: .78rem; color: var(--tk-mut); margin-left: auto; }

/* ---------- buttons ---------- */
.tk-btn {
  font-family: var(--tk-sans); font-size: .86rem; font-weight: 600; line-height: 1;
  border-radius: 8px; padding: 8px 13px; cursor: pointer;
  border: 1px solid var(--tk-accent); background: var(--tk-accent); color: #fff;
}
.tk-btn:hover { filter: brightness(1.09); }
.tk-btn.sec { background: var(--tk-card); color: var(--tk-accent); }
.tk-btn.ghost { background: transparent; color: var(--tk-mut); border-color: var(--tk-rule); }
.tk-btn.sm { font-size: .78rem; padding: 6px 10px; }
.tk-x {
  border: 1px solid var(--tk-rule); background: var(--tk-card); color: var(--tk-mut);
  border-radius: 6px; width: 26px; height: 26px; line-height: 1; cursor: pointer;
  font-family: var(--tk-sans); font-size: .95rem; padding: 0;
}
.tk-x:hover { color: var(--tk-stop); border-color: var(--tk-stop); }
.tk-x.up:hover, .tk-x.dn:hover { color: var(--tk-accent); border-color: var(--tk-accent); }
.tk-th-btn { border: none; background: none; color: var(--tk-accent); cursor: pointer;
  font-size: .9rem; line-height: 1; padding: 2px 3px; opacity: .55; }
.tk-th-btn:hover { opacity: 1; }

/* ---------- composed output ---------- */
.tk-out {
  background: var(--tk-accent-wash); border-radius: 9px; padding: 14px 16px;
  white-space: pre-wrap; font-size: 1.02rem; min-height: 3em; line-height: 1.55;
}
.tk-verdict { font-family: var(--tk-sans); font-weight: 600; font-size: .95rem;
  padding: 10px 14px; border-radius: 9px; margin-top: .5rem; }
.tk-verdict.go { background: #e9f5ee; color: var(--tk-ok); }
.tk-verdict.hold { background: #fbf1e3; color: var(--tk-warn); }
.tk-verdict.stop { background: #fbe9e6; color: var(--tk-stop); }
.tk-meter { height: 6px; background: var(--tk-rule-soft); border-radius: 999px; overflow: hidden; margin: .5rem 0 .1rem; }
.tk-meter span { display: block; height: 100%; background: var(--tk-accent-lt); width: 0; transition: width .2s ease; }

/* ---------- repeating blocks ---------- */
.tk-rep { border: 1px solid var(--tk-rule); border-radius: 10px; padding: 14px 16px; margin: 0 0 12px; background: var(--tk-paper); }
.tk-rep-head { display: flex; align-items: center; gap: 8px; margin-bottom: .6rem; }
.tk-rep-head h3 { font-size: 1rem; margin: 0; flex: 1; color: var(--tk-accent); font-weight: 600; }

/* ---------- action rail (signature element) ---------- */
.tk-rail {
  position: sticky; bottom: 0; z-index: 20; margin-top: 26px;
  background: rgba(255,255,255,.95); backdrop-filter: blur(8px);
  border-top: 2px solid var(--tk-accent); border-radius: 0;
  padding: 10px 6px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.tk-status {
  font-family: var(--tk-mono); font-size: .76rem; color: var(--tk-mut);
  margin-left: auto; text-align: right; line-height: 1.35;
}
.tk-status b { color: var(--tk-ok); font-weight: 500; }
.tk-menu { position: relative; }
.tk-menu-pop {
  position: absolute; bottom: calc(100% + 8px); left: 0; min-width: 232px;
  background: var(--tk-card); border: 1px solid var(--tk-rule); border-radius: 10px;
  box-shadow: 0 12px 34px rgba(0,0,0,.16); padding: 6px; display: none;
}
.tk-menu-pop.open { display: block; }
.tk-menu-pop button, .tk-menu-pop label {
  display: block; width: 100%; text-align: left; background: none; border: none;
  font-family: var(--tk-sans); font-size: .87rem; color: var(--tk-ink);
  padding: 8px 10px; border-radius: 7px; cursor: pointer;
}
.tk-menu-pop button:hover, .tk-menu-pop label:hover { background: var(--tk-accent-wash); color: var(--tk-accent); }
.tk-menu-pop .tk-menu-head {
  font-family: var(--tk-sans); font-size: .67rem; font-weight: 700; letter-spacing: .11em;
  text-transform: uppercase; color: var(--tk-mut); padding: 9px 10px 4px;
}
.tk-menu-pop hr { border: none; border-top: 1px solid var(--tk-rule-soft); margin: 5px 4px; }
.tk-menu-pop small { display: block; color: var(--tk-mut); font-family: var(--tk-sans); font-size: .76rem; }

/* saved copies */
.tk-copies { list-style: none; margin: .4rem 0 0; padding: 0; }
.tk-copies li { display: flex; align-items: center; gap: 8px; font-family: var(--tk-sans);
  font-size: .85rem; padding: 6px 0; border-top: 1px solid var(--tk-rule-soft); }
.tk-copies li span { flex: 1; }
.tk-copies li time { color: var(--tk-mut); font-size: .78rem; font-family: var(--tk-mono); }

/* toast */
.tk-toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 60;
  background: var(--tk-ink); color: #fff; font-family: var(--tk-sans); font-size: .86rem;
  padding: 10px 18px; border-radius: 999px; box-shadow: 0 8px 26px rgba(0,0,0,.28);
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
}
.tk-toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* footer credit */
.tk-credit { font-family: var(--tk-sans); font-size: .8rem; color: var(--tk-mut);
  border-top: 1px solid var(--tk-rule); margin-top: 28px; padding-top: 12px; }
.tk-credit a { color: var(--tk-accent); }

/* ---------- dark mode ---------- */
[data-md-color-scheme="slate"] .tk, .tk[data-tk-dark="1"] {
  --tk-paper: #14171d; --tk-card: #1c1f27; --tk-ink: #e8e6ea; --tk-mut: #a3a8b4;
  --tk-rule: #343845; --tk-rule-soft: #262a33; --tk-accent: #c39bea; --tk-accent-lt: #d3b6f2;
  --tk-accent-wash: #251d33; --tk-ok: #6bc48c; --tk-warn: #e0a75c; --tk-stop: #e08878;
}
[data-md-color-scheme="slate"] .tk--data, .tk--data[data-tk-dark="1"] {
  --tk-accent: #7fc6ca; --tk-accent-lt: #a5dade; --tk-accent-wash: #16292b;
}
[data-md-color-scheme="slate"] .tk-rail, .tk[data-tk-dark="1"] .tk-rail { background: rgba(16,18,23,.95); }
[data-md-color-scheme="slate"] .tk-verdict.go, .tk[data-tk-dark="1"] .tk-verdict.go { background: #17301f; }
[data-md-color-scheme="slate"] .tk-verdict.hold, .tk[data-tk-dark="1"] .tk-verdict.hold { background: #33260f; }
[data-md-color-scheme="slate"] .tk-verdict.stop, .tk[data-tk-dark="1"] .tk-verdict.stop { background: #331a17; }

/* ---------- print ---------- */
@media print {
  .tk { max-width: none; padding: 0; }
  .tk-rail, .tk-back, .tk-tablebar, .tk-x, .tk-th-btn, .tk-noprint, .tk-toast { display: none !important; }
  .tk-card { border-color: #bbb; break-inside: avoid; }
  .tk textarea { height: auto; min-height: 0; overflow: visible; }
  .tk input, .tk textarea, .tk select { border-color: #ccc; background: none; }
  .tk-table thead th, .tk-table tfoot td { background: #f2f2f2 !important; color: #000; }
  a[href]::after { content: ""; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .tk *, .tk *::before, .tk *::after { transition: none !important; animation: none !important; }
}

/* ============================================================
   Standalone page frame. These tools open as their own pages,
   inside the site and as saved files on a person's own computer.
   ============================================================ */
html.tk-page, html.tk-page body { background: #f2f0ec; }
html.tk-page body { margin: 0; padding: 22px 16px 0; -webkit-text-size-adjust: 100%; }
html.tk-page.tk-dark, html.tk-page.tk-dark body { background: #0f1116; }
@media (prefers-color-scheme: dark) {
  html.tk-page, html.tk-page body { background: #0f1116; }
  html.tk-page.tk-light, html.tk-page.tk-light body { background: #f2f0ec; }
}
@media print { html.tk-page, html.tk-page body { background: #fff; padding: 0; } }
