/* ════════════════════════════════════════════════════════════════════════
   study-page-automations.css: "Keep updated" on a Space page
   (public/js/study/study-page-automations.js). The chip in the page's top bar,
   and the dialog behind it.
   Tokens and the tactile .k-btn come from /css/shared/khio-ui.css, so light and
   dark follow html[data-theme] with nothing to redo here.
   The dialog's fields and labels are written on the #paDialog id: study-themes.css
   dresses every light-theme field and label with !important, and only an id
   beats that (the same reason study-pages.css uses #spLayer).
   ════════════════════════════════════════════════════════════════════════ */

.pa-chip, .pa-card { --pa-warn: #9a5b00; }
html[data-theme="dark"] .pa-chip, html[data-theme="dark"] .pa-card { --pa-warn: #f2c46d; }

/* ── The chip in the top bar ──────────────────────────────────────────── */
.pa-chip { display: inline-flex; align-items: center; gap: 7px; height: 30px; max-width: 340px; margin-right: 4px; padding: 0 12px 0 10px; border: 0; border-radius: 999px; background: var(--k-hover); color: var(--k-ink-2); font: 500 13px var(--k-sans); cursor: pointer; transition: background .15s ease, color .15s ease; }
.pa-chip:hover { background: color-mix(in srgb, var(--k-ink) 9%, transparent); color: var(--k-ink); }
.pa-chip:focus-visible { outline: 2px solid var(--k-blue); outline-offset: 2px; }
.pa-chip svg { flex: none; width: 14px; height: 14px; }
.pa-chip span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pa-chip.is-warn { color: var(--pa-warn); background: color-mix(in srgb, #e0a82e 16%, transparent); }
.pa-chip.is-busy svg { animation: pa-spin 1s linear infinite; }
@keyframes pa-spin { to { transform: rotate(360deg); } }

/* ── The dialog ───────────────────────────────────────────────────────── */
/* The dialog element is the scrim and centres the card with flex. study-core.css
   sets every margin to 0, which takes a modal dialog's own centring away (the
   trap js/shared/phone-link-gate.js documents). */
.pa-dialog[open] { position: fixed; inset: 0; box-sizing: border-box; display: flex; align-items: center; justify-content: center; width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; padding: 24px 16px; border: 0; background: transparent; overflow-y: auto; }
.pa-dialog::backdrop { background: rgba(10, 10, 12, .44); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.pa-card { box-sizing: border-box; width: min(580px, 100%); margin: auto; display: flex; flex-direction: column; border-radius: 24px; background: var(--k-surface); color: var(--k-ink); border: 1px solid var(--k-line); box-shadow: 0 2px 6px rgba(0, 0, 0, .06), 0 28px 80px rgba(0, 0, 0, .22); font-family: var(--k-sans); -webkit-font-smoothing: antialiased; animation: k-rise .28s var(--k-ease) both; }
.pa-card *, .pa-card *::before, .pa-card *::after { box-sizing: border-box; }
.pa-card button, .pa-card input, .pa-card select, .pa-card textarea { font-family: inherit; }
.pa-card svg { flex: none; }
.pa-card [hidden] { display: none !important; }
.pa-card button:disabled { cursor: default; }
.pa-dialog.is-busy .pa-card { cursor: progress; }
#paDialog label { font-family: var(--k-sans) !important; }

.pa-head { display: flex; align-items: flex-start; gap: 14px; padding: 24px 24px 4px; }
.pa-head-ico { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--k-hover); color: var(--k-ink); }
.pa-head-ico svg { width: 19px; height: 19px; }
.pa-head-text { flex: 1; min-width: 0; }
.pa-title { margin: 0; font: 500 28px/1.1 var(--k-display); letter-spacing: -.02em; }
.pa-sub { margin: 6px 0 0; font-size: 14.5px; line-height: 1.5; color: var(--k-ink-2); }
.pa-x { flex: none; width: 34px; height: 34px; margin: -4px -6px 0 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: var(--k-ink-3); cursor: pointer; }
.pa-x:hover { background: var(--k-hover); color: var(--k-ink); }
.pa-x svg { width: 18px; height: 18px; }

.pa-body { padding: 6px 24px 0; }
.pa-sec { padding: 14px 0; }
.pa-sec + .pa-sec { border-top: 1px solid var(--k-line); }
.pa-label { display: block; margin: 0 0 10px; font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--k-ink-3); }

/* What should Khio do: the ask, and three one-tap starts. */
#paDialog textarea, #paDialog textarea:hover { display: block; width: 100%; min-height: 84px; margin: 0; padding: 12px 14px; border: 1px solid var(--k-line) !important; border-radius: 14px !important; background: var(--k-paper) !important; box-shadow: none !important; outline: 0 !important; color: var(--k-ink) !important; font: 15.5px/1.5 var(--k-sans) !important; resize: vertical; transition: border-color .15s ease, box-shadow .15s ease; }
#paDialog textarea:focus { border-color: var(--k-blue) !important; background: var(--k-paper) !important; box-shadow: 0 0 0 3px rgba(10, 132, 255, .14) !important; }
#paDialog textarea::placeholder { color: var(--k-ink-3) !important; opacity: 1; }
.pa-starters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pa-starter { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; padding: 7px 12px; border: 1px solid var(--k-line); border-radius: 999px; background: var(--k-surface); color: var(--k-ink-2); font: 500 13px/1.3 var(--k-sans); text-align: left; cursor: pointer; transition: background .15s ease, border-color .15s ease, color .15s ease; }
.pa-starter:hover { background: var(--k-hover); color: var(--k-ink); }
.pa-starter.is-on { border-color: var(--k-ink); background: var(--k-hover); color: var(--k-ink); }
.pa-starter svg { width: 14px; height: 14px; color: var(--k-ink-3); }

/* How often: every day / weekdays / weekly, then the day and the time. */
.pa-often { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.pa-seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--k-hover); }
.pa-seg-btn { height: 32px; padding: 0 14px; border: 0; border-radius: 9px; background: none; color: var(--k-ink-2); font: 500 14px var(--k-sans); cursor: pointer; transition: background .15s ease, color .15s ease, box-shadow .15s ease; }
.pa-seg-btn:hover { color: var(--k-ink); }
.pa-seg-btn.is-on { background: var(--k-surface); color: var(--k-ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 0 0 1px var(--k-line); }
.pa-at { display: inline-flex; align-items: center; gap: 8px; color: var(--k-ink-2); font-size: 14px; }
#paDialog select, #paDialog input[type="time"] { height: 38px; margin: 0; padding: 0 12px; border: 1px solid var(--k-line) !important; border-radius: 11px !important; background: var(--k-paper) !important; box-shadow: none !important; outline: 0 !important; color: var(--k-ink) !important; font: 500 14px var(--k-sans) !important; }
#paDialog select:focus, #paDialog input[type="time"]:focus { border-color: var(--k-blue) !important; box-shadow: 0 0 0 3px rgba(10, 132, 255, .14) !important; }
html[data-theme="dark"] #paDialog select, html[data-theme="dark"] #paDialog input[type="time"] { color-scheme: dark; }

/* Sources: three cards, ticked when chosen, greyed when not connected. */
.pa-sources { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.pa-src { position: relative; display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--k-line); border-radius: 14px; background: var(--k-surface); cursor: pointer; transition: border-color .15s ease, background .15s ease, box-shadow .15s ease; }
.pa-src:hover { background: var(--k-hover); }
.pa-src input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.pa-src-ico { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 10px; background: var(--k-hover); color: var(--k-ink-2); }
.pa-src-ico svg { width: 16px; height: 16px; }
.pa-src-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pa-src-text b { font-size: 14.5px; font-weight: 600; }
.pa-src-text small { font-size: 12.5px; line-height: 1.4; color: var(--k-ink-3); }
.pa-src-text a { color: var(--k-blue); text-decoration: underline; text-underline-offset: 2px; }
.pa-src-tick { position: absolute; top: 10px; right: 10px; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; border: 1.5px solid color-mix(in srgb, var(--k-ink) 25%, transparent); color: transparent; transition: background .15s ease, border-color .15s ease, color .15s ease; }
.pa-src-tick svg { width: 12px; height: 12px; }
.pa-src:has(input:checked) { border-color: var(--k-ink); box-shadow: inset 0 0 0 1px var(--k-ink); }
.pa-src:has(input:checked) .pa-src-tick { background: var(--k-ink); border-color: var(--k-ink); color: var(--k-surface); }
.pa-src:has(input:focus-visible) { outline: 2px solid var(--k-blue); outline-offset: 2px; }
.pa-src.is-off { cursor: default; background: none; }
.pa-src.is-off .pa-src-ico, .pa-src.is-off b, .pa-src.is-off .pa-src-tick { opacity: .45; }

/* Text me what changed: a switch. */
.pa-switch { position: relative; display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.pa-switch input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.pa-switch-ui { position: relative; flex: none; width: 40px; height: 24px; margin-top: 1px; border-radius: 999px; background: color-mix(in srgb, var(--k-ink) 18%, transparent); transition: background .2s var(--k-ease); }
.pa-switch-ui::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .22); transition: transform .2s var(--k-ease), background .2s ease; }
.pa-switch input:checked + .pa-switch-ui { background: var(--k-ink); }
.pa-switch input:checked + .pa-switch-ui::after { transform: translateX(16px); background: var(--k-surface); }
.pa-switch input:focus-visible + .pa-switch-ui { outline: 2px solid var(--k-blue); outline-offset: 2px; }
.pa-switch-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pa-switch-text b { font-size: 14.5px; font-weight: 600; }
.pa-switch-text small { font-size: 13px; line-height: 1.45; color: var(--k-ink-3); }
.pa-switch.is-off { cursor: default; }
.pa-switch.is-off .pa-switch-ui, .pa-switch.is-off b { opacity: .45; }

/* What happened, then the buttons. */
.pa-status { margin: 0; padding: 4px 24px 0; font-size: 13.5px; line-height: 1.45; color: var(--k-ink-3); }
.pa-status:empty { display: none; }
.pa-status.is-warn { color: var(--pa-warn); }
.pa-status.is-good { color: var(--k-good); }
.pa-status.is-busy { color: var(--k-ink-2); }
.pa-status.is-busy::before { content: ''; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--k-ink) 18%, transparent); border-top-color: var(--k-ink); animation: pa-spin .8s linear infinite; }
.pa-foot { display: flex; align-items: center; gap: 8px; padding: 16px 24px 22px; }
.pa-grow { flex: 1; }
.pa-off { padding: 8px 6px; border: 0; border-radius: 8px; background: none; color: var(--k-bad); font: 500 14px var(--k-sans); cursor: pointer; }
.pa-off:hover { text-decoration: underline; text-underline-offset: 3px; }

.pa-x:focus-visible, .pa-starter:focus-visible, .pa-seg-btn:focus-visible, .pa-off:focus-visible { outline: 2px solid var(--k-blue); outline-offset: 2px; }

@media (max-width: 1023px) {
    .pa-chip { padding: 0 9px; }
    .pa-chip span { display: none; }
}
@media (max-width: 600px) {
    .pa-head { padding: 20px 18px 4px; }
    .pa-body { padding: 4px 18px 0; }
    .pa-status { padding: 4px 18px 0; }
    .pa-foot { flex-wrap: wrap; padding: 14px 18px 18px; }
    .pa-sources { grid-template-columns: 1fr; }
    .pa-src { flex-direction: row; align-items: center; padding-right: 40px; }
    .pa-src-tick { top: 50%; margin-top: -10px; }
}
@media (prefers-reduced-motion: reduce) {
    .pa-card { animation: none; }
    .pa-chip.is-busy svg, .pa-status.is-busy::before { animation: none; }
}
