/* Docshar AI editor styles (js/ai-editor.js): header button, AI panel (side panel / phone bottom sheet), Fill with AI box. */

/* Header button */
.ai-head-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 8px;
  font-size: 14px; font-weight: 600; color: #4338ca; flex-shrink: 0;
  background: linear-gradient(#fff, #fff) padding-box, linear-gradient(135deg, #1f6bff, #5b1cff) border-box;
  border: 1px solid transparent; transition: background .15s, color .15s;
}
.ai-head-btn:hover { background: linear-gradient(#eef2ff, #eef2ff) padding-box, linear-gradient(135deg, #1f6bff, #5b1cff) border-box; }
.ai-head-btn[data-active="true"] { color: #fff; background: linear-gradient(135deg, #1f6bff, #5b1cff) border-box; }
.ai-head-btn:focus-visible, #aiPanel button:focus-visible, .aip-fill button:focus-visible { outline: 2px solid #6366f1; outline-offset: 2px; }

/* Panel */
#aiPanel:not(.hidden) {
  width: 360px; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0;
  background: #fff; border-left: 1px solid #e2e8f0; position: relative; z-index: 26;
}
.aip-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 10px 16px; border-bottom: 1px solid #f1f5f9; }
.aip-logo { width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; background: #fff; border: 1px solid #ede9fe; }
.aip-logo svg { width: 17px; height: 17px; }
.aip-logo-sm { width: 28px; height: 28px; border-radius: 9px; }
.aip-logo-sm svg { width: 15px; height: 15px; }
.aip-name { font-size: 14px; font-weight: 700; color: #18181b; line-height: 1.2; }
.aip-sub { font-size: 12px; color: #64748b; line-height: 1.35; margin-top: 1px; }
.aip-icon-btn { width: 32px; height: 32px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; color: #64748b; }
.aip-icon-btn:hover { background: #f1f5f9; color: #18181b; }
.aip-icon-btn svg { width: 16px; height: 16px; }
.aip-icon-btn.aip-xs { width: 28px; height: 28px; }
.aip-icon-btn.aip-xs svg { width: 14px; height: 14px; }

/* Tabs */
.aip-tabs { display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid #f1f5f9; }
.aip-tabs [role="tab"] {
  flex: 1; height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 9px;
  font-size: 13px; font-weight: 600; color: #64748b; transition: background .15s, color .15s;
}
.aip-tabs [role="tab"] svg { width: 15px; height: 15px; }
.aip-tabs [role="tab"]:hover { background: #f8fafc; color: #27272a; }
.aip-tabs [role="tab"][aria-selected="true"] { background: #eef2ff; color: #4338ca; box-shadow: inset 0 0 0 1px #c7d2fe; }

.aip-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.aip-pane[hidden] { display: none; }
.aip-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 14px 10px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.aip-foot span:first-child { overflow: hidden; text-overflow: ellipsis; }
.aip-foot { display: flex; justify-content: space-between; gap: 8px; white-space: nowrap; overflow: hidden; padding: 7px 14px; border-top: 1px solid #f1f5f9; font-size: 11px; color: #94a3b8; }

/* Composer */
.aip-composer { padding: 8px 12px 12px; border-top: 1px solid #f1f5f9; }
.aip-inputrow { display: flex; align-items: flex-end; gap: 6px; border: 1px solid #e2e8f0; border-radius: 14px; padding: 5px 5px 5px 12px; background: #fff; transition: border-color .15s, box-shadow .15s; }
.aip-inputrow:focus-within { border-color: #a5b4fc; box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.aip-inputrow textarea, .aip-inputrow input { flex: 1; min-width: 0; border: 0; outline: none; resize: none; font-size: 14px; line-height: 20px; padding: 6px 0; color: #27272a; background: transparent; max-height: 140px; }
.aip-inputrow textarea:disabled { cursor: not-allowed; }
.aip-send, .aip-mic { width: 32px; height: 32px; flex-shrink: 0; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; transition: background .15s, color .15s; }
.aip-send { color: #fff; background: #4f46e5; }
.aip-send:hover:not(:disabled) { background: #4338ca; }
.aip-send:disabled, .aip-mic:disabled, .aip-lang:disabled { opacity: .45; cursor: not-allowed; }
.aip-send svg, .aip-mic svg { width: 16px; height: 16px; }
.aip-mic { color: #52525b; }
.aip-mic:hover:not(:disabled) { background: #f1f5f9; color: #18181b; }
.aip-mic[data-on="true"] { color: #fff; background: #e11d48; animation: aip-pulse 1.4s ease-in-out infinite; }
@keyframes aip-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(225,29,72,.45); } 50% { box-shadow: 0 0 0 6px rgba(225,29,72,0); } }
.aip-lang { height: 32px; min-width: 30px; padding: 0 4px; flex-shrink: 0; border-radius: 8px; font-size: 11px; font-weight: 700; color: #64748b; }
.aip-lang:hover:not(:disabled) { background: #f1f5f9; color: #18181b; }
.aip-tool-hint { margin-bottom: 8px; }
.aip-tool-hint.hidden { display: none; }

/* Chips */
.aip-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.aip-empty .aip-chips { justify-content: center; margin-top: 14px; }
.aip-chips-tail { margin-top: 2px; }
.aip-chip { height: 30px; padding: 0 11px; border-radius: 999px; font-size: 12.5px; font-weight: 500; color: #3f3f46; background: #fff; border: 1px solid #e2e8f0; display: inline-flex; align-items: center; gap: 6px; transition: border-color .15s, background .15s, color .15s; }
.aip-chip:hover { border-color: #a5b4fc; background: #eef2ff; color: #4338ca; }
.aip-chip svg { width: 13px; height: 13px; }
.aip-chip-tool { color: #4338ca; border-color: #c7d2fe; background: #eef2ff; }

/* Empty states */
.aip-empty { text-align: center; padding: 22px 8px 8px; margin: auto 0; }
.aip-empty-ico { width: 44px; height: 44px; margin: 0 auto 10px; border-radius: 14px; display: flex; align-items: center; justify-content: center; color: #4f46e5; background: #eef2ff; }
.aip-empty-ico svg { width: 22px; height: 22px; }
.aip-empty-title { font-size: 15px; font-weight: 700; color: #18181b; }
.aip-empty p { margin-top: 6px; font-size: 13px; line-height: 1.55; color: #64748b; }

/* Chat messages */
.aip-msg { display: flex; flex-direction: column; max-width: 100%; }
.aip-msg.user { align-items: flex-end; }
.aip-bubble { font-size: 13.5px; line-height: 1.55; color: #27272a; overflow-wrap: anywhere; }
.aip-msg.user .aip-bubble { max-width: 88%; padding: 8px 12px; border-radius: 14px 14px 4px 14px; color: #fff; background: #4f46e5; white-space: pre-wrap; }
.aip-msg.bot .aip-bubble { padding: 10px 12px; border-radius: 14px 14px 14px 4px; background: #f8fafc; border: 1px solid #eef2f7; }
.aip-bubble p + p, .aip-bubble p + ul, .aip-bubble ul + p, .aip-bubble p + ol, .aip-bubble ol + p { margin-top: 8px; }
.aip-bubble ul, .aip-bubble ol { padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }
.aip-bubble ul { list-style: disc; }
.aip-bubble ol { list-style: decimal; }
.aip-bubble b { font-weight: 650; color: #18181b; }
.aip-msg.err .aip-bubble { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 9px 12px; border-radius: 12px; color: #9f1239; background: #fff1f2; border: 1px solid #fecdd3; font-size: 13px; }
.aip-msg.err .aip-bubble svg { width: 16px; height: 16px; flex-shrink: 0; }
.aip-msg.err .aip-bubble span { flex: 1; min-width: 60%; }
.aip-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 4px; padding-left: 2px; }
.aip-meta-label { font-size: 11px; font-weight: 600; color: #94a3b8; margin-right: 2px; }
.aip-page { min-width: 28px; height: 24px; padding: 0 7px; border-radius: 7px; font-size: 12px; font-weight: 600; color: #4338ca; background: #eef2ff; border: 1px solid #e0e7ff; flex-shrink: 0; }
.aip-page:hover { background: #e0e7ff; border-color: #a5b4fc; }
.aip-inline-page { color: #4338ca; font-weight: 600; text-decoration: underline; text-decoration-color: #a5b4fc; text-underline-offset: 2px; }
.aip-inline-page:hover { text-decoration-color: #4338ca; }
.aip-note { align-self: center; max-width: 92%; text-align: center; font-size: 12px; line-height: 1.5; color: #64748b; background: #f8fafc; border-radius: 10px; padding: 6px 10px; }
.aip-link { color: #4f46e5; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.aip-link:hover { color: #3730a3; }
.aip-loading { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: #f8fafc; border: 1px dashed #c7d2fe; font-size: 13px; color: #4338ca; }

/* Cards */
.aip-card { border: 1px solid #e2e8f0; border-radius: 14px; padding: 12px; background: #fff; }
.aip-card p { font-size: 13px; line-height: 1.55; color: #52525b; }
.aip-card-title { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 700; color: #18181b; margin-bottom: 6px; }
.aip-card-title svg { width: 17px; height: 17px; flex-shrink: 0; }
.aip-card-label { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: #94a3b8; margin-bottom: 6px; }
.aip-card-label .aip-link { text-transform: none; letter-spacing: 0; }
.aip-warn { border-color: #fde68a; background: #fffbeb; }
.aip-warn .aip-card-title svg { color: #d97706; }
.aip-ok { border-color: #a7f3d0; background: #ecfdf5; }
.aip-ok .aip-card-title svg { color: #059669; }
.aip-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.aip-center { justify-content: center; }
.ai-btn.aip-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.ai-btn svg { width: 15px; height: 15px; }
.aip-muted { font-size: 12.5px; color: #64748b; }
.aip-warn-text { margin-top: 8px; font-size: 12px !important; line-height: 1.5; color: #92400e !important; background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 7px 10px; }
.aip-ok-text { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 13px; color: #047857; }
.aip-ok-text svg { width: 16px; height: 16px; }
.aip-summary { font-size: 13px; line-height: 1.5; color: #3f3f46; }
.aip-instr { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; font-weight: 600; color: #27272a; background: #f8fafc; border-radius: 10px; padding: 8px 10px; }
.aip-instr svg { width: 15px; height: 15px; margin-top: 2px; flex-shrink: 0; color: #6366f1; }

/* Change preview list (edits and form fill) */
.aip-list-head { display: flex; align-items: center; justify-content: space-between; }
.aip-check { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: #3f3f46; cursor: pointer; }
.aip-changes { display: flex; flex-direction: column; gap: 6px; }
.aip-changes li { display: flex; align-items: flex-start; gap: 6px; border: 1px solid #e2e8f0; border-radius: 12px; padding: 8px 8px 8px 10px; background: #fff; transition: opacity .15s, border-color .15s; }
.aip-changes li:hover { border-color: #c7d2fe; }
.aip-changes li.off { opacity: .55; }
.aip-change { flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: 9px; cursor: pointer; }
.aip-change input, .aip-check input { width: 16px; height: 16px; margin-top: 2px; flex-shrink: 0; accent-color: #4f46e5; }
.aip-change-body { min-width: 0; flex: 1; }
.aip-ctx { font-size: 12.5px; line-height: 1.55; color: #64748b; overflow-wrap: anywhere; }
.aip-ctx del { color: #be123c; background: #ffe4e6; text-decoration-color: rgba(190,18,60,.6); border-radius: 3px; padding: 0 2px; }
.aip-ctx ins { color: #047857; background: #d1fae5; text-decoration: none; border-radius: 3px; padding: 0 2px; margin-left: 3px; font-weight: 600; }
.aip-missing { padding: 0 2px; }
.aip-field-name { display: block; font-size: 11px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: #94a3b8; }
.aip-field-val { display: block; font-size: 13.5px; font-weight: 600; color: #18181b; overflow-wrap: anywhere; }
.aip-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; position: sticky; bottom: -10px; background: linear-gradient(transparent, #fff 30%); padding: 10px 0 2px; }
.aip-actions .ai-btn { height: 38px; }

/* Rewrite */
.aip-quote { font-size: 13.5px; line-height: 1.55; color: #27272a; max-height: 9.3em; overflow-y: auto; white-space: pre-wrap; overflow-wrap: anywhere; border-left: 3px solid #c7d2fe; padding-left: 10px; }
.aip-actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.aip-action { height: 38px; display: inline-flex; align-items: center; gap: 8px; padding: 0 11px; border-radius: 11px; border: 1px solid #e2e8f0; background: #fff; font-size: 13px; font-weight: 500; color: #3f3f46; text-align: left; transition: border-color .15s, background .15s, color .15s; }
.aip-action:hover { border-color: #a5b4fc; background: #eef2ff; color: #4338ca; }
.aip-action svg { width: 15px; height: 15px; color: #6366f1; flex-shrink: 0; }
.aip-custom { margin-top: 2px; }
.aip-result { border-color: #c7d2fe; box-shadow: 0 6px 20px -12px rgba(79,70,229,.35); }
.aip-compare { display: flex; flex-direction: column; gap: 6px; }
.aip-old { font-size: 13px; line-height: 1.5; color: #9f1239; background: #fff1f2; border-radius: 10px; padding: 8px 10px; text-decoration: line-through; text-decoration-color: rgba(159,18,57,.45); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 8em; overflow-y: auto; }
.aip-arrow { width: 16px; height: 16px; color: #94a3b8; align-self: center; }
.aip-new { width: 100%; font-size: 13.5px; line-height: 1.5; color: #064e3b; background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 10px; padding: 8px 10px; resize: vertical; min-height: 64px; }
.aip-new:focus { outline: none; border-color: #34d399; box-shadow: 0 0 0 3px rgba(16,185,129,.15); }

/* Fill with AI (Fill & Sign tool page) */
.aip-fill { border: 1px solid #c7d2fe; border-radius: 16px; padding: 14px; margin-bottom: 18px; background: linear-gradient(180deg, #f5f7ff, #fff 70%); display: flex; flex-direction: column; gap: 10px; }
.aip-fill-head { display: flex; align-items: flex-start; gap: 10px; }
.aip-fill .aip-changes { margin-top: 2px; }
.aip-fill .aip-actions { position: static; background: none; padding-top: 4px; }
.aip-filled { border-color: #34d399 !important; box-shadow: 0 0 0 3px rgba(16,185,129,.2) !important; transition: box-shadow .3s, border-color .3s; }

/* Find & replace bar moves left of the open panel */
@media (min-width: 640px) { #aiPanel:not(.hidden) ~ #findBar { right: 376px; left: auto; } }

/* Touch screens: bigger targets */
@media (pointer: coarse) {
  .aip-send, .aip-mic { width: 38px; height: 38px; }
  .aip-lang { height: 38px; }
  .aip-chip { height: 34px; }
  .aip-page { min-width: 32px; height: 30px; }
  .aip-icon-btn.aip-xs { width: 34px; height: 34px; }
}

/* Tablets: the panel floats over the stage instead of squeezing the page */
@media (min-width: 640px) and (max-width: 1023px) {
  #aiPanel:not(.hidden) { position: absolute; right: 0; top: 0; bottom: 0; box-shadow: -12px 0 32px -12px rgba(15,23,42,.3); }
}

/* Phones: bottom sheet */
@media (max-width: 639px) {
  .ai-head-btn { height: 36px; padding: 0 10px; }
  .ai-head-btn svg { display: none; }   /* "AI" alone keeps room for the file name */
  #aiPanel:not(.hidden) {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; height: 78vh; height: 78dvh; z-index: 47;
    border-left: 0; border-top: 1px solid #e2e8f0; border-radius: 18px 18px 0 0;
    box-shadow: 0 -16px 40px -12px rgba(15,23,42,.32);
    padding-bottom: env(safe-area-inset-bottom);
  }
  #aiPanel:not(.hidden)::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 4px; background: #cbd5e1; margin: 8px auto 0; flex-shrink: 0; }
  .aip-head { padding-top: 6px; }
  .aip-inputrow textarea, .aip-inputrow input { font-size: 16px; }   /* no zoom-on-focus in iOS Safari */
  .aip-fill { padding: 12px; }
}
.ai-head-btn[data-active="true"] .ai-icon-btn { background-color: #fff; border-radius: 50%; }
