/* Actum Forge — shared components: buttons, dialogs, form fields.
   Loaded on every page before the page stylesheet, so a page only keeps what is really its own.
   A page changes the colour of all of them at once through the accent tokens:

       :root { --accent: #8F6BFD; --accent-rgb: 143, 107, 253; --accent-text: #C6BDFB; --accent-hot: #EBE8FE; }

   Dialogs also get the stone surface from static/core/forge-fx (.forge-surface). */

:root {
    --accent: #FF6A1A;
    --accent-rgb: 255, 106, 26;
    --accent-text: #FFB070;
    --accent-hot: #FFE6C2;
}

/* ---------- buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #d7d9de;
    font: inherit;
    font-weight: 900;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.btn:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.09);
}

.btn:disabled {
    opacity: 0.5;
    cursor: default;
}

/* the main action: dark body, hot accent border, warm text */
.btn-primary {
    border-color: var(--accent);
    background: rgba(22, 13, 8, 0.85);
    color: var(--accent-text);
    box-shadow: 0 0 18px rgba(var(--accent-rgb), 0.18), inset 0 0 14px rgba(var(--accent-rgb), 0.08);
}

.btn-primary:hover {
    border-color: var(--accent-text);
    background: rgba(36, 20, 10, 0.92);
    color: var(--accent-hot);
    box-shadow: 0 0 26px rgba(var(--accent-rgb), 0.32), inset 0 0 18px rgba(var(--accent-rgb), 0.14);
}

.btn-danger {
    border-color: rgba(239, 68, 68, 0.4);
    background: rgba(239, 68, 68, 0.1);
    color: #ff9b9b;
}

.btn-danger:hover {
    border-color: rgba(239, 68, 68, 0.6);
    background: rgba(239, 68, 68, 0.2);
}

/* a button that stays pressed (settings mode, a shown panel…): ember wash and a thin hot frame */
.btn.is-active,
.btn.active,
.btn[aria-pressed="true"] {
    border-color: rgba(var(--accent-rgb), 0.5);
    background: rgba(var(--accent-rgb), 0.1);
    color: var(--accent-text);
    box-shadow: inset 0 0 16px rgba(var(--accent-rgb), 0.08);
}

/* square button with a single icon or symbol */
.btn-icon {
    width: 42px;
    padding: 0;
    font-size: 20px;
    line-height: 1;
}

/* ---------- page head: a card with the eyebrow, the title, a line of text and actions on the right ---------- */

.page-titlebar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 18px;
}

/* the text gives way first, so the actions stay on the right until the page is really narrow */
.page-titlebar > :first-child {
    flex: 1 1 320px;
    min-width: 0;
}

.page-titlebar h1 {
    margin: 0 0 8px;
    font-size: clamp(26px, 5vw, 32px);
    line-height: 1.05;
}

.page-titlebar p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.page-titlebar .eyebrow {
    margin: 0 0 7px;
}

/* the small caps line above a title — of a page, a panel or a dialog */
.eyebrow {
    display: block;
    margin: 0 0 7px;
    color: var(--accent-text);
    font-size: 11.5px;
    font-weight: 900;
    letter-spacing: 2.5px;
    text-transform: uppercase;
}

/* ---------- tabs ----------
   .tabs > .tab — a row of separate tabs (periods, days, categories).
   .segmented > .tab — the same tabs inside one frame (a switch between two-four views).
   The selected tab: .is-active, .active or aria-selected="true". */

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 40px;
    padding: 0 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.04);
    color: #c8cbd3;
    font: inherit;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.tab:hover {
    border-color: rgba(var(--accent-rgb), 0.35);
    color: #fff;
}

.tab.is-active,
.tab.active,
.tab[aria-selected="true"] {
    border-color: rgba(var(--accent-rgb), 0.5);
    background: rgba(var(--accent-rgb), 0.1);
    color: var(--accent-text);
    box-shadow: inset 0 0 16px rgba(var(--accent-rgb), 0.08);
}

.segmented {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.18);
}

.segmented > .tab {
    flex: 1;
    min-height: 34px;
    border-color: transparent;
    border-radius: 9px;
    background: transparent;
}

.segmented > .tab:hover {
    background: rgba(255, 255, 255, 0.06);
}

.segmented > .tab.is-active,
.segmented > .tab.active,
.segmented > .tab[aria-selected="true"] {
    border-color: rgba(var(--accent-rgb), 0.5);
    background: rgba(var(--accent-rgb), 0.1);
}

/* ---------- dialogs ---------- */

.dialog {
    width: min(var(--dialog-width, 520px), calc(100vw - 36px));
    max-height: calc(100dvh - 48px);
    overflow-y: auto;
    padding: 0;
    border: 1px solid rgba(var(--accent-rgb), 0.33);
    border-radius: 18px;
    background: #12141a;
    color: var(--text);
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.55);
}

.dialog::backdrop {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
}

.dialog [hidden] {
    display: none !important;
}

.dialog-body {
    display: grid;
    gap: 15px;
    padding: 22px;
}

.dialog h2,
.modal-card h2 {
    margin: 0;
    font-size: 24px;
}

/* a dialog's head: the title (or a date) on the left, close and other tools in the top right corner */
.dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.dialog-head > .dialog-close,
.dialog-head > .dialog-head-tools {
    margin-left: auto;
}

/* the square buttons of a dialog head: close, help… */
.dialog-close {
    flex: none;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #e4e6ea;
    font: inherit;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.dialog-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.dialog-head-tools {
    display: flex;
    gap: 6px;
}

.dialog-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.dialog-actions .btn {
    min-width: 120px;
}

.dialog-actions .btn-icon {
    flex: none;
    min-width: 0;
}

/* a destructive button leading the row sits on the far left, away from "Сохранить" */
.dialog-actions > .btn-danger:first-child {
    margin-right: auto;
}

/* pushes the buttons after it to the right edge (delete on the left, save on the right) */
.dialog-spacer {
    flex: 1;
}

/* the app's confirm / alert / prompt (static/core/JS/dialogs.js) — a small .dialog */
.app-dialog {
    --dialog-width: 460px;
}

.app-dialog h2 {
    font-size: 20px;
}

.app-dialog-text {
    margin: 0;
    color: #d7d9de;
    line-height: 1.55;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

/* ---------- div modals: .modal.is-open > .modal-backdrop + .modal-card ----------
   For pages that open their windows with a class instead of <dialog>.
   Same look as .dialog; the card carries its own padding. */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: none;
    place-items: center;
    padding: 24px;
}

.modal.is-open {
    display: grid;
}

body:has(.modal.is-open) {
    overflow: hidden;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
}

.modal-card {
    position: relative;
    z-index: 1;
    width: min(var(--dialog-width, 520px), calc(100vw - 48px));
    max-height: calc(100dvh - 48px);
    overflow: auto;
    overscroll-behavior: contain;
    padding: 22px;
    border: 1px solid rgba(var(--accent-rgb), 0.33);
    border-radius: 18px;
    background: #12141a;
    color: var(--text);
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.55);
}

.modal-card > .dialog-head {
    align-items: flex-start;
    margin-bottom: 18px;
}

.modal-card .dialog-actions {
    margin-top: 20px;
}

/* ---------- form fields ----------
   Inside a .dialog / .modal-card the text fields and the labels are styled on their own;
   :where() keeps that light, so any page rule still wins. */

.field,
:where(.dialog-body, .modal-card) :where(label) {
    display: grid;
    gap: 7px;
    color: #cfd2d8;
    font-weight: 800;
}

.input,
.dialog :where(input:not([type="checkbox"], [type="radio"], [type="color"], [type="file"], [type="range"], [type="hidden"]), select, textarea),
.modal-card :where(input:not([type="checkbox"], [type="radio"], [type="color"], [type="file"], [type="range"], [type="hidden"]), select, textarea) {
    width: 100%;
    min-width: 0;
    padding: 13px 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    outline: none;
    background: rgba(0, 0, 0, 0.28);
    color: var(--text);
    color-scheme: dark;
    font: inherit;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.input::placeholder,
.dialog :where(input, textarea)::placeholder,
.modal-card :where(input, textarea)::placeholder {
    color: #8e96a7;
}

.input:focus,
.dialog :where(input, select, textarea):focus,
.modal-card :where(input, select, textarea):focus {
    border-color: rgba(var(--accent-rgb), 0.65);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.14);
}

textarea.input,
.dialog :where(textarea),
.modal-card :where(textarea) {
    min-height: 110px;
    line-height: 1.5;
    resize: vertical;
}

/* colour field: native swatch, a rainbow strip lit by the chosen colour, the hex value */
.tracker-color-picker {
    display: grid;
    grid-template-columns: 64px 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.035);
}

.tracker-color-picker input[type="color"] {
    width: 64px;
    height: 48px;
    padding: 0;
    border: 0;
    border-radius: 14px;
    overflow: hidden;
    background: transparent;
    cursor: pointer;
}

.tracker-color-picker input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.tracker-color-picker input[type="color"]::-webkit-color-swatch {
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 14px;
}

.tracker-color-picker span {
    height: 14px;
    border-radius: 999px;
    background:
        linear-gradient(90deg, transparent, var(--picker-color), transparent),
        linear-gradient(90deg, #f87171, #fb923c, #facc15, #4ade80, #22d3ee, #60a5fa, #a28dfc, #f472b6);
    box-shadow: 0 0 24px color-mix(in srgb, var(--picker-color) 40%, transparent);
}

.tracker-color-picker b {
    color: #f4f4f5;
    font-size: 12px;
    letter-spacing: 0.06em;
}

@media (max-width: 640px) {
    .page-titlebar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 16px;
    }

    /* in a column the 320px basis would become a height */
    .page-titlebar > :first-child {
        flex-basis: auto;
    }

    .page-titlebar h1 {
        font-size: 22px;
    }

    .dialog h2,
    .modal-card h2 {
        font-size: 20px;
    }

    .modal {
        padding: 16px;
    }

    .modal-card {
        width: 100%;
        max-height: calc(100dvh - 32px);
        padding: 18px;
    }

    .dialog-body {
        gap: 12px;
        padding: 16px;
    }

    .dialog-actions {
        flex-wrap: wrap;
    }

    .dialog-actions .btn {
        flex: 1 1 0;
        min-width: 0;
    }

    .dialog-actions .btn-icon {
        flex: none;
    }

    .dialog-spacer {
        display: none;
    }

    .input,
    .dialog :where(input, select, textarea),
    .modal-card :where(input, select, textarea) {
        font-size: 16px;
    }
}

/* ---------- date navigation and date picker ----------
   "‹ Октябрь 2026 ›" and the calendar button that drops a panel (День / Неделя / Месяц / Год) under it.
   Born in Сон, shared since: the JS client draws it (frontend/src/components/DatePicker.tsx).
   The colour follows the page's accent tokens (purple in Сон, orange elsewhere). */





.date-picker {
    position: relative;
}

.date-picker-panel {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    z-index: 30;
    width: 300px;
    max-width: calc(100vw - 32px);
    display: grid;
    gap: 12px;
    padding: 12px;
    border: 1px solid rgba(var(--accent-rgb), 0.35);
    border-radius: 16px;
    background: #16171d;
    box-shadow: 0 24px 60px rgba(0,0,0,0.55);
}

.date-picker-panel[hidden] {
    display: none;
}

/* compact layout: the panel lives under the calendar, in the page flow (moved there by JS) */
.date-picker-slot:not(:has(.date-picker-panel:not([hidden]))) {
    display: none;
}

.date-picker-slot .date-picker-panel {
    position: static;
    /* the forge effects make cards position: relative (inline), and then the dropdown's own
       top: calc(100% + 10px) pushed the panel a whole panel-height down, over the page */
    top: auto;
    width: auto;
    max-width: none;
    /* scrolled into view on open: stop above the fixed bottom nav (main's padding-bottom) */
    scroll-margin-bottom: 96px;
}

/* four equal tabs in a 300px panel: smaller text and no side padding so "Неделя" fits */
.date-picker-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
}

.date-picker-tabs .tab {
    min-width: 0;
    padding: 0;
    font-size: 13px;
}

.date-picker-head button,
.date-picker-day,
.date-picker-grid button {
    border: 0;
    background: transparent;
    color: #cfd2d8;
    font: inherit;
    cursor: pointer;
}

.date-picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.date-picker-head strong {
    color: #f4f4f5;
    font-size: 15px;
}

.date-picker-head button {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-size: 17px;
    line-height: 1;
}

.date-picker-head button:hover {
    background: rgba(255,255,255,0.08);
}

.date-picker-weekdays,
.date-picker-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

.date-picker-weekdays span {
    padding: 4px 0;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-align: center;
}

.date-picker-row {
    border-radius: 9px;
}

.date-picker-row.weekly:hover {
    background: rgba(var(--accent-rgb), 0.16);
}

.date-picker-row.weekly.selected {
    background: rgba(var(--accent-rgb), 0.3);
}

.date-picker-day {
    position: relative;
    height: 34px;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 700;
}

.date-picker-day.muted {
    color: #5d616b;
}

.date-picker-day.today,
.date-picker-grid button.today {
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35);
}

.date-picker-day.has-entry::after {
    content: "";
    position: absolute;
    bottom: 4px;
    left: 50%;
    width: 4px;
    height: 4px;
    margin-left: -2px;
    border-radius: 50%;
    background: var(--accent-text);
}

.date-picker-day.selected,
.date-picker-grid button.selected {
    background: linear-gradient(90deg, var(--accent), var(--accent-text));
    color: #111318;
}

.date-picker-day.selected::after {
    background: #111318;
}

.date-picker:not(:has(.date-picker-row.weekly)) .date-picker-day:hover,
.date-picker-grid button:hover {
    background: rgba(var(--accent-rgb), 0.22);
}

.date-picker-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.date-picker-grid button {
    padding: 12px 0;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    font-weight: 800;
}

.date-picker-footer {
    text-align: center;
    color: var(--accent-text);
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
}

.date-picker-footer:hover {
    text-decoration: underline;
}

@media (max-width: 760px) {
    .date-picker-day { height: 40px; }

    /* on a phone the panel takes the width of the row it sits in, not of the button it hangs off
       (a page that moves it elsewhere, like Сон's slot, is unaffected) */
    .date-picker { position: static; }

    .date-picker-panel {
        left: 0;
        right: 0;
        width: auto;
        max-width: none;
    }
}

/* ---------- voice input (frontend MicButton / DictationStatus): Сон, Рефлексия ----------
   The section draws the button itself (its size and place); recording and waiting look the
   same everywhere, and so does the status line next to it. */

.mic-btn.is-recording {
    border-color: rgba(239, 68, 68, 0.65);
    background: rgba(239, 68, 68, 0.2);
    color: #ff8080;
    animation: mic-pulse 1.4s ease-in-out infinite;
}

.mic-btn:disabled {
    opacity: 0.45;
    cursor: wait;
}

@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.mic-status {
    max-width: 230px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,0.07);
    color: #c7cbd3;
    font-size: 13px;
    font-weight: 700;
}

.mic-status[data-kind="recording"],
.mic-status[data-kind="error"] {
    background: rgba(239, 68, 68, 0.16);
    color: #ff9b9b;
}

.mic-status[data-kind="busy"] {
    background: rgba(143, 107, 253, 0.18);
    color: #cdc6fb;
}

/* ---------- a section's archive in a dialog (frontend ArchiveDialog): Привычки, Аскезы, Курсы ----------
   Each item in its own colour (--item-color): its icon, its name, since when it is put away,
   "Вернуть" and the bin. */

.archive-dialog {
    --dialog-width: 680px;
}

.archive-list {
    max-height: min(66vh, 620px);
    overflow: auto;
    display: grid;
    gap: 10px;
    padding-right: 4px;
}

.archive-item {
    --item-color: #ff8a2a;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border: 1px solid color-mix(in srgb, var(--item-color) 24%, rgba(255,255,255,0.08));
    border-radius: 14px;
    background:
        radial-gradient(circle at 0% 0%, color-mix(in srgb, var(--item-color) 16%, transparent), transparent 34%),
        rgba(255,255,255,0.035);
}

.archive-item-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    color: var(--item-color);
    background: color-mix(in srgb, var(--item-color) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--item-color) 28%, transparent);
}

.archive-item strong,
.archive-item small {
    display: block;
    min-width: 0;
    overflow-wrap: anywhere;
}

.archive-item strong {
    color: #f4f4f5;
}

.archive-item small {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.archive-restore {
    min-height: 34px;
    padding: 7px 11px;
    border: 1px solid rgba(96, 165, 250, 0.3);
    border-radius: 10px;
    background: rgba(96, 165, 250, 0.1);
    color: #bfdbfe;
    font: inherit;
    font-size: 13px;
    font-weight: 900;
    cursor: pointer;
}

.archive-restore:hover {
    border-color: rgba(96, 165, 250, 0.58);
    background: rgba(96, 165, 250, 0.16);
}

.archive-delete {
    width: 34px;
    height: 34px;
    border: 1px solid rgba(239,68,68,0.28);
    border-radius: 10px;
    background: rgba(239,68,68,0.08);
    color: #ffb4b4;
    font: inherit;
    font-size: 18px;
    font-weight: 900;
    cursor: pointer;
}

.archive-delete:hover {
    color: #fff;
    border-color: rgba(239,68,68,0.6);
    background: rgba(239,68,68,0.18);
}

.archive-empty {
    padding: 22px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    color: var(--muted);
    background: rgba(255,255,255,0.035);
    text-align: center;
}

@media (max-width: 560px) {
    .archive-item {
        grid-template-columns: 42px minmax(0, 1fr) auto;
    }

    .archive-restore {
        grid-column: 2;
        justify-self: start;
    }

    .archive-delete {
        grid-column: 3;
        grid-row: 1;
    }
}

/* Habit instructions use the same private document viewer in the tracker and routine. */
.habit-details-with-files { display:flex; align-items:flex-start; gap:6px; min-width:0; flex:1; }
.habit-details-with-files > .habit-details { flex:1; min-width:0; }
.habit-document-button { display:inline-flex; align-items:center; justify-content:center; gap:3px; width:28px; height:28px; flex:none; margin-left:6px; padding:0; border:1px solid rgba(255,255,255,.12); border-radius:7px; background:transparent; color:#999; cursor:pointer; vertical-align:middle; }
.habit-document-button.has-files { color:#ff9d2e; border-color:rgba(255,122,26,.4); }
.habit-document-button:hover { color:#ff9d2e; }
.habit-document-list { display:grid; gap:8px; }
.habit-document-list > div { display:flex; gap:8px; }
.habit-document-list > div > .btn:first-child { flex:1; white-space:normal; text-align:left; overflow-wrap:anywhere; }
.document-viewer-dialog { --dialog-width:900px; }
.document-reader { line-height:1.65; overflow-wrap:anywhere; }
.document-reader img { display:block; max-width:100%; height:auto; margin:12px auto; }
.document-reader img[data-align=left] { margin-left:0; }
.document-reader img[data-align=right] { margin-right:0; }
.document-reader table { border-collapse:collapse; width:100%; }
.document-reader td,.document-reader th { border:1px solid rgba(150,150,150,.3); padding:6px; }
.document-pdf { width:100%; height:65vh; border:0; background:white; }

.routine-return { display: inline-flex; align-items: center; margin-bottom: 12px; text-decoration: none; }
