/* ============================================================
   ROUTINES — the routines index
   The LEDGER look again: a card per routine, its tasks as ranked rows, and a strip of the
   browsed month beside each task — filled where the task was due and kept, open where it
   was due and missed. A routine is a pattern, so the pattern is what the page draws.
   ============================================================ */

/* A kept day and a missed one are the only two states, so nothing here blends; the
   summary strip at the top is the one that averages. */
.rtn-strip .ledger-day { cursor: default; }
.rtn-no-strip { color: var(--text-3); font-size: var(--fs-11); }

.rtn-card-link {
  color: var(--text-1);
  text-decoration: none;
  transition: color var(--dur-fast) ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.rtn-card-link:hover { text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }

/* Delete sits past the score, and stays out of the way until the card is hovered. */

.rtn-description {
  margin: 0;
  padding: 11px 16px 3px;
  color: var(--text-2);
  font-size: var(--fs-12);
  line-height: 1.55;
  white-space: pre-wrap;
  text-wrap: pretty;
}

.rtn-cat-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }

/* A task's name and how often it recurs sit on one line: both are short, and stacking them
   made a 60px row out of two words with a wide empty column beside it. */
.rtn-row .ledger-body { display: flex; align-items: baseline; gap: 8px; }
.rtn-row .ledger-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rtn-row .ledger-meta { margin-top: 0; flex-shrink: 0; }

/* The rate in the card's score slot. The three bands are the same ones the page has
   always used, now on tokens rather than raw hex. */
.rtn-rate { font-variant-numeric: tabular-nums; }
.rtn-rate.is-good { color: var(--accent-bright); }
.rtn-rate.is-fair { color: var(--warn-bright); }
.rtn-rate.is-poor { color: var(--danger-bright); }
.ledger-card-score:has(.rtn-rate)::before { display: none; }

.rtn-card-empty {
  padding: 14px 16px 16px;
  color: var(--text-3);
  font-size: var(--fs-12);
}
.rtn-card-empty a { color: var(--text-1); }

/* Add habit, under a card's rows: a quiet line until it's opened, then a box for a new
   habit and a picker of the ones not yet in a routine. */
.rtn-add { border-top: 1px solid rgba(255, 255, 255, 0.035); }
.rtn-add-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  color: var(--text-3);
  font-size: var(--fs-12);
  cursor: pointer;
  list-style: none;
  transition: color var(--dur-fast) ease;
}
.rtn-add-toggle::-webkit-details-marker { display: none; }
.rtn-add-toggle i { font-size: var(--fs-10); }
.rtn-add-toggle:hover,
.rtn-add[open] .rtn-add-toggle { color: var(--text-1); }
.rtn-add-body { display: flex; flex-direction: column; gap: 8px; padding: 0 16px 14px; }
.rtn-add-form { display: flex; gap: 8px; margin: 0; }
.rtn-add-input {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-1);
  font: inherit;
  font-size: var(--fs-13);
}
.rtn-add-input::placeholder { color: var(--text-3); }
.rtn-add-input:focus { outline: none; border-color: var(--border-strong); }
.rtn-add-submit {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-2);
  font-size: var(--fs-12);
  cursor: pointer;
  transition: color var(--dur-fast) ease, border-color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.rtn-add-submit:hover { color: var(--text-1); border-color: var(--border-strong); background-color: var(--surface-2); }

/* Links and images a routine carries. A link shows its host, not its whole URL — the URL
   was unreadable at this size and was the only thing on the page in another palette. */
.rtn-resources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 10px 16px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.035);
}
.rtn-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-2);
  font-size: var(--fs-11);
  text-decoration: none;
  transition: color var(--dur-fast) ease;
}
.rtn-link i { color: var(--text-3); font-size: var(--fs-9); }
.rtn-link:hover { color: var(--text-1); }
.rtn-link:hover i { color: var(--text-2); }
.rtn-image {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  object-fit: cover;
}

/* Start from a template (routines/_templates): the RoutineTemplates not made yet, a
   tile each, under the cards — or under the empty panel, where the column is narrow
   enough that the grid folds to two across on its own. */
.rtn-templates { margin: 24px 0 14px; }
.rtn-templates-title {
  margin: 0 0 10px; color: var(--text-3); font-size: var(--fs-11); font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
}
/* Two across everywhere: the six templates come out in even rows, where a third column
   left one alone on the last. */
.rtn-templates-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
  margin: 0; padding: 0; list-style: none;
}
.empty-panel-page .rtn-templates { text-align: left; }
.empty-panel-page .rtn-templates-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.rtn-template {
  display: flex; flex-direction: column; gap: 8px; height: 100%; box-sizing: border-box;
  padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background-color: var(--surface-card); background-image: var(--sheen);
  color: var(--text-2); text-decoration: none;
  transition: border-color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.rtn-template:hover { border-color: var(--border-strong); background-color: var(--surface-2); }
.rtn-template-head { display: flex; align-items: center; gap: 8px; }
.rtn-template-icon { color: var(--text-3); font-size: var(--fs-13); width: 1.1em; text-align: center; }
.rtn-template-name { color: var(--text-1); font-size: var(--fs-14); font-weight: 700; }
/* How often it repeats, on its own line under the name. */
.rtn-template-cadence {
  align-self: flex-start; margin-top: -2px; padding: 1px 7px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-3); font-size: var(--fs-10); white-space: nowrap;
}
.rtn-template-habits { flex: 1; color: var(--text-3); font-size: var(--fs-11); line-height: 1.5; }
.rtn-template-use {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--accent-bright); font-size: var(--fs-12); font-weight: 600;
}
.rtn-template-use i { font-size: var(--fs-10); transition: transform var(--dur-fast) ease; }
.rtn-template:hover .rtn-template-use i { transform: translateX(2px); }
/* One someone already has a routine of: still there to use again, but dimmed. */
.rtn-template.is-used { opacity: 0.5; transition: opacity var(--dur-fast) ease, border-color var(--dur-fast) ease, background-color var(--dur-fast) ease; }
.rtn-template.is-used:hover, .rtn-template.is-used:focus-visible { opacity: 0.8; }
.rtn-template.is-used .rtn-template-use { color: var(--text-3); }
.rtn-template.is-used:hover .rtn-template-use i { transform: none; }

/* A template's form (routines/template): a checklist per source of habits — suggested,
   already yours, your own — each row a tick and an editable name. */
.rtn-tpl-body { padding: 16px; max-height: min(64vh, 620px); overflow-y: auto; }
.rtn-tpl-blurb { margin: 0 0 14px; color: var(--text-2); font-size: var(--fs-13); line-height: 1.5; }
.rtn-tpl-label {
  display: block; margin-bottom: 6px; color: var(--text-3); font-size: var(--fs-10);
  font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
}
.rtn-tpl-hint { display: block; margin: -2px 0 8px; color: var(--text-3); font-size: var(--fs-11); }
.rtn-tpl-input, .rtn-tpl-row-input {
  width: 100%; box-sizing: border-box; min-width: 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--recess); color: var(--text-1);
  font: inherit; font-size: var(--fs-13);
}
.rtn-tpl-input { padding: 8px 10px; }
.rtn-tpl-input:focus, .rtn-tpl-row-input:focus { outline: none; border-color: var(--border-strong); }
.rtn-tpl-section { margin-top: 18px; }
.rtn-tpl-list { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.rtn-tpl-list.is-scroll { max-height: 220px; overflow-y: auto; }
.rtn-tpl-row { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.rtn-tpl-check { flex-shrink: 0; width: 15px; height: 15px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.rtn-tpl-row-icon { flex-shrink: 0; width: 15px; color: var(--text-3); font-size: var(--fs-10); text-align: center; }
/* Borderless until touched, so a list of suggestions reads as a list, not a form. */
.rtn-tpl-row-input { flex: 1; padding: 5px 8px; border-color: transparent; background: transparent; }
.rtn-tpl-row-input:hover { border-color: var(--border); }
.rtn-tpl-row-input:focus { background: var(--recess); }
.rtn-tpl-row:has(.rtn-tpl-check:not(:checked)) .rtn-tpl-row-input,
.rtn-tpl-row:has(.rtn-tpl-check:not(:checked)) .rtn-tpl-row-title { color: var(--text-3); }
/* The category a habit will be filed under: its dot and a picker, quiet like the name
   beside it until it's touched (a built-in's is shown, not picked — .is-fixed). A fixed
   width keeps the names in one column down the list. An empty dot is no category. */
.rtn-tpl-cat {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px;
  width: 112px; max-width: 34%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  color: var(--text-3); font-size: var(--fs-11);
}
.rtn-tpl-cat.is-fixed { gap: 9px; } /* lines its name up with a picker's, past the select's border and padding */
.rtn-tpl-cat .rtn-cat-dot { flex-shrink: 0; box-shadow: inset 0 0 0 1px var(--border-strong); }
.rtn-tpl-cat-select {
  flex: 1; min-width: 0; padding: 3px 4px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-3);
  font: inherit; font-size: var(--fs-11); cursor: pointer; text-overflow: ellipsis;
}
.rtn-tpl-cat-select:hover, .rtn-tpl-cat-select:focus { outline: none; border-color: var(--border); background: var(--recess); color: var(--text-2); }
.rtn-tpl-cat-select option { background: var(--surface-2); color: var(--text-1); }
.rtn-tpl-row-title { flex: 1; min-width: 0; padding: 5px 9px; color: var(--text-1); font-size: var(--fs-13); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rtn-tpl-tag {
  flex-shrink: 0; padding: 1px 7px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-3); font-size: var(--fs-10);
}
.rtn-tpl-tag.is-fit { border-color: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--accent-bright); }
.rtn-tpl-tag.is-locked { border-color: color-mix(in srgb, var(--gold-bright) 40%, transparent); color: var(--gold-bright); }
.rtn-tpl-tag.is-locked i { font-size: var(--fs-9); }
.rtn-tpl-add {
  margin-top: 6px; padding: 4px 0; border: none; background: none;
  color: var(--text-3); font: inherit; font-size: var(--fs-12); cursor: pointer;
}
.rtn-tpl-add:hover { color: var(--text-1); }
.rtn-tpl-actions {
  display: flex; justify-content: flex-end; padding: 12px 16px;
  background: var(--recess); border-top: 1px solid var(--border-panel);
}
.rtn-tpl-submit {
  padding: 8px 16px; border: none; border-radius: var(--radius-md);
  background: var(--accent); color: #06130a;
  font: inherit; font-size: var(--fs-13); font-weight: 600; cursor: pointer;
}
.rtn-tpl-submit:hover { background: var(--accent-bright); }

/* The last week of a habit, for a phone (RoutinesHelper#routine_task_recent). */
.rtn-recent { display: none; gap: 4px; }
.rtn-recent-day {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 22px; border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-3); font-size: var(--fs-10); font-weight: 600;
}
.rtn-recent-day.is-kept { color: rgba(0, 0, 0, 0.72); }
.rtn-recent-day.is-off { background: transparent; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06); }
.rtn-recent-day.is-today { outline: 1px solid var(--text-2); outline-offset: 1px; }

@media (max-width: 720px) {
  /* A month of days is wider than the row it would share with the task's name, so on a
     phone the row shows its last week instead. */
  .rtn-row .ledger-strip { display: none; }
  .rtn-row .rtn-recent { display: flex; }
  .rtn-row > .ledger-track { align-items: flex-start; }
  /* Its figure after the week, on the same line (the line it came in has only it left). */
  .rtn-row > .ledger-track:has(.ledger-row-score) { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: 10px; }
  .rtn-row .ledger-row-score { min-width: 0; text-align: left; }
  .rtn-resources { padding: 10px 12px 12px; }
}
@media (max-width: 480px) {
  .rtn-templates-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Uploaded category icons (IconHelper#icon_for). An upload has to occupy exactly
   the space a glyph would, or it changes the height of every row it appears in:
   1em square, contained so a wide logo letterboxes instead of stretching, and
   nudged onto the text baseline the way Font Awesome sits. */
.icon-image {
  width: 1em;
  height: 1em;
  object-fit: contain;
  vertical-align: -0.125em;
  border-radius: 2px;
  flex-shrink: 0;
}

/* An app-drawn mark (IconHelper's "mark:apex"). The svg carries no width or
   height of its own, so the line it sits on has to give it one: 1em tall, width
   from the viewBox, on the text baseline like a glyph. */
.icon-mark {
  height: 1em;
  width: auto;
  vertical-align: -0.125em;
  display: inline-block;
  flex-shrink: 0;
}

/* Inside the round day-item / thing badges the icon is inset slightly so it does
   not touch the rim the way a glyph never does. */
.day-item-icon .icon-image,
.thing-circle .icon-image,
.sidebar-thing-avatar .icon-image {
  width: 0.8em;
  height: 0.8em;
}

.day-item-icon .icon-mark,
.thing-circle .icon-mark,
.sidebar-thing-avatar .icon-mark {
  height: 0.8em;
}

/* A missed day is a wash with an edge rather than a solid block, so a month with some
   misses still reads as mostly kept. */
.rtn-strip .ledger-day.is-missed { box-shadow: inset 0 0 0 1px rgba(220, 53, 69, 0.45); }

/* ---- Routines polish ---- */
/* Today on a habit's strip: an outline round the cell, as the Overall strip and Rules mark
   it, rather than a dot under it that read as a stray pixel. */
.rtn-strip:not(.is-summary) .ledger-day.is-today { box-shadow: 0 0 0 1.5px var(--text-2); }
.rtn-strip:not(.is-summary) .ledger-day.is-today::after { display: none; }
/* The count beside the name: the pencil that shows on hover took its room at rest. */
.rtn-card .rtn-card-edit { display: none; margin-left: 6px; }
.rtn-card .rtn-card-link:hover .rtn-card-edit,
.rtn-card .rtn-card-link:focus-visible .rtn-card-edit { display: inline; }
.rtn-card .ledger-card-head .ledger-card-count { margin-left: 2px; }
@media (max-width: 640px) {
  /* The month switcher smaller and to the right, as on Rules, Values, and Things. */
  .ledger-page.is-routines .ledger-head { flex-wrap: wrap; row-gap: 8px; }
  .ledger-page.is-routines .ledger-head .ledger-month { order: 0; width: auto; margin-left: auto; justify-content: flex-end; }
  .ledger-page.is-routines .ledger-head .ledger-month-label { min-width: 0; padding: 0 6px; font-size: var(--fs-13); }
  .ledger-page.is-routines .ledger-head .ledger-nav-btn { width: 24px; height: 24px; border-color: transparent; }
  /* Today's chip as "0/3", so a long name keeps its line. */
  .rtn-today-count .rtn-today-word, .rtn-today-count .rtn-today-of { display: none; }
  .rtn-today-count strong::after { content: '/'; color: var(--text-3); font-weight: 400; }
}
/* No routines yet: the heading over the panel's left edge. */
.rtn-empty .ledger-head { max-width: 440px; margin-left: auto; margin-right: auto; }
/* The form: the icon as a button beside the name, its presets a panel under the row. */
.rtn-form-namerow { position: relative; display: flex; align-items: stretch; gap: 8px; }
.rtn-form-namerow > .rtn-form-input { flex: 1; min-width: 0; }
.rtn-form-namerow .rtn-icon-picker { flex: 0 0 auto; }
.rtn-form-namerow .rtn-icon-current { margin: 0; height: 100%; }
.rtn-form-namerow .rtn-icon-preview { width: 40px; height: 100%; min-height: 38px; box-sizing: border-box; transition: border-color var(--dur-fast); }
.rtn-form-namerow .rtn-icon-current:hover .rtn-icon-preview,
.rtn-form-namerow .rtn-icon-picker[open] .rtn-icon-preview { border-color: var(--border-strong); }
.rtn-icon-panel {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 20;
  padding: 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface-pop, var(--surface-2)); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
}
/* Custom icon or emoji: a "+" link, as on the Things form, not the browser's triangle. */
.rtn-form-custom > summary { display: inline-flex; align-items: center; gap: 5px; list-style: none; font-size: var(--fs-11); }
.rtn-form-custom > summary::-webkit-details-marker { display: none; }
.rtn-form-custom > summary::before { content: '+'; font-weight: 600; }
.rtn-form-custom[open] > summary::before { content: '−'; }
/* New Routine: the templates as chips. */
.rtn-form-template-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.rtn-form-template-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px;
  border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-2); font-size: var(--fs-12); text-decoration: none;
  transition: border-color var(--dur-fast), color var(--dur-fast);
}
.rtn-form-template-chip i { color: var(--text-3); font-size: var(--fs-11); }
.rtn-form-template-chip:hover { border-color: var(--border-strong); color: var(--text-1); }
.rtn-form-template-chip:hover i { color: var(--accent-bright); }
.rtn-form-template-chip.is-used { opacity: 0.5; }
.rtn-form-template-chip.is-used:hover, .rtn-form-template-chip.is-used:focus-visible { opacity: 0.8; }
/* A template's "Category for all": quiet like the pickers on its rows until touched. */
.rtn-tpl-all-select {
  padding: 3px 4px !important; border: 1px solid transparent !important; border-radius: var(--radius-sm);
  background: transparent !important; color: var(--text-2); font: inherit; font-size: var(--fs-11); cursor: pointer;
}
.rtn-tpl-all-select:hover, .rtn-tpl-all-select:focus { outline: none; border-color: var(--border) !important; background: var(--recess) !important; color: var(--text-1); }

/* A habit's own month after its strip (routine_task_rate); an optional one keeps the room. */
.rtn-row .ledger-row-score.is-blank::before { content: none; }

/* "From a template" lives in the header now; the fold at the foot shows only once opened
   from there (its own summary then closes it). */
body:has(.rtn-templates-head-link) .rtn-templates-fold:not([open]) { display: none; }
