/* Diarity adaptive interface: v6.20+ mobile components and safe-area fixes.
   Loaded after styles.css to preserve historical cascade and desktop layout. */
/* ===== Diarity v6.20: mobile-first app shell =====
   Navigation and safe areas are shared with a future native-app shell.
   Desktop stays untouched. */
.mobile-drawer-backdrop,.mobile-drawer-heading,.mobile-bottom-nav { display:none; }
@media (max-width:900px) {
  :root { --mobile-nav-height: 66px; }
  html { scroll-padding-top:76px; }
  .app-shell { display:block; min-height:100dvh; }
  .main { width:100%; min-width:0; }
  .topbar {
    height:66px; padding:0 18px; gap:10px;
    padding-top:env(safe-area-inset-top,0px);
    height:calc(66px + env(safe-area-inset-top,0px));
    background:color-mix(in srgb,var(--bg) 90%,transparent);
    -webkit-backdrop-filter:blur(22px);backdrop-filter:blur(22px);
  }
  .topbar .mobile-menu { display:none; }
  .topbar .page-heading { min-width:0; margin:0 auto 0 0; }
  .topbar .eyebrow { font-size:9px; margin-bottom:4px; letter-spacing:.08em; }
  .topbar h1 { font-size:clamp(19px,4.5vw,23px); }
  .topbar-actions { gap:7px; flex-shrink:0; }
  .topbar .topbar-tool { min-width:42px;width:42px; height:42px; border-radius:13px; }
  .topbar .help-button,.topbar .theme-toggle { display:none; }
  .topbar .avatar { display:grid; width:41px;height:41px; }
  .content {
    padding:22px clamp(14px,4vw,26px) calc(110px + env(safe-area-inset-bottom,0px));
    max-width:100%; min-width:0;
  }
  .mobile-drawer-backdrop {
    display:block; position:fixed;inset:0; z-index:49;
    background:rgba(10,10,20,.52);
    -webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px);
    animation:fade .16s ease;
    touch-action:none;
  }
  .sidebar {
    position:fixed; inset:0 auto 0 0; z-index:50;
    width:min(352px,88vw); max-width:100%; height:100dvh;
    padding:calc(15px + env(safe-area-inset-top,0px)) 14px calc(16px + env(safe-area-inset-bottom,0px));
    transform:translate3d(-105%,0,0);
    transition:transform .25s cubic-bezier(.2,.8,.2,1);
    box-shadow:none; border-radius:0 22px 22px 0; overflow:hidden;
    overscroll-behavior:contain;
  }
  .sidebar.open { transform:translate3d(0,0,0);box-shadow:20px 0 80px rgba(0,0,0,.26); }
  .sidebar .mobile-drawer-heading { display:flex;align-items:center;justify-content:space-between;padding:0 8px 12px;flex:none;font-size:15px;font-weight:800; }
  .mobile-drawer-close { width:44px;height:44px;display:grid;place-items:center;border:1px solid var(--border);border-radius:14px;background:var(--surface-2);font-size:24px;color:var(--text);cursor:pointer; }
  .sidebar .brand { flex:none;padding:0 8px 18px; }
  .sidebar .nav { flex:1 1 auto; min-height:0;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin;padding:4px 3px 12px;gap:4px; }
  .sidebar .nav-item { min-height:49px;padding:0 13px;font-size:14px;border-radius:13px; }
  .sidebar .nav-icon { width:25px; height:25px;font-size:19px; }
  .sidebar .sidebar-bottom { flex:none;padding-top:12px;border-top:1px solid var(--border-soft);margin-top:0; }
  .sidebar .sidebar-account { min-height:60px; }
  .sidebar .sidebar-account-menu { bottom:calc(76px + env(safe-area-inset-bottom,0px)); }
  .sidebar .nav-overflow-menu { display:none !important; }
  body.mobile-drawer-open { overflow:hidden;touch-action:none; }
  body.mobile-drawer-open .sidebar { touch-action:pan-y; }
  .mobile-bottom-nav {
    display:grid;grid-template-columns:repeat(5,minmax(0,1fr)); align-items:start;
    position:fixed;left:0;right:0;bottom:0;z-index:40;
    min-height:calc(var(--mobile-nav-height) + env(safe-area-inset-bottom,0px));
    padding:5px max(8px,env(safe-area-inset-left,0px)) calc(5px + env(safe-area-inset-bottom,0px)) max(8px,env(safe-area-inset-right,0px));
    background:color-mix(in srgb,var(--sidebar) 94%,transparent);
    border-top:1px solid var(--border-soft);
    box-shadow:0 -10px 36px rgba(0,0,0,.055);
    -webkit-backdrop-filter:blur(20px);backdrop-filter:blur(20px);
  }
  .mobile-bottom-item {
    display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;
    min-height:56px;min-width:0;padding:4px 0;
    border:0;border-radius:13px;background:transparent;color:var(--muted);
    cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent;
    font-family:inherit;font-size:10px;font-weight:660;line-height:1.15;
  }
  .mobile-bottom-item svg {width:23px;height:23px;flex:none;}
  .mobile-bottom-item span:last-child {white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%;}
  .mobile-bottom-item.active {color:var(--accent);}
  .mobile-bottom-item.active:not(.mobile-bottom-add) svg {filter:drop-shadow(0 2px 8px rgba(var(--accent-rgb),.12));}
  .mobile-bottom-item:active:not(.mobile-bottom-add) {background:var(--accent-soft);}
  .mobile-bottom-add { color:var(--text); }
  .mobile-add-icon {display:grid;place-items:center;width:47px;height:47px;min-height:47px;border-radius:16px;background:var(--accent);color:#fff;font-size:32px;font-weight:400;line-height:1;box-shadow:0 7px 22px rgba(var(--accent-rgb),.25);margin-top:-9px;}
  .mobile-bottom-add span:last-child {margin-top:-1px;}
  .mobile-bottom-item:focus-visible,.mobile-drawer-close:focus-visible {outline:3px solid var(--accent);outline-offset:2px;}
  /* Bottom sheets for thumb reach: the content scrolls, the close button stays visible. */
  .modal-backdrop { padding:0;align-items:end;place-items:unset;display:flex;justify-content:center; }
  .modal { width:100%;max-width:none;max-height:calc(94dvh - env(safe-area-inset-top,0px));border-radius:23px 23px 0 0;border-bottom:0;display:flex;flex-direction:column;min-height:0;animation:slide .18s ease; }
  .modal::before { content:"";display:block;width:38px;height:5px;border-radius:999px;background:var(--border);margin:8px auto -2px;flex:none; }
  .modal-head {padding:13px 18px;min-height:58px;flex:none;}
  .modal-head h3 {font-size:16px;}
  .modal-body {overflow-y:auto;overscroll-behavior:contain;min-height:0;max-height:none;flex:1 1 auto;padding:18px 18px calc(24px + env(safe-area-inset-bottom,0px));}
  .modal-close {min-width:44px;min-height:44px;}
  .journal2-modal {width:100%;max-height:calc(94dvh - env(safe-area-inset-top,0px));}
  .journal2-modal .modal-body {max-height:none;overflow-y:auto;padding-bottom:env(safe-area-inset-bottom,0px);}
  .journal2-editor {padding:16px 17px 26px;}
  .journal2-savebar {bottom:0;padding:12px 0 10px;}
  .settings-modal {width:100%;max-height:calc(94dvh - env(safe-area-inset-top,0px));}
  .settings-modal .modal-body {min-height:0;max-height:none;flex:1 1 auto;overflow:hidden;padding:0;}
  .settings-modal .settings-layout {height:100%;min-height:0;max-height:100%;}
  .settings-modal .settings-content {overscroll-behavior:contain;}
  /* Larger, consistent tap targets and no iOS input zoom. */
  .content button,.content .btn,.modal button,.settings-tab {touch-action:manipulation;}
  .content .btn,.modal .btn {min-height:44px;}
  .content .icon-btn,.modal .icon-btn {min-width:42px;min-height:42px;}
  .content input:not([type="checkbox"]):not([type="radio"]),.content textarea,.content select,
  .modal input:not([type="checkbox"]):not([type="radio"]),.modal textarea,.modal select {font-size:16px;max-width:100%;}
  .content .card,.content .dashboard-widget {min-width:0;}
  .page-head {gap:14px;}
  .page-head .actions {width:100%;justify-content:flex-start;}
  .page-head .actions>.btn {flex:0 1 auto;}
  .dashboard-widget-board,.dashboard-widget-board.dashboard-packed {grid-template-columns:minmax(0,1fr) !important;gap:14px;}
  .dashboard-widget-board>[data-dashboard-widget],.dashboard-widget-board.dashboard-packed>[data-dashboard-widget] {grid-column:1 / -1 !important;}
  .dashboard-home-head .actions {flex-wrap:wrap;}
  .dashboard-home-head #quickAdd {display:none;}
  .toast-stack {bottom:calc(79px + env(safe-area-inset-bottom,0px));}
  .calendar-shell,.spreadsheet-scroll,.table-wrap {overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch;}
}
@media (max-width:600px) {
  .content {padding:17px 14px calc(105px + env(safe-area-inset-bottom,0px));}
  .page-head h2,.dashboard-home-head h2 {font-size:clamp(23px,6vw,29px);line-height:1.16;}
  .dashboard-home-head p {font-size:13px;line-height:1.5;}
  .dashboard-widget-board .card-body {padding:15px;}
  .journal2-hero {padding:20px 18px;}
  .journal2-hero>.btn {width:100%;}
  .journal2-section-head {align-items:flex-start;flex-wrap:wrap;}
  .journal2-draft {width:100%;}
  .journal2-savebar .row-actions {width:100%;}
  .journal2-savebar .btn {flex:1 1 auto;}
  .quick-grid {grid-template-columns:repeat(2,minmax(0,1fr));}
  .quick-action {min-width:0;min-height:110px;}
  .module-picker,.customize-layout .module-picker {grid-template-columns:1fr;}
  .content .dashboard-health-kpis,.content .dashboard-finance-kpis {grid-template-columns:1fr;}
}
@media (max-width:360px) {
  .topbar {padding-left:12px;padding-right:12px;gap:6px;}
  .topbar-actions {gap:4px;}
  .topbar .topbar-tool {width:38px;min-width:38px;}
  .topbar .avatar {width:38px;height:38px;}
  .mobile-bottom-nav {padding-left:3px;padding-right:3px;}
  .mobile-bottom-item {font-size:9px;}
  .mobile-bottom-item svg {width:21px;height:21px;}
}
@media (prefers-reduced-motion:reduce) {
  .sidebar,.mobile-drawer-backdrop,.mobile-add-icon,.modal {transition:none;animation:none;}
}
/* A thumb-friendly agenda on phone/tablet rather than a 720px wide desktop calendar. */
.mobile-calendar-view {display:none;}
@media (max-width:900px) {
  .calendar-shell {display:none;}
  .mobile-calendar-view {display:block;min-width:0;}
  .calendar-toolbar {align-items:flex-start;gap:15px;flex-wrap:wrap;}
  .calendar-toolbar h2 {font-size:23px;}
  .calendar-nav {
    width:100%;
    display:grid;
    grid-template-columns:minmax(0,1fr) auto auto;
    align-items:center;
    gap:12px;
  }
  .calendar-nav>.btn {min-height:44px;}
  .calendar-nav>#calToday {
    justify-self:start;
    padding-inline:18px;
  }
  .calendar-nav>#calPrev,
  .calendar-nav>#calNext {
    width:44px;
    min-width:44px;
    padding-inline:0;
    justify-self:end;
  }
  .mobile-calendar-days {display:flex;gap:9px;overflow-x:auto;overscroll-behavior-x:contain;scroll-snap-type:x proximity;-webkit-overflow-scrolling:touch;padding:7px 0 14px;scrollbar-width:none;}
  .mobile-calendar-days::-webkit-scrollbar {display:none;}
  .mobile-calendar-day {width:55px;min-width:55px;min-height:79px;display:flex;flex-direction:column;gap:6px;align-items:center;justify-content:center;border:1px solid var(--border);border-radius:16px;background:var(--surface);color:var(--muted);scroll-snap-align:center;cursor:pointer;}
  .mobile-calendar-day span {font-size:11px;text-transform:capitalize;}
  .mobile-calendar-day b {font-size:19px;line-height:1;}
  .mobile-calendar-day i {width:5px;height:5px;border-radius:50%;background:var(--accent);}
  .mobile-calendar-day.selected {border-color:var(--accent);background:var(--accent-soft);color:var(--text);}
  .mobile-calendar-agenda {border:1px solid var(--border-soft);border-radius:19px;background:var(--surface);min-height:180px;padding:20px 16px;margin-top:5px;}
  .mobile-calendar-agenda h3 {font-size:17px;letter-spacing:-.02em;margin:0 0 17px;text-transform:capitalize;}
  .mobile-agenda-row {width:100%;min-height:58px;padding:12px 8px;border:0;border-top:1px solid var(--border-soft);background:transparent;color:var(--text);display:grid;grid-template-columns:9px minmax(0,1fr) 20px;align-items:center;gap:12px;text-align:left;font-size:14px;cursor:pointer;}
  .mobile-agenda-row b {font-weight:650;overflow-wrap:anywhere;}
  .mobile-agenda-row>span:last-child {color:var(--muted);font-size:20px;}
  .mobile-agenda-dot {width:9px;height:9px;border-radius:50%;background:var(--accent);}
  .mobile-agenda-empty {padding:20px 5px;color:var(--text);}
  .mobile-agenda-empty b {font-size:14px;}
  .mobile-agenda-empty p {font-size:13px;color:var(--muted);line-height:1.5;}
  .settings-modal .settings-layout {grid-template-columns:1fr;}
  .settings-modal .settings-nav {border-right:0;border-bottom:1px solid var(--border-soft);flex-direction:row;overflow-x:auto;padding:10px;flex:none;}
  .settings-modal .settings-tab {width:auto;min-width:max-content;padding:0 12px;}
  .settings-modal .settings-content {padding:17px;min-height:0;}
}
@media(max-width:900px){
 .quick-action {display:block;width:100%;text-align:left;color:var(--text);font:inherit;min-height:104px;}
 .quick-action:focus-visible {outline:3px solid var(--accent);outline-offset:2px;}
 .quick-action .quick-symbol {display:inline-block;min-height:19px;}
 .quick-action small {display:block;}
}
@media(max-width:900px) {
  body.mobile-input-focus .mobile-bottom-nav {transform:translateY(calc(110% + env(safe-area-inset-bottom,0px)));pointer-events:none;}
  .mobile-bottom-nav {transition:transform .15s ease;}
}
@media(prefers-reduced-motion:reduce){.mobile-bottom-nav{transition:none;}}


/* ===== Diarity v6.21 — responsive foundation and finance on phones =====
   Keep this layer after the historical responsive rules. Components may
   scroll *inside their own viewport*; the whole page must not expand. */
.app-shell,.main,.content,#app,.modal,.modal-body,.settings-content {min-width:0;max-width:100%;}
.form-grid,.form-field,.form-grid>*,.money-input-row,.money-input-row>* {min-width:0;max-width:100%;}
.form-field input,.form-field select,.form-field textarea,
.money-input-row input,.money-input-row select {min-inline-size:0;max-inline-size:100%;box-sizing:border-box;}
/* Native date controls have an intrinsic width on iOS Safari. */
.form-field input[type="date"],.form-field input[type="datetime-local"],
.form-field input[type="time"],.form-field input[type="month"] {
  display:block;inline-size:100%;min-inline-size:0;max-inline-size:100%;
  box-sizing:border-box;overflow:hidden;
}
.form-field.full {min-width:0;}
.money-transaction-copy b,.money-transaction-copy span {min-width:0;overflow-wrap:anywhere;}
.money-transaction-amount {overflow-wrap:anywhere;}

@media(max-width:900px) {
  /* Prevent incidental overflowing artwork from enlarging the viewport,
     without disabling deliberate horizontal scrolling in tables or timelines. */
  html,body {max-width:100%;overflow-x:clip;}
  .content>* {min-width:0;max-width:100%;}
  .modal-backdrop {max-width:100vw;overflow:hidden;}
  .modal {min-width:0;max-width:100vw;overflow-x:clip;}
  .modal-body>* {min-width:0;max-width:100%;}
  .modal .form-grid {min-width:0;max-width:100%;}
  .modal .form-field {min-width:0;}
  .money-input-row {grid-template-columns:minmax(0,1fr) minmax(0,132px);}
  .money-filters>* {min-width:0;max-width:100%;}
  .money-goal,.money-goal-head,.money-goal-values,.money-category-row {min-width:0;}
  .money-goal-values {flex-wrap:wrap;overflow-wrap:anywhere;}
  .money-day-head {min-width:0;gap:10px;}
  .money-day-head>div {min-width:0;}
  .money-day-head strong {text-align:right;min-width:0;overflow-wrap:anywhere;}
  .money-day-list {grid-template-columns:minmax(0,1fr);}
  .money-transaction-row:nth-child(odd) {border-right:0;}
  .money-transaction-row:nth-child(2) {border-top:1px solid var(--border-soft);}
  .money-transaction-row {min-width:0;}
  .journal2-editor,.journal2-writing,.journal2-form-meta,
  .settings-layout,.settings-panel,.settings-content {min-width:0;max-width:100%;}
}
@media(max-width:600px) {
  /* Two desktop form columns become a genuine one-column mobile form. */
  .modal .form-grid {grid-template-columns:minmax(0,1fr);gap:14px;}
  .modal .form-grid>.form-field,.modal .form-field.full {grid-column:auto;}
  .modal .form-footer {display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end;}
  .modal .form-footer>.btn {flex:1 1 0;min-width:0;white-space:normal;}
  .modal .form-footer>.btn:only-child {flex:0 1 auto;}
  .modal-body {padding-inline:16px;}
  .money-input-row {grid-template-columns:minmax(0,1fr) minmax(0,116px);gap:8px;}
  .money-page-head {margin-bottom:12px;}
  .money-page-head > div:first-child {display:none;}
  .money-page-head .actions {display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;width:100%;}
  .money-page-head .actions>.btn {width:100%;min-width:0;justify-content:center;white-space:normal;}
  .money-journal-card {min-width:0;}
  .money-journal-head {flex-wrap:wrap;}
  .money-filters {grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;padding:12px;}
  .money-filters>input[name="q"] {grid-column:1/-1;}
  .money-filters select {grid-column:auto;}
  .money-filters button,.money-filters #moneyClearFilters {grid-column:auto;width:100%;}
  .money-filters button[type="submit"]:last-child {grid-column:1/-1;}
  .money-day-head {padding:10px 12px;align-items:center;}
  .money-day-head>div {display:flex;flex-wrap:wrap;gap:2px 7px;align-items:baseline;}
  .money-day-head b {font-size:13px;}
  .money-day-head strong {font-size:11px;}
  .money-day-list {display:grid;grid-template-columns:minmax(0,1fr);}
  /* Two concise lines instead of the former four-row desktop-table layout:
       [category / description] [edit/delete]
       [income/expense badge]   [amount]
     Both actions stay visible and have proper touch targets. */
  .money-transaction-row {
    display:grid;
    grid-template-columns:minmax(0,1fr) auto;
    grid-template-rows:auto auto;
    grid-template-areas:"details actions" "type amount";
    align-items:center;
    column-gap:8px;row-gap:7px;
    padding:10px 12px;
    min-height:0;
  }
  .money-transaction-copy {grid-area:details;grid-column:auto;grid-row:auto;gap:2px;align-self:center;}
  .money-transaction-copy b {font-size:13px;font-weight:750;line-height:1.3;white-space:normal;overflow-wrap:anywhere;}
  .money-transaction-copy span {font-size:11px;line-height:1.3;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
  .money-transaction-type {grid-area:type;grid-column:auto;grid-row:auto;align-self:center;}
  .money-transaction-type .type-pill {padding:4px 8px;line-height:1.3;}
  .money-transaction-amount {
    grid-area:amount;grid-column:auto;grid-row:auto;
    text-align:right;font-size:13px;line-height:1.25;
    font-variant-numeric:tabular-nums;white-space:normal;
  }
  .money-transaction-amount .money-original {margin-top:2px;white-space:normal;font-size:10px;}
  .money-transaction-row .row-actions {grid-area:actions;grid-column:auto;grid-row:auto;justify-content:flex-end;gap:2px;}
  .money-transaction-row .row-actions .icon-btn {
    width:40px;min-width:40px;height:40px;min-height:40px;
    padding:0;border-radius:10px;
  }
  /* Keep the monthly overview readable without four tall metric cards. */
  .money-metrics {grid-template-columns:repeat(2,minmax(0,1fr));gap:9px;margin-bottom:12px;}
  .money-metrics .metric {min-height:0;padding:12px;}
  .money-metrics .metric-top {font-size:11px;gap:5px;}
  .money-metrics .metric-icon {width:27px;height:27px;flex:none;}
  .money-metrics .metric-value {font-size:clamp(15px,4.5vw,22px);margin-top:10px;white-space:normal;overflow-wrap:anywhere;}
  .money-metrics .metric-foot {font-size:10px;margin-top:3px;line-height:1.35;}
  .money-period {margin-bottom:12px;}
  .money-overview-grid,.money-analysis-grid {gap:12px;margin-bottom:12px;}
  .money-goals-card {margin-bottom:12px;}
  .money-load-more {gap:6px;padding:12px;}
  .money-load-more .btn {width:100%;}
  /* Long native values (including localised dates) should wrap, not push the app. */
  .settings-panel-head,.page-head,.card-head {min-width:0;}
  .settings-panel-head>* {min-width:0;}
}
@media(max-width:360px) {
  .money-transaction-row {padding-inline:10px;column-gap:5px;}
  .money-transaction-row .row-actions .icon-btn {width:36px;min-width:36px;height:40px;min-height:40px;}
  .money-input-row {grid-template-columns:minmax(0,1fr) minmax(0,103px);}
  .money-day-head strong {max-width:45%;}
}


/* ===== Diarity 6.21.1 — actual mobile finance rows, not desktop grid remnants =====
   A finance entry uses two small rows on phones. Keep this final, mobile-only
   layer after the v6.21 responsiveness block. */
@media (max-width:600px) {
  .money-journal-card .money-journal-head {padding:11px 13px;gap:8px;align-items:center;}
  .money-journal-head .card-title {font-size:15px;}
  .money-journal-head .card-subtitle {display:none;}
  .money-journal-head #exportMoney {padding-inline:11px;min-height:36px;}
  .money-metrics .metric-foot {display:none;}
  .money-metrics .metric-value {margin-top:7px;}
  .money-journal-card .money-filters {
    display:grid;
    grid-template-columns:minmax(0,1fr) auto;
    gap:7px;
    padding:10px 12px;
    align-items:stretch;
  }
  .money-journal-card .money-filters>input[name="q"] {grid-area:1/1/2/2;width:100%;min-width:0;}
  .money-journal-card .money-filters>select[name="type"] {grid-area:2/1/3/2;width:100%;min-width:0;}
  .money-journal-card .money-filters>select[name="category"] {grid-area:2/2/3/3;width:100%;min-width:0;max-width:min(45vw,190px);}
  .money-journal-card .money-filters>button[type="submit"] {grid-area:1/2/2/3;width:auto;min-width:68px;padding-inline:12px;}
  .money-journal-card .money-filters>#moneyClearFilters {grid-area:3/1/4/3;width:100%;}
  .money-journal-card .money-filters>input,.money-journal-card .money-filters>select,
  .money-journal-card .money-filters>button {margin:0;min-height:39px;max-width:100%;}
  .money-journal-card .money-day-head {padding:9px 12px;align-items:center;min-height:40px;}
  .money-journal-card .money-day-head>div {display:flex;align-items:baseline;gap:6px;flex-wrap:wrap;}
  .money-journal-card .money-day-head b {font-size:12px;}
  .money-journal-card .money-day-head span {font-size:10px;}
  .money-journal-card .money-day-head strong {font-size:11px;}
  .money-journal-card .money-day-list {display:grid;grid-template-columns:minmax(0,1fr);}
  .money-journal-card .money-transaction-row {
    display:grid;
    grid-template-columns:minmax(0,1fr) auto;
    grid-template-rows:auto auto;
    grid-template-areas:"name value" "kind controls";
    column-gap:8px;
    row-gap:1px;
    padding:7px 12px;
    min-width:0;
    min-height:0;
    align-items:center;
    border-top:1px solid var(--border-soft);
  }
  .money-journal-card .money-transaction-row:first-child {border-top:0;}
  .money-journal-card .money-transaction-copy {grid-area:name;min-width:0;min-height:0;display:grid;gap:2px;align-self:center;}
  .money-journal-card .money-transaction-copy b {font-size:13px;line-height:1.3;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
  .money-journal-card .money-transaction-copy span {font-size:11px;line-height:1.25;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
  .money-journal-card .money-transaction-amount {
    grid-area:value;
    min-width:0;
    max-width:min(54vw,210px);
    text-align:right;
    font-size:13px;
    line-height:1.25;
    font-weight:750;
    white-space:normal;
    justify-self:end;
    align-self:center;
  }
  .money-journal-card .money-transaction-amount .money-original {font-size:10px;line-height:1.3;}
  .money-journal-card .money-transaction-type {grid-area:kind;min-width:0;justify-self:start;align-self:center;}
  .money-journal-card .money-transaction-type .type-pill {font-size:10px;padding:3px 7px;}
  .money-journal-card .money-transaction-row .row-actions {
    grid-area:controls;
    display:flex;
    justify-content:flex-end;
    gap:3px;
    margin:0;
    min-width:0;
  }
  .money-journal-card .money-transaction-row .row-actions .icon-btn {
    display:grid;place-items:center;
    width:40px;min-width:40px;height:40px;min-height:40px;
    padding:0;line-height:1;border-radius:9px;font-size:17px;
  }
  .money-journal-card .money-transaction-row .row-actions .icon-btn:focus-visible {outline-offset:0;}
}
@media (max-width:360px) {
  .money-journal-card .money-transaction-row {padding-inline:10px;column-gap:5px;}
  .money-journal-card .money-transaction-amount {font-size:12px;max-width:54vw;}
  .money-journal-card .money-transaction-copy b {font-size:12px;}
}


/* ===== Diarity 6.21.2 — meaningful mobile density: quick add / health / budget ===== */
/* The quick-entry sheet sizes itself to its actions, instead of inheriting
   a full-height scrollable form body. Other form dialogs keep their scroll. */
.quick-add-modal .quick-add-intro {
  margin:0 0 12px;color:var(--muted);font-size:12px;line-height:1.45;
}
.quick-add-modal .quick-action {
  display:grid;grid-template-columns:39px minmax(0,1fr);
  grid-template-rows:auto auto;column-gap:11px;align-content:center;
  align-items:center;min-height:70px;padding:10px 12px;text-align:left;
  color:var(--text);border-radius:13px;
}
.quick-add-modal .quick-action .quick-symbol {
  grid-column:1;grid-row:1/3;display:grid;place-items:center;
  width:39px;height:39px;min-height:39px;
  border-radius:12px;background:var(--accent-soft);color:var(--accent);
  font-size:19px;font-weight:650;
}
.quick-add-modal .quick-action b {
  grid-column:2;grid-row:1;margin:0;
  font-size:13px;line-height:1.35;
}
.quick-add-modal .quick-action small {
  grid-column:2;grid-row:2;display:block;min-width:0;
  font-size:11px;line-height:1.35;overflow:hidden;text-overflow:ellipsis;
  white-space:nowrap;
}
@media (max-width:900px) {
  /* Target only quick add: the legacy `place-items:unset` shorthand on the
     backdrop otherwise resets align-items and leaves small sheets at the top. */
  .modal-backdrop.quick-add-backdrop {align-items:flex-end;}
  /* Quick add: a true compact bottom sheet. It still scrolls if many
     optional modules are enabled or the device has a short viewport. */
  .modal.quick-add-modal {
    /* max-content stops the backdrop flex cross-size from stretching the sheet
       to max-height even when there are only a few shortcuts. */
    height:max-content;min-height:0;flex:0 1 auto;
    max-height:min(85dvh,670px);
  }
  .quick-add-modal .modal-body {
    flex:0 1 auto;min-height:0;overflow-y:auto;
    padding:13px 16px calc(17px + env(safe-area-inset-bottom,0px));
  }
  .quick-add-modal .quick-grid {
    display:grid;grid-template-columns:minmax(0,1fr);gap:8px;
  }
  .quick-add-modal .quick-action {min-height:61px;padding:8px 12px;}
  .quick-add-modal .quick-add-intro {margin-bottom:10px;}

}
@media (max-width:600px) {
  /* Empty budget: never reserve chart-sized space for absent data. */
  .money-budget-card.budget-unset {min-height:0;}
  .money-budget-card.budget-unset .card-head {
    padding:12px 14px;min-height:0;gap:10px;align-items:center;
  }
  .money-budget-card.budget-unset .card-head>div:first-child {
    flex:1 1 auto;min-width:0;
  }
  .money-budget-card.budget-unset .card-title {font-size:15px;}
  .money-budget-card.budget-unset .card-subtitle {
    font-size:11px;line-height:1.3;margin-top:4px;
  }
  .money-budget-card.budget-unset .card-head .btn {
    flex:0 0 auto;min-height:38px;padding:0 11px;
  }
  .money-budget-card.budget-unset .money-budget-empty {
    display:grid;place-content:start;min-height:0;gap:3px;
    padding:11px 14px 14px;text-align:left;
    border-top:0;
  }
  .money-budget-card.budget-unset .money-budget-empty b {font-size:12px;}
  .money-budget-card.budget-unset .money-budget-empty span {
    font-size:11px;line-height:1.4;max-width:none;
  }

  /* Health summary: four KPIs in 2 × 2, not four tall full-width tiles. */
  .content .health-metrics {
    display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:9px;
    margin-bottom:12px;
  }
  .content .health-metrics .metric {
    display:flex;flex-direction:column;justify-content:space-between;
    padding:11px;min-height:106px;min-width:0;
  }
  .health-metrics .metric-top {font-size:11px;gap:4px;line-height:1.3;}
  .health-metrics .metric-icon {
    width:26px;height:26px;min-width:26px;font-size:12px;
  }
  .content .health-metrics .metric-value {
    margin-top:5px;font-size:clamp(16px,4.6vw,21px);
    line-height:1.15;white-space:normal;overflow-wrap:anywhere;
  }
  .content .health-metrics .health-macro-value {font-size:clamp(12px,3.4vw,16px);}
  .health-metrics .metric-foot {margin-top:5px;font-size:10px;line-height:1.25;}
  .health-layout-main,.health-secondary-grid {gap:12px;margin-bottom:12px;}

  /* Body estimates should make one 2 × 2 panel, not four stacked panels. */
  .content .health-estimates {
    grid-template-columns:repeat(2,minmax(0,1fr));gap:9px;
  }
  .health-estimates .info-box {
    display:flex;flex-direction:column;justify-content:center;min-width:0;
    padding:10px 11px;min-height:70px;gap:4px;
  }
  .health-estimates .info-box b {
    margin:0;font-size:clamp(13px,3.9vw,17px);line-height:1.25;
    overflow-wrap:anywhere;
  }
  .health-estimates .info-box span {font-size:10px;line-height:1.3;}
  .health-secondary-grid .card-head {
    min-height:0;padding:12px 14px;gap:10px;flex-wrap:wrap;
  }
  .health-secondary-grid .card-head>div:first-child {
    flex:1 1 155px;min-width:0;
  }
  .health-secondary-grid .card-head .btn {
    margin-left:auto;flex:0 0 auto;min-height:38px;padding:7px 10px;
    font-size:11px;white-space:normal;text-align:center;
  }
  .health-secondary-grid .card-body {padding:12px 14px;}
  .health-layout-main .card-head {padding:12px 14px;min-height:0;}
  .health-layout-main .card-body {padding:14px;}
  .health-history-card .card-head {padding:12px 14px;min-height:0;}
  .health-goals-list {gap:11px;}
}
@media (max-width:360px) {
  .content .health-metrics .metric {min-height:102px;padding:9px;}
  .health-estimates .info-box {padding:9px;}
  .health-secondary-grid .card-head>div:first-child {flex-basis:125px;}
  .money-budget-card.budget-unset .card-head {gap:8px;}
}


/* ===== Diarity 6.21.3 — mobile modal width and money section spacing ===== */
/* iPhone Safari gives native date fields a stubborn intrinsic width. Keep
   modal forms clipped to the viewport and let inputs shrink correctly. */
.modal form,.modal form > div,.modal .form-grid,.modal .form-grid > .form-field,
.modal .form-field > label { min-width:0; max-width:100%; }
.modal .form-field > label { display:block; }
.modal .form-field input,.modal .form-field select,.modal .form-field textarea,
.modal .input { min-width:0; max-width:100%; }
.modal input[type="date"],.modal input[type="datetime-local"],
.modal input[type="time"],.modal input[type="month"] {
  min-width:0; max-width:100%; inline-size:100%; width:100%;
}
@media (max-width:600px) {
  .modal-backdrop { padding:8px; }
  .modal {
    width:min(580px,calc(100vw - 16px));
    max-width:calc(100vw - 16px);
  }
  .modal-body {
    overflow-x:hidden;
    overscroll-behavior-x:contain;
  }
  /* When the finance journal is moved upward on phones, restore a clear
     block gap before the budget / analysis groups that follow it. */
  .money-journal-card { margin-bottom:12px; }
  .money-journal-card + .money-overview-grid,
  .money-overview-grid + .money-analysis-grid,
  .money-analysis-grid + .money-goals-card,
  .money-goals-card + .fx-attribution,
  .fx-attribution + .money-journal-card { margin-top:0; }
}
@media (max-width:360px) {
  .modal {
    width:min(580px,calc(100vw - 12px));
    max-width:calc(100vw - 12px);
  }
  .modal-backdrop { padding:6px; }
}


/* ===== Diarity v6.21.4 — iOS date picker frame: no painted border overflow =====
   The visible frame belongs to the wrapper. The original native date input is
   still active, in the form and receives taps, but cannot paint beyond it. */
.modal-date-control { display:block; position:relative; inline-size:100%; min-inline-size:0; }
.modal-date-display,.modal-date-icon { display:none; }
@media(max-width:900px) {
  .modal .modal-date-control {
    position:relative; isolation:isolate;
    display:flex; align-items:center; justify-content:center;
    box-sizing:border-box; inline-size:100%; width:100%; max-width:100%;
    min-inline-size:0; height:48px; padding:0 42px;
    border:1px solid var(--border); border-radius:10px;
    background:var(--input-bg); color:var(--text);
    overflow:hidden; flex:none;
  }
  .modal .modal-date-display {
    display:block; font-size:16px; font-weight:450; line-height:1.2;
    white-space:nowrap; text-overflow:ellipsis; overflow:hidden;
    text-align:center; max-width:100%; pointer-events:none;
  }
  .modal .modal-date-control.is-empty .modal-date-display { color:var(--muted-2); }
  .modal .modal-date-icon {
    display:block; position:absolute; right:14px; top:50%; transform:translateY(-50%);
    color:var(--muted-2); font-size:18px; line-height:1; pointer-events:none;
  }
  .modal .modal-date-control:focus-within {
    border-color:var(--accent); box-shadow:0 0 0 3px rgba(var(--accent-rgb),.10);
  }
  .modal .modal-date-control > input[type="date"] {
    /* Absolute positioning prevents the iOS intrinsic control width from
       participating in layout; the frame draws the only visible border. */
    position:absolute!important; inset:0!important;
    display:block!important; inline-size:100%!important;
    block-size:100%!important; width:100%!important; height:100%!important;
    min-inline-size:0!important; min-width:0!important;
    max-inline-size:none!important; margin:0!important; padding:0!important;
    box-sizing:border-box!important;
    opacity:0!important; z-index:2; cursor:pointer;
  }
}


/* ===== Diarity v6.21.5 — compact Daily Health entry on phones =====
   Only this form changes; other dialogs and desktop forms retain their layout.
   Group closely related values without sacrificing 44px tap targets. */
@media (max-width:600px) {
  .modal #healthForm .health-entry-grid {
    display:grid; grid-template-columns:repeat(6,minmax(0,1fr));
    gap:11px 9px; align-items:start;
  }
  .modal #healthForm .health-entry-grid>.form-field {
    grid-column:auto; min-width:0; gap:5px;
  }
  .modal #healthForm .health-entry-date {grid-column:1 / -1!important;}
  .modal #healthForm .health-entry-weight,
  .modal #healthForm .health-entry-calories {grid-column:span 3!important;}
  .modal #healthForm .health-entry-protein,
  .modal #healthForm .health-entry-fat,
  .modal #healthForm .health-entry-carbs {grid-column:span 2!important;}
  .modal #healthForm .health-entry-steps,
  .modal #healthForm .health-entry-note,
  .modal #healthForm .health-macro-calc {grid-column:1 / -1!important;}
  .modal #healthForm .health-entry-grid label {
    font-size:12px; line-height:1.25; min-height:15px;
    overflow-wrap:normal;
  }
  .modal #healthForm .health-entry-grid .input {
    min-width:0; height:46px; padding:9px 10px; font-size:16px;
  }
  .modal #healthForm .health-entry-grid .modal-date-control {height:46px;}
  .modal #healthForm .health-entry-note textarea {
    min-height:66px; height:66px; padding:11px 12px; font-size:16px;
  }
  .modal #healthForm .health-macro-calc {
    min-height:0; padding:10px 12px; gap:3px 8px;
    grid-template-columns:max-content minmax(0,1fr);
    align-items:center;
  }
  .modal #healthForm .health-macro-calc span {font-size:10px;}
  .modal #healthForm .health-macro-calc b {font-size:13px;text-align:right;}
  .modal #healthForm .health-macro-calc small {
    grid-column:1 / -1; line-height:1.35;
  }
  .modal #healthForm .form-footer {margin-top:12px;gap:9px;}
  .modal #healthForm .form-footer .btn {min-height:46px;}
}
@media (max-width:359px) {
  .modal #healthForm .health-entry-grid {column-gap:6px;}
  .modal #healthForm .health-entry-grid label {font-size:11px;}
  .modal #healthForm .health-entry-grid .input {padding-inline:8px;}
}

/* A compact Health entry must size its bottom sheet to its CONTENT.
   Legacy modal styles otherwise stretch the sheet to 94dvh and leave
   a large empty area below Save, even when the form has few rows. */
@media (max-width:900px) {
  .modal-backdrop.health-entry-backdrop {align-items:flex-end;}
  .modal.health-entry-modal {
    height:max-content;min-height:0;flex:0 1 auto;
    max-height:calc(94dvh - env(safe-area-inset-top,0px));
  }
  .health-entry-modal .modal-body {
    flex:0 1 auto;min-height:0;overflow-y:auto;
  }
}

/* ===== Diarity v6.21.6 — keep the document still behind open dialogs ===== */
.modal-backdrop { overscroll-behavior: none; }
.modal-backdrop .modal-body, .modal-backdrop .settings-content {
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

/* v6.22: keyboard access and comfortable touch targets. These enhance
   the existing controls without changing the Finance/Health grid tracks. */
:where(button, a[href], input, select, textarea, [tabindex="0"]):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
@media (pointer: coarse) {
  .content .icon-btn, .modal .icon-btn,
  .money-journal-card .money-transaction-row .row-actions .icon-btn {
    min-inline-size: 44px;
    min-block-size: 44px;
  }
}
@media (max-width: 900px) {
  html { scroll-padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px)); }
  .content :is(h1, h2, h3, [id]) { scroll-margin-top: 90px; }
}
@media (prefers-reduced-motion: reduce) {
  :where(.content, .modal) *, .mobile-bottom-nav {
    scroll-behavior: auto !important;
  }
}


/* ===== Diarity 6.23 — Mobile form consistency and resilient content =====
   Scoped mobile rules only: preserve desktop grid and long-form journal editor. */
@media (max-width:600px) {
  /* Plain CRUD sheets need less chrome, not smaller touch targets. */
  .modal:not(.settings-modal):not(.journal2-modal):not(.quick-add-modal):not(.health-entry-modal) .modal-body {
    padding:14px 14px calc(18px + env(safe-area-inset-bottom, 0px));
  }
  .modal:not(.settings-modal):not(.journal2-modal):not(.quick-add-modal):not(.health-entry-modal) .form-grid {gap:11px;}
  .modal:not(.settings-modal):not(.journal2-modal):not(.quick-add-modal):not(.health-entry-modal) .form-field {gap:6px;min-width:0;}
  .modal:not(.settings-modal):not(.journal2-modal):not(.quick-add-modal):not(.health-entry-modal) .form-field > label {
    font-size:12px;line-height:1.4;
  }
  .modal:not(.settings-modal):not(.journal2-modal):not(.quick-add-modal):not(.health-entry-modal) .form-footer {margin-top:14px;}
  .modal:not(.settings-modal):not(.journal2-modal):not(.quick-add-modal):not(.health-entry-modal) .form-footer .btn {
    min-height:44px;
  }
  /* For shorter task/habit notes the default desktop textarea is wasteful.
     The journal itself stays a full writing surface. */
  #taskForm textarea[name="details"],
  #habitForm textarea[name="description"],
  #goalForm textarea[name="description"] {min-height:74px;}
  /* An icon and a name belong on one line; descriptions stay full width. */
  #habitForm .form-grid {display:grid;grid-template-columns:78px minmax(0,1fr);}
  #habitForm .form-grid>.form-field:not(.full):first-child {grid-column:1;}
  #habitForm .form-grid>.form-field:not(.full):nth-child(2) {grid-column:2;}
  #habitForm .form-grid>.full {grid-column:1 / -1;}
  /* The same icon/name pair is used by custom trackers. */
  #trackerForm .form-grid {display:grid;grid-template-columns:78px minmax(0,1fr);}
  #trackerForm .form-grid>.form-field:first-child {grid-column:2;grid-row:1;}
  #trackerForm .form-grid>.form-field:nth-child(2) {grid-column:1;grid-row:1;}
  #trackerForm .form-grid>.form-field:not(:first-child):not(:nth-child(2)),
  #trackerForm .form-grid>.full {grid-column:1 / -1;}
  .content .page-head h2, .content .card-title,
  .content .card-subtitle, .content .goal-card h3,
  .content .habit-card h3 {overflow-wrap:anywhere;}
  .modal :is(input,textarea,select) {scroll-margin-block:24px;}
  .modal .modal-date-control {scroll-margin-block:24px;}
}
@media (max-width:360px) {
  /* Long localised labels must never crush narrow 320px icon/name rows. */
  #habitForm .form-grid, #trackerForm .form-grid {
    grid-template-columns:64px minmax(0,1fr);
  }
}

@media (max-width:360px) {
  .calendar-nav {gap:10px;}
  .calendar-nav>#calToday {padding-inline:15px;}
}

/* v6.29: Admin-only operational summaries; no user content. */
.admin-metrics-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px;padding:var(--card-block) var(--card-inline);}
.admin-metrics-grid>div{min-width:0;padding:12px;border:1px solid var(--border-soft);border-radius:12px;background:var(--surface-2);display:grid;gap:8px;}
.admin-metrics-grid span{font-size:11px;color:var(--muted);overflow-wrap:anywhere;}
.admin-metrics-grid b{font-size:17px;overflow-wrap:anywhere;}
.release-history-summary{color:var(--muted);line-height:1.55;margin:0;}
@media(max-width:900px){.admin-metrics-grid{grid-template-columns:repeat(2,minmax(0,1fr));}}
@media(max-width:360px){.admin-metrics-grid{gap:8px;}}

/* v6.47.1: consistent task/note/habit/goal editors only. */
.everyday-form{min-width:0;}
.everyday-form .form-grid{align-items:start;}
.everyday-form .form-field{min-width:0;}
.everyday-form .form-field>label{font-weight:650;line-height:1.45;}
.everyday-form .form-field :is(input,select,textarea){width:100%;min-width:0;}
.everyday-form .form-footer{position:sticky;bottom:0;z-index:2;
  margin-top:18px;padding:12px 0 max(10px,env(safe-area-inset-bottom,0px));
  background:var(--surface);border-top:1px solid var(--border-soft);}
@media(max-width:520px){
  .everyday-form .form-grid{gap:12px;}
  .everyday-form .form-footer{gap:10px;}
  .everyday-form .form-footer>.btn{min-height:46px;}
}

@media(max-width:760px){.journal2-savebar #journalRetryDraft:not([hidden]){flex-basis:100%}}
