:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #68736e;
  --canvas: #f2f4f1;
  --surface: #ffffff;
  --soft: #f6f7f5;
  --line: #dfe4e0;
  --accent: #0f7658;
  --accent-dark: #09573f;
  --accent-soft: #e4f2ed;
  --danger: #ad423c;
  --warning: #a95e17;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input, textarea { font: inherit; }
button, a, label { -webkit-tap-highlight-color: transparent; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { position: fixed; inset: 0; width: min(1440px, 100%); height: 100vh; height: 100dvh; max-height: 100dvh; margin: 0 auto; overflow: hidden; overflow-anchor: none; display: grid; grid-template-rows: auto minmax(0, 1fr); background: var(--surface); border-inline: 1px solid var(--line); }
.topbar { position: relative; z-index: 20; min-height: 76px; display: flex; align-items: center; gap: 13px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.97); backdrop-filter: blur(12px); }
.brand-mark, .avatar { display: grid; place-items: center; flex: 0 0 auto; color: white; background: var(--accent); font-weight: 800; }
.brand-mark { width: 42px; height: 42px; border-radius: 13px; font-family: Georgia, serif; font-size: 1.25rem; }
.brand-copy h1 { margin: 0; font-size: 1.05rem; letter-spacing: -.01em; }
.brand-copy p { margin: 3px 0 0; color: var(--muted); font-size: .8rem; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.workflow-status { display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 0 12px; color: var(--accent-dark); background: var(--accent-soft); border-radius: 999px; font-size: .78rem; font-weight: 700; }
.workflow-status > span, .account-status > span { width: 7px; height: 7px; border-radius: 50%; background: #21a575; box-shadow: 0 0 0 3px rgba(33,165,117,.12); }
.icon-button { min-height: 36px; padding: 0 12px; color: var(--muted); background: white; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: .8rem; font-weight: 700; }
.icon-button:hover { color: var(--ink); border-color: #bcc6c0; }

.chat-panel { min-width: 0; min-height: 0; overflow: hidden; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.chat-log { min-height: 0; overflow-y: auto; overflow-anchor: none; overscroll-behavior: contain; padding: 30px clamp(18px, 4vw, 58px) 40px; scroll-behavior: smooth; }
.message-row { width: min(1260px, 100%); margin: 0 auto 28px; display: flex; gap: 12px; }
.assistant-row { align-items: flex-start; }
.user-row { justify-content: flex-end; }
.avatar { width: 34px; height: 34px; border-radius: 10px; font-family: Georgia, serif; font-size: .9rem; }
.message-stack { min-width: 0; max-width: 980px; }
.assistant-label { margin: 0 0 7px; color: var(--muted); font-size: .73rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.assistant-bubble, .user-bubble, .publish-bubble { border-radius: 16px; line-height: 1.55; }
.assistant-bubble { max-width: 650px; padding: 13px 16px; background: var(--soft); border: 1px solid var(--line); }
.memory-bubble { white-space: pre-wrap; }
.user-bubble { max-width: min(720px, 84%); padding: 13px 17px; color: white; background: var(--accent); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.preview-row { width: min(1320px, 100%); }
.preview-stack { width: calc(100% - 46px); max-width: none; }
.preview-intro { margin: 0 0 13px; color: var(--muted); font-size: .86rem; }
.preview-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

.post-preview { min-width: 0; display: flex; flex-direction: column; overflow: hidden; background: white; border: 1px solid var(--line); border-radius: 17px; box-shadow: 0 7px 24px rgba(23,33,29,.055); }
.post-header { display: flex; align-items: center; gap: 10px; padding: 14px 15px 12px; }
.platform-mark { width: 34px; height: 34px; display: grid; place-items: center; color: white; border-radius: 10px; font-weight: 800; font-size: .82rem; }
.facebook .platform-mark { background: #1877f2; }
.instagram .platform-mark { background: linear-gradient(135deg, #6a3edb, #d62d78 55%, #f2a23a); }
.linkedin .platform-mark { background: #0a66c2; }
.platform-title { min-width: 0; display: grid; }
.platform-title strong { font-size: .9rem; }
.platform-title small { color: var(--muted); font-size: .7rem; }
.post-status { margin-left: auto; padding: 5px 8px; color: var(--muted); background: var(--soft); border-radius: 999px; font-size: .64rem; font-weight: 800; text-transform: uppercase; letter-spacing: .045em; }
.post-status.ready, .post-status.posted { color: var(--accent-dark); background: var(--accent-soft); }
.post-status.needs_resource { color: var(--warning); background: #fff1df; }
.post-status.error { color: var(--danger); background: #fae8e7; }
.format-row { display: flex; gap: 5px; padding: 0 15px 12px; }
.format-button { min-height: 31px; padding: 0 10px; color: var(--muted); background: white; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-size: .72rem; font-weight: 700; }
.format-button:hover { border-color: var(--accent); color: var(--accent-dark); }
.format-button.selected { color: white; background: var(--accent); border-color: var(--accent); }
.format-button:focus-visible, button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(15,118,88,.22); outline-offset: 2px; }
.text-post-label { margin: 0 15px; padding: 9px 11px; color: var(--muted); background: var(--soft); border: 1px dashed #cdd5d0; border-radius: 10px; font-size: .72rem; font-weight: 700; text-align: center; }
.media-frame { position: relative; margin: 0 15px; overflow: hidden; background: #101612; border-radius: 12px; }
.media-frame img, .media-frame video { width: 100%; height: 210px; display: block; object-fit: cover; }
.media-frame video { background: #101612; }
.media-name { position: absolute; right: 8px; bottom: 8px; left: 8px; overflow: hidden; padding: 6px 8px; color: white; background: rgba(12,20,16,.72); border-radius: 7px; backdrop-filter: blur(6px); font-size: .68rem; text-overflow: ellipsis; white-space: nowrap; }
.media-dropzone { position: relative; min-height: 150px; margin: 0 15px; overflow: hidden; display: grid; place-content: center; justify-items: center; gap: 4px; color: var(--muted); background: #fafbf9; border: 1px dashed #bdc9c2; border-radius: 12px; cursor: pointer; text-align: center; }
.media-dropzone:hover { color: var(--accent-dark); border-color: var(--accent); background: #f4faf7; }
.media-dropzone input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.media-dropzone strong { font-size: .82rem; }
.media-dropzone small { font-size: .68rem; }
.upload-symbol { width: 30px; height: 30px; display: grid; place-items: center; color: white; background: var(--accent); border-radius: 9px; font-size: 1.15rem; }
.stored-media { position: relative; min-height: 92px; margin: 0 15px; padding: 14px; display: flex; align-items: center; gap: 11px; color: var(--ink); background: var(--soft); border-radius: 12px; }
.remove-media { position: absolute; top: 8px; right: 8px; z-index: 3; width: 28px; height: 28px; display: grid; place-items: center; padding: 0; color: white; background: rgba(20,28,24,.82); border: 1px solid rgba(255,255,255,.7); border-radius: 50%; cursor: pointer; font-size: 1.05rem; line-height: 1; }
.remove-media:hover { background: var(--danger); }
.stored-media div { min-width: 0; display: grid; gap: 2px; }
.stored-media strong { overflow: hidden; font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.stored-media small { color: var(--muted); font-size: .68rem; }
.file-symbol { width: 40px; height: 40px; display: grid; place-items: center; color: var(--accent-dark); background: var(--accent-soft); border-radius: 10px; font-size: .64rem; font-weight: 900; }
.post-copy { min-height: 150px; margin: 13px 15px 18px; color: #303b36; font-size: .82rem; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.post-copy.empty { color: #8a938e; font-style: italic; }
.draft-editor { margin: 13px 15px 18px; display: grid; gap: 7px; }
.draft-editor textarea { width: 100%; min-height: 150px; resize: vertical; padding: 10px; color: #303b36; background: white; border: 1px solid var(--line); border-radius: 9px; font-size: .82rem; line-height: 1.55; }
.save-draft { justify-self: end; min-height: 32px; padding: 0 11px; color: var(--accent-dark); background: var(--accent-soft); border: 1px solid #b9dace; border-radius: 8px; cursor: pointer; font-size: .7rem; font-weight: 800; }
.save-draft:hover { color: white; background: var(--accent); }
.post-error { margin: 10px 15px 0; color: var(--danger); font-size: .74rem; }
.upload-error { padding: 9px 10px; background: #fae8e7; border: 1px solid #efc9c6; border-radius: 9px; line-height: 1.4; }
.post-footer { min-height: 48px; margin-top: auto; padding: 11px 15px 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid #edf0ee; }
.account-status { min-width: 0; display: inline-flex; align-items: center; gap: 6px; color: var(--accent-dark); font-size: .69rem; font-weight: 700; }
.account-control { min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.account-status.disconnected { color: var(--muted); }
.account-status.disconnected > span { background: #9aa39f; box-shadow: 0 0 0 3px rgba(104,115,110,.12); }
.account-status.selection-required { color: #9a5a13; }
.account-status.selection-required > span { background: #d8892b; box-shadow: 0 0 0 3px rgba(216,137,43,.14); }
.facebook-account-control { width: 100%; }
.page-selector-label { min-width: 120px; flex: 1 1 150px; }
.page-selector-label select { width: 100%; min-height: 30px; padding: 0 28px 0 8px; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 8px; font-size: .69rem; font-weight: 700; }
.page-selector-label select:focus-visible { outline: 3px solid rgba(15,118,88,.22); outline-offset: 1px; }
.connect-link { display: inline-flex; min-height: 28px; align-items: center; padding: 0 9px; color: white; background: var(--accent); border-radius: 8px; font-size: .7rem; font-weight: 800; text-decoration: none; }
.reconnect-link { color: var(--accent-dark); background: var(--accent-soft); }
.connect-link:hover { text-decoration: underline; }
.attachment-note { max-width: 45%; overflow: hidden; color: var(--muted); font-size: .64rem; text-overflow: ellipsis; white-space: nowrap; }

.publish-bubble { width: min(830px, 100%); padding: 15px; display: grid; grid-template-columns: 1fr minmax(320px, 1.15fr); align-items: center; gap: 16px; background: var(--soft); border: 1px solid var(--line); }
.publish-bubble strong { font-size: .9rem; }
.publish-bubble p { margin: 4px 0 0; color: var(--muted); font-size: .76rem; }
.approval-control { display: flex; gap: 8px; }
.approval-control input { min-width: 0; width: 100%; height: 42px; padding: 0 12px; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 10px; outline: none; }
.approval-control button { min-height: 42px; padding: 0 14px; color: white; background: var(--accent); border: 0; border-radius: 10px; cursor: pointer; font-size: .76rem; font-weight: 800; white-space: nowrap; }
.approval-control button:hover, .send-button:hover { background: var(--accent-dark); }
.approval-control button:disabled { cursor: not-allowed; opacity: .5; }

.composer-shell { position: relative; z-index: 10; min-width: 0; max-height: min(42dvh, 360px); overflow-y: auto; overscroll-behavior: contain; padding: 13px clamp(18px, 4vw, 58px) 14px; border-top: 1px solid var(--line); background: rgba(255,255,255,.96); box-shadow: 0 -10px 30px rgba(23,33,29,.05); backdrop-filter: blur(14px); }
.platform-picker, .brief-mode, .composer-row, .platform-briefs, .composer-meta { width: min(1100px, 100%); margin-inline: auto; }
.platform-picker { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-bottom: 9px; }
.picker-label { margin-right: 2px; color: var(--muted); font-size: .72rem; font-weight: 700; }
.platform-picker label { cursor: pointer; }
.platform-picker input { position: absolute; opacity: 0; }
.platform-picker span:not(.picker-label) { min-height: 30px; display: grid; place-items: center; padding: 0 10px; color: var(--muted); background: white; border: 1px solid var(--line); border-radius: 999px; font-size: .72rem; font-weight: 700; }
.platform-picker input:checked + span { color: var(--accent-dark); background: var(--accent-soft); border-color: #b9dace; }
.platform-picker input:focus-visible + span { outline: 3px solid rgba(15,118,88,.22); outline-offset: 2px; }
.brief-mode { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.brief-mode-button { min-height: 28px; padding: 0 10px; color: var(--muted); background: white; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: .7rem; font-weight: 700; }
.brief-mode-button.selected { color: var(--accent-dark); background: var(--accent-soft); border-color: #b9dace; }
.platform-briefs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; align-items: end; gap: 8px; }
.platform-briefs[hidden] { display: none; }
.platform-briefs label { min-width: 0; display: grid; gap: 4px; }
.platform-briefs label > span { color: var(--muted); font-size: .68rem; font-weight: 700; }
.platform-briefs textarea { width: 100%; min-height: 64px; resize: vertical; padding: 9px 10px; color: var(--ink); background: white; border: 1px solid #cfd7d2; border-radius: 10px; line-height: 1.35; }
.platform-briefs label.inactive { display: none; }
.composer-row { display: flex; align-items: flex-end; gap: 9px; padding: 7px; background: white; border: 1px solid #cfd7d2; border-radius: 15px; box-shadow: 0 6px 22px rgba(23,33,29,.07); }
.composer-row[hidden] { display: none; }
.composer-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,118,88,.12), 0 6px 22px rgba(23,33,29,.07); }
.composer-row textarea { min-height: 42px; max-height: 160px; flex: 1; resize: none; padding: 10px 9px; color: var(--ink); background: transparent; border: 0; outline: none; line-height: 1.45; }
.send-button { min-height: 42px; padding: 0 17px; color: white; background: var(--accent); border: 0; border-radius: 10px; cursor: pointer; font-size: .78rem; font-weight: 800; }
.send-button:disabled { cursor: wait; opacity: .55; }
.composer-meta { min-height: 20px; display: flex; justify-content: space-between; gap: 14px; padding: 6px 4px 0; }
.composer-meta p { margin: 0; color: var(--muted); font-size: .67rem; }
.composer-meta strong { color: var(--ink); }

@media (max-width: 1050px) {
  .preview-grid { grid-template-columns: 1fr 1fr; }
  .post-preview.linkedin { grid-column: 1 / -1; }
  .linkedin .media-frame img, .linkedin .media-frame video { height: 300px; }
  .platform-briefs { grid-template-columns: 1fr; }
  .platform-briefs .send-button { width: 100%; }
}

@media (max-width: 720px) {
  .app-shell { border: 0; }
  .topbar { min-height: 66px; padding: 11px 14px; }
  .brand-mark { width: 38px; height: 38px; }
  .brand-copy p { display: none; }
  .workflow-status { display: none; }
  .chat-log { padding: 20px 12px 28px; }
  .message-row { gap: 8px; margin-bottom: 22px; }
  .avatar { width: 30px; height: 30px; border-radius: 9px; }
  .preview-stack { width: calc(100% - 38px); }
  .preview-grid { grid-template-columns: 1fr; }
  .post-preview.linkedin { grid-column: auto; }
  .linkedin .media-frame img, .linkedin .media-frame video, .media-frame img, .media-frame video { height: min(68vw, 340px); }
  .publish-bubble { grid-template-columns: 1fr; }
  .composer-shell { padding: 10px 12px 11px; }
  .composer-meta p:last-child { display: none; }
}

@media (max-width: 460px) {
  .topbar-actions { gap: 6px; }
  .icon-button { min-height: 34px; padding-inline: 10px; }
  .user-bubble { max-width: 90%; }
  .preview-stack { width: 100%; }
  .preview-row > .avatar { display: none; }
  .approval-control { flex-direction: column; }
  .approval-control button { width: 100%; }
  .send-button { padding-inline: 13px; }
  .composer-meta { display: block; }
}
