/* Saad AI Chat widget — voice-first layout (wireframe 1c).
   The mic is the primary control; typing, photo and sensors live behind chips.
   Static, full-container width, grows with content.
   Fonts and font-sizes INHERIT from the theme.
   Colors resolve from theme/Elementor/WP global tokens first,
   falling back to the plugin palette only when none are defined. */

.saad-chat{
	/* Accent (dark olive) — bot bubble, avatar, mic, send button */
	--saad-accent: var(--e-global-color-primary, var(--wp--preset--color--primary, #4b5a34));
	/* User (outgoing) bubble — pale sage */
	--saad-user-bg: var(--e-global-color-accent, var(--wp--preset--color--secondary, #dbe4c0));
	/* Surfaces */
	--saad-surface: #ffffff;
	--saad-header-bg: #eef1e8;
	--saad-input-bg: #eef1e8;
	/* Text */
	--saad-text: var(--e-global-color-text, var(--wp--preset--color--foreground, #2b2f26));
	--saad-bot-text: #ffffff;
	--saad-user-text: #384325;
	--saad-muted: color-mix(in srgb, var(--saad-text) 55%, transparent);
	/* Lines / effects */
	--saad-border: color-mix(in srgb, var(--saad-text) 10%, transparent);
	--saad-radius: 24px;
	--saad-shadow: 0 24px 48px -16px rgba(40,50,25,.25), 0 6px 16px -8px rgba(40,50,25,.14);

	position: relative;          /* inline in the page flow; anchors the tools sheet */
	width: 100%;
	min-height: 500px;           /* grows dynamically beyond this */
	margin: 0;
	background: var(--saad-surface);
	color: var(--saad-text);
	font: inherit;               /* inherit family + size from theme */
	border: 1px solid var(--saad-border);
	border-radius: var(--saad-radius);
	box-shadow: var(--saad-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}
.saad-chat *{ box-sizing: border-box; }
.saad-chat [hidden]{ display: none !important; }

/* ---------- Header ---------- */
.saad-chat__header{
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 18px 24px;
	background: var(--saad-header-bg);
	border-bottom: 1px solid var(--saad-border);
}
.saad-avatar{
	flex: 0 0 auto;
	width: 52px; height: 52px;
	border-radius: 50%;
	background: var(--saad-accent);
	color: #fff;
	display: flex; align-items: center; justify-content: center;
	font-weight: 700; font-size: 1.2em;
	overflow: hidden;
}
.saad-avatar img{ width: 100%; height: 100%; object-fit: cover; }
.saad-chat__id{ display: flex; flex-direction: column; gap: 2px; line-height: 1.25; min-width: 0; }
.saad-chat__name{ font-weight: 700; font-size: 1.05em; }
.saad-chat__role{ font-size: .85em; color: var(--saad-muted); }
.saad-chat__status{ margin-left: 10px; font-size: .75em; color: var(--saad-muted); white-space: nowrap; }

/* ---------- Chips (shared data, mode switch, tools) ---------- */
.saad-chip{
	display: inline-flex; align-items: center; gap: 6px;
	border: 1px solid var(--saad-border);
	background: var(--saad-header-bg);
	color: var(--saad-text);
	border-radius: 2em;
	padding: 7px 14px;
	font: inherit; font-size: .85em;
	cursor: pointer;
	line-height: 1.2;
}
.saad-chip:hover{ filter: brightness(.96); }
.saad-chip:disabled{ opacity: .5; cursor: not-allowed; }
.saad-chip--tts{ margin-left: auto; flex: 0 0 auto; }
.saad-chip--tts.is-off{ opacity: .65; }
.saad-chip--shared{ background: var(--saad-user-bg); color: var(--saad-user-text); cursor: default; }
.saad-chip__x{
	border: none; background: transparent; color: inherit;
	cursor: pointer; font-size: .9em; line-height: 1; padding: 0 0 0 2px;
}

/* ---------- Messages ---------- */
.saad-chat__box{
	flex: 1 1 auto;              /* fill to reach min-height, then grow */
	min-height: 250px;
	max-height: 350px;
	overflow-y: auto;
	padding: 24px 24px;
	display: flex;
	flex-direction: column;
	gap: 16px;
	background: var(--saad-surface);
	scroll-behavior: auto;
}
.saad-chat[data-fresh="1"] .saad-chat__box{ min-height: 120px; } /* leave room for the hero mic */

.saad-msg{
	max-width: 82%;
	padding: 15px 20px;
	border-radius: 22px;
	line-height: 1.55;
	word-wrap: break-word;
	white-space: normal;
}
.saad-msg--bot{
	align-self: flex-start;
	background: var(--saad-accent);
	color: var(--saad-bot-text);
	border-bottom-left-radius: 6px;
}
.saad-msg--user{
	align-self: flex-end;
	padding: 13px 18px;
	background: var(--saad-user-bg);
	color: var(--saad-user-text);
	border-bottom-right-radius: 6px;
}
.saad-msg a{ text-decoration: underline; color: inherit; }
.saad-typing{ opacity: .7; font-style: italic; }
.saad-speaking{
	align-self: flex-start;
	font-size: .8em;
	color: var(--saad-muted);
	cursor: pointer;
	margin: -8px 0 0 8px;
}

/* ---------- Shared-data chips row (above the bar) ---------- */
.saad-chips{
	display: flex; flex-wrap: wrap; gap: 8px;
	padding: 10px 24px 0;
}

/* ---------- Voice stage: the mic IS the interface ---------- */
.saad-stage{
	display: flex; flex-direction: column; align-items: center; gap: 8px;
	padding: 16px 20px 6px;
	border-top: 1px solid var(--saad-border);
}
.saad-stage__ring{ position: relative; display: flex; }
.saad-mic{
	width: 60px; height: 60px;
	border: none; border-radius: 50%;
	background: var(--saad-accent); color: #fff;
	display: flex; align-items: center; justify-content: center;
	cursor: pointer; padding: 0;
	box-shadow: 0 10px 22px -10px rgba(40,50,25,.55);
	transition: width .15s, height .15s;
}
.saad-mic svg{ width: 26px; height: 26px; display: block; }
.saad-mic:hover{ filter: brightness(1.06); }
.saad-mic:disabled{ opacity: .5; cursor: not-allowed; }
.saad-mic.is-rec{ background: #c0492f; animation: saadPulse 1s infinite; }
@keyframes saadPulse{ 0%,100%{opacity:1} 50%{opacity:.55} }

/* First visit: hero mic with a dashed ring, label and example */
.saad-chat[data-fresh="1"] .saad-mic{ width: 92px; height: 92px; }
.saad-chat[data-fresh="1"] .saad-mic svg{ width: 38px; height: 38px; }
.saad-chat[data-fresh="1"] .saad-stage{ padding: 26px 20px 10px; gap: 12px; }
.saad-chat[data-fresh="1"] .saad-stage__ring::before{
	content: "";
	position: absolute; inset: -14px;
	border: 3px dashed var(--saad-accent);
	border-radius: 50%;
	opacity: .4;
	animation: saadSpin 16s linear infinite;
}
@keyframes saadSpin{ to{ transform: rotate(360deg); } }
.saad-stage__label{ font-weight: 600; }
.saad-stage__hint{ font-size: .85em; color: var(--saad-muted); }
.saad-chat:not([data-fresh="1"]) .saad-stage__hint{ display: none; }
.saad-chat:not([data-fresh="1"]) .saad-stage__label{
	font-weight: 400; font-size: .8em; color: var(--saad-muted);
}

/* ---------- Type bar (fallback mode) ---------- */
.saad-typebar{
	display: flex; align-items: center; gap: 12px;
	padding: 16px 20px 4px;
	border-top: 1px solid var(--saad-border);
}
.saad-input{
	flex: 1; min-width: 0;
	border: none;
	background: var(--saad-input-bg);
	color: var(--saad-text);
	border-radius: 30px;
	padding: 14px 20px;
	font: inherit;
}
.saad-input::placeholder{ color: var(--saad-muted); }
.saad-input:focus{ outline: 2px solid var(--saad-accent); outline-offset: 1px; }
.saad-send{
	flex: 0 0 auto;
	display: inline-flex; align-items: center; justify-content: center;
	width: 48px; height: 48px;
	background: var(--saad-accent); color: #fff;
	border: none; border-radius: 50%;
	padding: 0; cursor: pointer;
}
.saad-send:hover{ filter: brightness(1.06); }
.saad-send:disabled{ opacity: .5; cursor: not-allowed; }
.saad-send svg{ display: block; }

/* ---------- Bottom chips: mode switch · photo · more… ---------- */
.saad-modebar{
	display: flex; align-items: center; justify-content: center; gap: 10px;
	flex-wrap: wrap;
	padding: 12px 20px 16px;
}

/* ---------- Tools sheet ("more…") ---------- */
.saad-sheet{
	position: absolute; inset: 0;
	background: color-mix(in srgb, var(--saad-text) 35%, transparent);
	display: flex; align-items: flex-end; justify-content: center;
	z-index: 9;
}
.saad-sheet__panel{
	width: 100%; max-width: 460px;
	background: var(--saad-surface);
	border-radius: 18px 18px 0 0;
	padding: 14px 16px 18px;
	box-shadow: 0 -10px 30px rgba(0,0,0,.18);
	animation: saadUp .18s ease-out;
}
@keyframes saadUp{ from{ transform: translateY(28px); opacity: .4; } to{ transform: none; opacity: 1; } }
.saad-sheet__grab{
	width: 40px; height: 4px; border-radius: 2px;
	background: color-mix(in srgb, var(--saad-text) 25%, transparent);
	margin: 0 auto 12px;
}
.saad-sheet__title{ font-weight: 600; margin-bottom: 10px; }
.saad-sheet__grid{
	display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.saad-tile{
	display: flex; flex-direction: column; align-items: center; gap: 6px;
	border: 1px solid var(--saad-border); border-radius: 12px;
	padding: 12px 6px;
	background: var(--saad-header-bg); color: var(--saad-text);
	font: inherit; font-size: .85em; text-align: center;
	cursor: pointer;
}
.saad-tile:hover{ background: var(--saad-user-bg); }
.saad-tile__emoji{ font-size: 1.5em; line-height: 1; }
.saad-sheet__detail{
	display: flex; flex-direction: column; gap: 8px;
	margin-top: 12px; padding-top: 12px;
	border-top: 1px solid var(--saad-border);
}
.saad-sheet__detail .saad-input{ padding: 11px 16px; }
.saad-sheet__detail .saad-chip{ align-self: flex-start; background: var(--saad-user-bg); color: var(--saad-user-text); }

/* ---------- Desktop ---------- */
@media (min-width: 700px){
	.saad-chat__box{ max-height: 420px; padding: 28px 32px; }
	.saad-chips{ padding: 10px 32px 0; }
	.saad-typebar{ padding: 18px 28px 4px; }
	.saad-modebar{ padding: 14px 28px 20px; }
	.saad-chat[data-fresh="1"] .saad-mic{ width: 104px; height: 104px; }
	.saad-chat[data-fresh="1"] .saad-mic svg{ width: 42px; height: 42px; }
	.saad-sheet__panel{ border-radius: 18px; margin-bottom: 16px; }
}
