/* Foundation: design tokens, base elements, controls, surfaces, dialogs and sheets.
   Every other stylesheet builds on these tokens. Light scheme only for now: a dark scheme
   would redefine the "Palette" block and nothing else.

   How surfaces stack: the page is white (--color-bg); a section sits on it as a soft grey tile
   (--color-tile, no border, no shadow); whatever is raised on a tile (a row, a field, a sheet) is
   white again (--color-surface) with the faint --shadow-card. */

:root {
  color-scheme: light;

  /* Palette */
  --color-bg: #ffffff;
  --color-tile: #f5f5f7;
  --color-tile-hover: #ededf1;
  --color-surface: #ffffff;
  --color-surface-2: #fafafc;
  --color-fill: #e8e8ed;
  --color-fill-hover: #dcdce2;
  --color-fill-soft: #f0f0f3;
  --color-text: #1d1d1f;
  --color-text-2: #515154;
  --color-text-3: #6e6e73;
  --color-separator: #e5e5ea;
  --color-border: #d2d2d7;
  --color-control-border: #86868b;
  /* The accent fills buttons and marks; text in the accent colour uses the darker --color-accent-text,
     which keeps 4.5:1 on a grey tile too. */
  --color-accent: #0071e3;
  --color-accent-hover: #0077ed;
  --color-accent-active: #0068d1;
  --color-accent-text: #0066cc;
  --color-accent-soft: #e6f1fd;
  --color-accent-border: #a8cdf5;
  --color-on-accent: #ffffff;
  --color-success: #186a31;
  --color-success-fill: #248a3d;
  --color-success-soft: #e1f5e6;
  --color-success-border: #b5dfc0;
  --color-danger: #c4271b;
  --color-danger-hover: #a92015;
  --color-danger-soft: #fdecea;
  --color-danger-border: #f2c3bd;
  --color-warning: #8a4700;
  --color-warning-fill: #d95700;
  --color-warning-soft: #ffefd9;
  --color-warning-border: #f0d2a4;
  --color-indigo: #4543c9;
  --color-indigo-soft: #ecebff;
  --color-ink: #1d1d1f;
  --color-scrim: rgba(0, 0, 0, .36);
  --material-bar: rgba(255, 255, 255, .76);

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --text-caption: 12px;
  --text-footnote: 13px;
  --text-body: 15px;
  --text-headline: 17px;
  --text-title-3: 20px;
  --text-title-2: 19px;
  --text-title-1: 24px;
  --text-large-title: 30px;

  /* Space (4 px steps) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Shape, depth, motion */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-control: 10px;  /* buttons, fields, switches between views */
  --radius-row: 12px;      /* a white row or card on a tile */
  --radius-badge: 6px;     /* status labels and tags */
  --radius-pill: 999px;    /* only what is round by nature: counters, tracks, the on/off switch */
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .06);
  --shadow-raised: 0 0 0 1px rgba(0, 0, 0, .05), 0 10px 30px rgba(0, 0, 0, .10);
  --shadow-sheet: 0 0 0 1px rgba(0, 0, 0, .06), 0 28px 80px rgba(0, 0, 0, .24);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --duration-fast: .15s;
  --duration: .26s;
  --control-height: 40px;
  --focus-ring: 0 0 0 4px rgba(0, 113, 227, .22);
  --shell-gap: 12px;

  /* Names from before the redesign. Other stylesheets (Materiały, the onboarding wizard) are written
     against these, so they stay defined and point at the tokens above. */
  --paper: var(--color-bg);
  --white: var(--color-surface);
  --ink: var(--color-text);
  --navy: var(--color-accent);
  --navy-hover: var(--color-accent-hover);
  --muted: var(--color-text-2);
  --line: var(--color-separator);
  --line-strong: var(--color-border);
  --soft: var(--color-tile);
  --green: var(--color-success);
  --green-soft: var(--color-success-soft);
  --red: var(--color-danger);
  --red-soft: var(--color-danger-soft);
  --amber: var(--color-warning);
  --amber-soft: var(--color-warning-soft);
  --radius: var(--radius-md);
}
/* Fingers need 44 px; a mouse pointer does not. */
@media (pointer: coarse), (max-width: 760px) { :root { --control-height: 44px; } }

/* ---- Base ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; -webkit-text-size-adjust: 100%; }
body { margin: 0; color: var(--color-text); background: var(--color-bg); font: 400 var(--text-body)/1.5 var(--font-sans); -webkit-font-smoothing: antialiased; }
body.dialog-open { overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button, a, input, textarea, select, summary, label { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
/* A heading that only receives focus from a script (after a change of view) shows no ring. */
[tabindex="-1"]:focus { outline: none; }
::selection { background: #cfe4fb; color: var(--color-text); }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: clamp(26px, 1vw + 18px, var(--text-large-title)); font-weight: 700; letter-spacing: -.022em; line-height: 1.15; }
h2 { font-size: var(--text-title-2); font-weight: 600; letter-spacing: -.014em; line-height: 1.25; }
h3 { font-size: var(--text-headline); font-weight: 600; letter-spacing: -.01em; line-height: 1.3; }
h4 { font-size: var(--text-body); font-weight: 600; line-height: 1.35; }
p { color: var(--color-text-2); }
a { color: var(--color-accent-text); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
strong { font-weight: 600; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
summary { cursor: pointer; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ---- Form controls ---- */
label { display: block; margin: var(--space-4) 0 6px; color: var(--color-text); font-size: var(--text-footnote); font-weight: 600; }
input, textarea, select { display: block; width: 100%; min-width: 0; min-height: 44px; padding: 10px 12px; color: var(--color-text); background: var(--color-surface);
  border: 1px solid var(--color-control-border); border-radius: var(--radius-control); font-size: var(--text-body); line-height: 1.4; transition: border-color var(--duration-fast), box-shadow var(--duration-fast); }
textarea { resize: vertical; line-height: 1.55; }
select { appearance: none; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--color-text-2) 50%), linear-gradient(135deg, var(--color-text-2) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
input::placeholder, textarea::placeholder { color: var(--color-text-3); opacity: 1; }
input:hover, textarea:hover, select:hover { border-color: var(--color-text-2); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--color-accent); box-shadow: var(--focus-ring); }
input:disabled, textarea:disabled, select:disabled { background: var(--color-fill-soft); border-color: var(--color-border); color: var(--color-text-3); cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { appearance: auto; display: inline-block; width: 18px; height: 18px; min-height: 18px; flex: 0 0 18px; padding: 0; margin: 0; border: 0; box-shadow: none; accent-color: var(--color-accent); }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; box-shadow: none; }
/* An on/off switch: a checkbox with class "switch". */
input[type="checkbox"].switch { appearance: none; position: relative; width: 46px; height: 28px; min-height: 28px; flex: 0 0 46px; border-radius: var(--radius-pill); background: #b4b4b9; cursor: pointer; transition: background-color var(--duration) var(--ease-out); }
input[type="checkbox"].switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform var(--duration) var(--ease-out); }
input[type="checkbox"].switch:checked { background: var(--color-success-fill); }
input[type="checkbox"].switch:checked::after { transform: translateX(18px); }
input[type="checkbox"].switch:disabled { opacity: .5; cursor: not-allowed; }
input[type="date"] { max-width: 250px; }
input[type="time"] { max-width: 180px; }
input[type="search"] { border-radius: var(--radius-control); padding-inline: 16px; background: var(--color-surface); }
.field-help { margin-top: 6px; font-size: var(--text-caption); }
.label-optional { color: var(--color-text-3); font-weight: 400; }

/* ---- Buttons ---- */
button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--control-height); padding: 0 16px; border: 1px solid transparent; border-radius: var(--radius-control);
  font-size: var(--text-body); font-weight: 500; line-height: 1.25; cursor: pointer; text-align: center;
  transition: background-color var(--duration-fast), border-color var(--duration-fast), color var(--duration-fast), box-shadow var(--duration-fast), transform var(--duration-fast); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:active:not(:disabled) { transform: scale(.97); }
.button-primary { background: var(--color-accent); color: var(--color-on-accent); font-weight: 600; }
.button-primary:hover:not(:disabled) { background: var(--color-accent-hover); }
.button-primary:active:not(:disabled) { background: var(--color-accent-active); }
.button-secondary { background: var(--color-fill); color: var(--color-text); }
.button-secondary:hover:not(:disabled) { background: var(--color-fill-hover); }
.button-text { background: transparent; color: var(--color-accent-text); padding: 0 12px; }
.button-text:hover:not(:disabled) { background: var(--color-accent-soft); }
.button-danger { background: var(--color-danger); color: #fff; font-weight: 600; }
.button-danger:hover:not(:disabled) { background: var(--color-danger-hover); }
.button-danger-text { background: transparent; color: var(--color-danger); padding: 0 12px; }
.button-danger-text:hover:not(:disabled) { background: var(--color-danger-soft); }
.button-square { flex: 0 0 auto; width: var(--control-height); min-width: var(--control-height); padding: 0; background: var(--color-fill); color: var(--color-text); border-radius: 50%; font-size: 20px; font-weight: 400; line-height: 1; }
.button-square:hover:not(:disabled) { background: var(--color-fill-hover); }
.button-wide { width: 100%; }
.button-icon { flex: 0 0 auto; width: var(--control-height); min-width: var(--control-height); padding: 0; border-radius: 50%; }
.button-icon .ui-icon { width: 18px; height: 18px; }
a.button-text { display: inline-flex; align-items: center; min-height: var(--control-height); padding: 0 12px; border-radius: var(--radius-control); font-weight: 600; text-decoration: none; }
a.button-primary, a.button-secondary { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--control-height); padding: 0 18px; border-radius: var(--radius-control); font-weight: 600; text-decoration: none; }
a.button-primary:hover { color: var(--color-on-accent); background: var(--color-accent-hover); }
.button-large { min-height: 42px; padding: 0 18px; }
.ui-icon { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Text helpers ---- */
.eyebrow { color: var(--color-text-3); font-size: var(--text-footnote); font-weight: 500; line-height: 1.4; }
.small-note { color: var(--color-text-2); font-size: var(--text-footnote); line-height: 1.45; }
.small-label { color: var(--color-text-2); font-size: var(--text-caption); font-weight: 600; }
.form-error { margin: var(--space-3) 0; padding: 10px 14px; border-radius: var(--radius-md); background: var(--color-danger-soft); color: var(--color-danger); font-size: var(--text-footnote); font-weight: 500; overflow-wrap: anywhere; }
.skip-link { position: fixed; left: 12px; top: 10px; z-index: 200; padding: 10px 16px; border-radius: var(--radius-md); background: var(--color-surface); box-shadow: var(--shadow-raised); transform: translateY(-200%); }
.skip-link:focus { transform: none; }
.noscript { padding: 24px; text-align: center; }

/* ---- Status and tags ---- */
.status-badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: var(--radius-badge); background: var(--color-fill); color: #48484a; font-size: var(--text-caption); font-weight: 600; line-height: 1.5; white-space: nowrap; }
.status-badge.is-ready { background: var(--color-success-soft); color: var(--color-success); }
.status-badge.is-failed { background: var(--color-danger-soft); color: var(--color-danger); }

/* ---- Page frame ---- */
.workspace { max-width: 1168px; margin: 0 auto; padding: 0 24px; min-width: 0; outline: none; }
.session-check { padding: 96px 0; text-align: center; }

/* ---- Messages: the short toast, and Powiadomienia under the bell ---- */
/* Only a new, five-second message floats over the page, in the bottom-right corner (left of an
   open Agent panel, placed by studio.js); history is opt-in under the bell. */
.notification-region { position: fixed; right: max(24px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom)); width: min(380px, calc(100vw - 32px)); z-index: 90; }
.notice { display: grid; grid-template-columns: 24px minmax(0, 1fr) 32px; align-items: start; gap: 10px; padding: 12px 8px 12px 14px; margin: 0; border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, .84); -webkit-backdrop-filter: saturate(180%) blur(22px); backdrop-filter: saturate(180%) blur(22px); box-shadow: var(--shadow-raised);
  color: var(--color-text); font-size: var(--text-footnote); font-weight: 500; overflow-wrap: anywhere; animation: toast-in var(--duration) var(--ease-out); }
.notice p { color: inherit; margin: 0; padding-top: 2px; }
.notice-icon { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: var(--color-success-fill); color: #fff; font-size: 13px; font-weight: 700; line-height: 1; }
.notice-icon::before { content: "✓"; }
.notice.is-error p { color: var(--color-danger); }
.notice.is-error .notice-icon { background: var(--color-danger); }
.notice.is-error .notice-icon::before { content: "!"; }
.notification-close { width: 32px; min-width: 32px; min-height: 32px; padding: 0; background: transparent; color: var(--color-text-3); font-size: 20px; font-weight: 400; line-height: 1; border-radius: 50%; }
.notification-close:hover { background: var(--color-fill); color: var(--color-text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* Opens beside the bell (position set by studio.js); this is the fallback. */
.history-dialog { position: fixed; inset: auto auto 16px 264px; margin: 0; width: min(400px, calc(100% - 32px)); max-width: calc(100% - 32px); max-height: min(76dvh, 700px); overflow-y: auto; overscroll-behavior: contain;
  padding: 0 16px 16px; border-radius: var(--radius-xl); }
.history-dialog::backdrop { background: rgba(0, 0, 0, .12); }
.history-dialog .dialog-heading { margin: 0 -16px; padding: 14px 12px 10px 16px; }
.history-dialog .dialog-heading h2 { font-size: var(--text-headline); }
.history-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; margin: 0 -6px 8px; }
.history-actions button { min-height: 32px; padding: 0 8px; font-size: var(--text-footnote); }
.history-actions .history-clear { color: var(--color-danger); }
.history-actions .history-clear:hover:not(:disabled) { background: var(--color-danger-soft); }
.history-actions button:disabled { color: var(--color-text-3); cursor: default; opacity: .6; }
.history-dot { width: 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: transparent; }
.is-new > .history-dot { background: var(--color-accent); }
.is-new.is-failed > .history-dot, .is-new.is-error > .history-dot { background: var(--color-danger); }
.history-when { display: block; margin-top: 2px; font-size: var(--text-caption); color: var(--color-text-3); }
.history-remove { width: 32px; min-width: 32px; height: 32px; min-height: 32px; padding: 0; background: transparent; border-radius: 50%; color: var(--color-text-3); font-size: 18px; font-weight: 400; line-height: 1; }
.history-remove:hover { background: var(--color-fill); color: var(--color-text); }
.history-dialog .uncertain-request { margin-bottom: 12px; }
.history-notice { display: grid; grid-template-columns: 8px minmax(0, 1fr) 32px; gap: 10px; padding: 8px 4px 8px 10px; border-radius: var(--radius-md); color: var(--color-text); font-size: var(--text-footnote); overflow-wrap: anywhere; }
.history-notice + .history-notice { margin-top: 2px; }
.history-notice p { margin: 0; padding-top: 1px; color: var(--color-text); }
.history-notice.is-new { background: var(--color-accent-soft); }
.history-notice.is-error p { color: var(--color-danger); }
.notice-history-list { margin-top: 12px; }
#history-empty { padding: 20px 8px 12px; text-align: center; }
.job-status { margin: 0; border-radius: var(--radius-md); background: var(--color-tile); overflow: hidden; }
.job-row { display: grid; grid-template-columns: 8px minmax(0, 1fr) 32px; column-gap: 10px; row-gap: 2px; padding: 10px 6px 10px 12px; overflow-wrap: anywhere; }
.job-row.is-new { background: var(--color-accent-soft); }
.job-row > .history-dot { grid-column: 1; grid-row: 1; }
.job-row > .history-remove { grid-column: 3; grid-row: 1; }
.job-copy { grid-column: 2; grid-row: 1; min-width: 0; }
.job-row + .job-row { border-top: 1px solid var(--color-separator); }
.job-row strong { font-size: var(--text-footnote); font-weight: 600; }
.job-row p { font-size: var(--text-caption); margin-top: 2px; }
.job-row.is-failed p { color: var(--color-danger); }
.job-row-actions { grid-column: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-left: -8px; min-width: 0; }
.job-row-actions button { min-height: 32px; padding: 0 8px; font-size: var(--text-footnote); }
.poll-paused { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--color-separator); overflow-wrap: anywhere; }
.poll-paused p { font-size: var(--text-caption); }
.poll-paused button { flex-shrink: 0; }
.uncertain-request { margin: 0; padding: 14px; border-radius: var(--radius-md); background: var(--color-warning-soft); font-size: var(--text-footnote); }
.uncertain-request strong { color: var(--color-warning); }
.uncertain-request p { margin-top: 4px; font-size: var(--text-footnote); }
.inline-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* ---- Page furniture ---- */
.loading { padding: var(--space-4) 0 0; font-size: var(--text-footnote); }
.load-error { padding: 48px 0 80px; }
.load-error p { margin: 12px 0 20px; max-width: 650px; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-4) var(--space-6); padding: var(--space-2) 0 var(--space-6); }
.page-heading h1 { overflow-wrap: anywhere; }
.page-heading p { margin-top: 6px; font-size: var(--text-body); line-height: 1.45; max-width: 68ch; }
.page-heading > button, .page-heading > .inline-actions { flex-shrink: 0; margin-top: 0; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-3); margin: 0 0 var(--space-3); }
.section-heading p { margin-top: 2px; font-size: var(--text-footnote); }
.section-heading .button-text { flex-shrink: 0; }
.availability-note { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; margin: 0 0 var(--space-4); padding: 12px 16px; border-radius: var(--radius-md); background: var(--color-warning-soft); color: var(--color-warning); font-size: var(--text-footnote); }
.availability-note strong { font-weight: 600; }
.availability-note a { font-weight: 600; }
.empty-state { padding: var(--space-10) var(--space-6); border-radius: var(--radius-xl); background: var(--color-tile); text-align: center; }
.empty-state h3 { font-size: var(--text-headline); }
.empty-state p { margin: 6px auto 0; font-size: var(--text-body); max-width: 46ch; }
.empty-state .button-text { margin-top: 10px; }

/* ---- Shared building blocks (Materiały and the onboarding wizard build on these) ---- */
.materials-card { display: flex; flex-direction: column; gap: 14px; min-width: 0; padding: var(--space-6); border-radius: var(--radius-xl); background: var(--color-tile); }
.materials-card h2 { font-size: var(--text-title-3); }
.materials-card h3 { font-size: var(--text-headline); }
.materials-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: var(--space-3); }
.materials-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.materials-form .materials-actions { grid-column: 1 / -1; }
.material-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.material-field label { margin: 0; }
.profile-row { display: grid; gap: var(--space-2); align-items: start; padding: 12px; border-radius: var(--radius-md); background: var(--color-surface); box-shadow: var(--shadow-card); }
.profile-row textarea, .profile-row input, .profile-row select { width: 100%; min-width: 0; }
.team-check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 0; font-size: var(--text-body); font-weight: 400; }
@media (max-width: 760px) {
  .materials-card { padding: var(--space-4); }
  .materials-form { grid-template-columns: minmax(0, 1fr); }
}

/* ---- A post in a list ---- */
.post-row { display: block; width: 100%; min-height: 0; padding: var(--space-4); border-radius: var(--radius-lg); background: var(--color-tile); color: var(--color-text); text-align: left; font-weight: 400; }
.post-row:hover:not(:disabled) { background: var(--color-tile-hover); }
.post-row-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.post-row-heading strong { font-size: 16px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.post-preview { color: var(--color-text-2); font-size: var(--text-footnote); margin: 4px 0 8px; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; white-space: pre-wrap; overflow-wrap: anywhere; }
.post-row-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; align-items: center; margin-top: 6px; color: var(--color-text-2); font-size: var(--text-caption); }
.post-row.has-image { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 14px; align-items: start; }
.post-row-body { display: block; min-width: 0; }
.post-thumbnail { display: block; width: 56px; height: 70px; object-fit: cover; border-radius: var(--radius-sm); background: var(--color-fill); }
.post-image-status { color: var(--color-text-3); }
.channel-label { color: var(--color-text-2); font-size: var(--text-caption); font-weight: 500; }

/* ---- Plan: the week ---- */
.week-brief-panel { margin-bottom: var(--space-5); padding: var(--space-6); border-radius: var(--radius-xl); background: var(--color-tile); animation: reveal var(--duration) var(--ease-out); }
.week-brief-panel > div > h2 { font-size: var(--text-title-3); }
.week-brief-panel > div > p { margin-top: 2px; font-size: var(--text-footnote); }
.week-brief-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(270px, 380px); gap: var(--space-6); }
.week-brief-actions { display: flex; justify-content: space-between; align-items: center; gap: var(--space-5); margin-top: var(--space-4); }
@keyframes reveal { from { opacity: 0; transform: translateY(-6px); } }
.calendar-toolbar, .week-navigation { display: flex; align-items: center; gap: var(--space-2); }
.calendar-toolbar { justify-content: space-between; flex-wrap: wrap; row-gap: var(--space-3); margin-bottom: var(--space-4); }
.week-navigation h2 { min-width: 0; padding: 0 var(--space-2); font-size: var(--text-title-2); white-space: nowrap; }
.week-navigation .button-square { width: 40px; min-width: 40px; min-height: 40px; font-size: 17px; background: var(--color-tile); }
.week-navigation .button-square:hover:not(:disabled) { background: var(--color-fill); }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-2); padding: var(--space-3); border-radius: var(--radius-xl); background: var(--color-tile); }
.calendar-day { display: flex; flex-direction: column; min-width: 0; min-height: 400px; padding: 0; border-radius: var(--radius-md); transition: background-color var(--duration-fast); }
.calendar-day.is-today .day-name { color: var(--color-accent-text); }
.day-content { display: flex; flex-direction: column; flex: 1; gap: var(--space-2); min-width: 0; }
.day-heading { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0 10px; }
.day-name { color: var(--color-text-3); font-size: var(--text-footnote); font-weight: 600; }
.day-number { display: grid; place-items: center; min-width: 36px; height: 36px; padding: 0 4px; border-radius: var(--radius-pill); color: var(--color-text); font-size: var(--text-title-3); font-weight: 600; }
.is-today .day-number { background: var(--color-accent); color: var(--color-on-accent); }
.day-empty { padding: var(--space-4) 0; font-size: var(--text-footnote); text-align: center; color: var(--color-text-3); }
.day-add { margin-top: auto; width: 100%; min-height: 40px; padding: 0 4px; border: 1.5px dashed #c7c7cc; border-radius: var(--radius-md); background: transparent; color: var(--color-text-3); font-size: var(--text-footnote); font-weight: 600; }
.day-add:hover { border-color: var(--color-accent); color: var(--color-accent-text); background: var(--color-surface); }
@media (hover: hover) and (min-width: 901px) {
  .day-add { opacity: 0; transition: opacity var(--duration-fast); }
  .calendar-day:hover .day-add, .day-add:focus-visible { opacity: 1; }
}
.calendar-post { display: block; width: 100%; min-height: 0; padding: 10px; border-radius: var(--radius-md); background: var(--color-surface); box-shadow: var(--shadow-card), 0 6px 16px rgba(0, 0, 0, .05); color: var(--color-text); text-align: left; font-weight: 400; }
.calendar-post:hover { box-shadow: var(--shadow-card), 0 10px 24px rgba(0, 0, 0, .10); }
.calendar-post[draggable="true"] { cursor: grab; }
.calendar-post > strong { display: block; margin: 4px 0 6px; font-size: 14px; line-height: 1.3; font-weight: 600; overflow-wrap: break-word; hyphens: auto; }
.calendar-post .channel-label { display: block; font-size: var(--text-caption); line-height: 1.3; overflow-wrap: anywhere; }
.calendar-time { display: block; color: var(--color-text-3); font-size: var(--text-footnote); font-weight: 600; font-variant-numeric: tabular-nums; }
.calendar-post .status-badge { display: inline-block; max-width: 100%; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; vertical-align: top; }
.calendar-thumbnail { display: block; width: 100%; height: auto; max-height: 110px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-md); margin-bottom: 8px; background: var(--color-fill); }
.calendar-image-status { display: block; margin-top: 6px; color: var(--color-text-3); font-size: var(--text-caption); line-height: 1.3; overflow-wrap: anywhere; }
.unscheduled-section { margin-top: var(--space-8); }
.unscheduled-posts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); }
.unscheduled-posts .post-row-heading { flex-wrap: wrap; gap: 6px; }
.unscheduled-posts .day-empty { grid-column: 1 / -1; padding: var(--space-6); border-radius: var(--radius-lg); background: var(--color-tile); }

/* ---- Dialogs and sheets ---- */
/* Native dialogs give keyboard focus containment and Escape. On a phone they rise from the bottom edge. */
dialog { padding: var(--space-6); border: 0; border-radius: var(--radius-xl); background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sheet); }
dialog[open] { animation: sheet-in var(--duration) var(--ease-out); }
dialog::backdrop { background: var(--color-scrim); animation: fade-in var(--duration) ease-out; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(16px) scale(.985); } }
@keyframes fade-in { from { opacity: 0; } }
.brand-dialog { width: 520px; max-width: calc(100% - 32px); max-height: calc(100dvh - 48px); overflow-y: auto; overscroll-behavior: contain; padding: 0 var(--space-6) var(--space-6); }
.dialog-heading { position: sticky; top: 0; z-index: 6; display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); margin: 0 calc(-1 * var(--space-6)) var(--space-2); padding: var(--space-4) var(--space-4) var(--space-3) var(--space-6);
  background: rgba(255, 255, 255, .88); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); }
.dialog-heading h2 { font-size: var(--text-title-3); }
.dialog-heading .button-square { width: 36px; min-width: 36px; min-height: 36px; height: 36px; font-size: 18px; color: var(--color-text-2); background: var(--color-tile); }
.confirm-sheet { width: 400px; max-width: calc(100% - 32px); padding: var(--space-6); }
.confirm-title { font-size: var(--text-title-3); }
.confirm-message { margin-top: 6px; font-size: var(--text-body); white-space: pre-line; overflow-wrap: anywhere; }
.confirm-list { margin: 10px 0 0; padding-left: 20px; color: var(--color-text-2); font-size: var(--text-footnote); overflow-wrap: anywhere; }
.confirm-list li + li { margin-top: 4px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); }
.confirm-actions button { min-width: 96px; min-height: 44px; }

/* ---- Post editor: fields shared by the editor dialog ---- */
.editor-state { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.copy-label { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: var(--space-4); }
.copy-label label { margin: 0; }
.copy-label button { min-height: 32px; font-size: var(--text-footnote); }
.platform-picker { margin-top: var(--space-4); }
.platform-picker legend, .visual-style-picker legend { margin-bottom: 6px; padding: 0; color: var(--color-text); font-size: var(--text-footnote); font-weight: 600; }
.platform-chips { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; }
.platform-chips label { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; margin: 0; padding: 0 14px 0 12px; border-radius: var(--radius-control); background: var(--color-fill); color: var(--color-text); cursor: pointer; font-size: var(--text-footnote); font-weight: 500;
  transition: background-color var(--duration-fast), color var(--duration-fast); }
.platform-chips label:hover { background: var(--color-fill-hover); }
.platform-chips label:has(input:checked) { background: var(--color-accent-soft); color: var(--color-accent-text); box-shadow: inset 0 0 0 1.5px var(--color-accent); font-weight: 600; }
.platform-chips label:has(input:focus-visible) { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.platform-chips label:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.planning-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-4); }
.planning-fields label { margin-top: 0; }
#editor-message { padding: 10px 0 0; color: var(--color-success); font-weight: 500; }
.editor-conflict { margin-top: var(--space-4); padding: 12px 14px; border-radius: var(--radius-md); background: var(--color-warning-soft); }
.editor-conflict p { margin-bottom: 10px; font-size: var(--text-footnote); color: var(--color-warning); }
.editor-save-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.editor-images { margin-top: var(--space-6); padding-top: var(--space-5); border-top: 1px solid var(--color-separator); }
.images-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.image-ai-label { padding: 2px 8px; border-radius: var(--radius-badge); background: var(--color-fill); color: var(--color-text-2); font-size: 11px; font-weight: 600; letter-spacing: .04em; }
.image-status { margin: 10px 0 12px; }
.image-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.image-option { display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch; min-width: 0; min-height: 0; padding: 4px; border-radius: var(--radius-md); background: var(--color-surface); box-shadow: inset 0 0 0 1px var(--color-separator); color: var(--color-text); text-align: left; overflow: hidden; }
.image-option:hover:not(:disabled), .image-option[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--color-accent-border); }
.image-option.is-selected { box-shadow: inset 0 0 0 2px var(--color-accent); }
.image-option img { display: block; width: 100%; height: auto; aspect-ratio: 4 / 5; max-height: 156px; object-fit: cover; border-radius: var(--radius-sm); background: var(--color-fill); }
.image-option-label { display: flex; flex-direction: column; gap: 2px; padding: 6px 4px 4px; font-size: var(--text-caption); font-weight: 500; line-height: 1.35; overflow-wrap: anywhere; }
.image-option-selected { color: var(--color-success); font-size: var(--text-caption); font-weight: 600; }
.image-load-failed::before { content: 'Podgląd niedostępny'; display: grid; place-items: center; min-height: 80px; padding: 8px; border-radius: var(--radius-sm); background: var(--color-fill); color: var(--color-text-2); font-size: var(--text-caption); font-weight: 400; }
.image-preview { margin: var(--space-4) 0 0; border-radius: var(--radius-md); overflow: hidden; background: var(--color-fill-soft); }
.image-preview-photo { display: block; width: 100%; height: auto; max-height: 365px; object-fit: contain; }
.image-preview figcaption { padding: 10px 14px 12px; }
.image-preview figcaption strong { font-size: var(--text-footnote); overflow-wrap: anywhere; }
.image-preview figcaption p { margin-top: 2px; font-size: var(--text-caption); overflow-wrap: anywhere; }
.image-load-error { padding: 20px 16px; background: var(--color-warning-soft); color: var(--color-warning); font-size: var(--text-footnote); }
.image-selection-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 12px; }
.image-download { display: inline-flex; align-items: center; min-height: var(--control-height); font-size: var(--text-footnote); font-weight: 500; }
.image-generation { margin-top: 12px; }
.image-generation details { color: var(--color-text-2); font-size: var(--text-footnote); }
.image-generation summary { width: fit-content; min-height: 40px; padding: 10px 0; color: var(--color-accent-text); font-weight: 600; }
.image-generation label { margin-top: 4px; }
.image-generation-actions { display: flex; flex-wrap: wrap; gap: 4px 8px; margin: 6px 0 0 -10px; }
#image-action-help { color: var(--color-warning); }

@media (max-width: 1080px) {
  .week-brief-panel > div { display: block; }
}
@media (max-width: 900px) {
  /* The week becomes an agenda: one row per day. */
  .calendar { display: flex; flex-direction: column; }
  .calendar { gap: 0; padding: var(--space-1) var(--space-3); }
  .calendar-day { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: 0 12px; align-items: start; min-height: 0; padding: 12px 0; border-radius: 0; }
  .calendar-day + .calendar-day { box-shadow: 0 -1px 0 var(--color-separator); }
  .day-heading { align-items: center; padding: 0; }
  .day-content { grid-column: 2; gap: 8px; }
  .calendar-post { padding: 10px 12px; }
  .calendar-post > strong { font-size: var(--text-body); }
  .calendar-post .channel-label, .calendar-image-status, .calendar-post .status-badge { font-size: var(--text-caption); }
  .calendar-thumbnail { max-width: 160px; }
  .day-add { align-self: flex-start; width: auto; margin: 0; padding: 0 14px; min-height: var(--control-height); }
  .unscheduled-posts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .workspace { padding: 0 16px; }
  .page-heading { flex-wrap: wrap; align-items: flex-start; padding: var(--space-2) 0 var(--space-4); }
  .page-heading p { font-size: var(--text-body); }
  .week-navigation { flex-wrap: wrap; }
  .week-navigation h2 { padding: 0 4px; font-size: 19px; }
  .day-name { font-size: var(--text-caption); }
  .week-brief-panel { padding: var(--space-4); }
  .week-brief-fields { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .week-brief-actions { flex-direction: column; align-items: stretch; gap: 10px; }
  .planning-fields { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
  .unscheduled-posts { grid-template-columns: 1fr; }
  .editor-save-actions button { flex: 1 1 auto; }
  /* 16 px keeps iOS from zooming into a focused field. */
  input, textarea, select { font-size: 16px; }
  /* Sheets rise from the bottom edge. */
  dialog.brand-dialog, dialog.confirm-sheet { position: fixed; inset: auto 0 0 0; width: 100%; max-width: 100%; max-height: calc(100dvh - 40px); margin: 0; border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom)); }
  dialog.brand-dialog[open], dialog.confirm-sheet[open] { animation-name: sheet-up; }
  .confirm-actions { flex-direction: column-reverse; }
  .confirm-actions button { width: 100%; }
  /* Messages sit just above the tab bar; Powiadomienia opens under the top bar. */
  .notification-region { left: 12px; right: 12px; bottom: calc(96px + env(safe-area-inset-bottom)); width: auto; }
  .history-dialog { inset: 68px 12px auto 12px; width: auto; max-width: none; max-height: calc(100dvh - 180px); }
}
@keyframes sheet-up { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
