:root {
  --ink: #2b2b2b; --mute: #6b655d; --bg: #f3f1ec; --card: #fff; --line: #e3dfd6;
  --gold: #f2b01e; --gold-l: #fdf3da; --green: #2e7d32; --red: #c62828; --blue: #1e5aa8;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden;
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
button, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
#app { display: flex; flex-direction: column; height: 100dvh; }

.hd { background: var(--ink); color: #fff; display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-t) + 10px) 12px 10px; flex: none; }
.hd-back { color: #fff; text-decoration: none; font-weight: 600; padding: 8px 10px; border-radius: 10px; background: #ffffff1a; }
.hd-title { flex: 1; text-align: center; font-weight: 700; font-size: 19px; }
.spark { color: var(--gold); }
.hd-menu { background: #ffffff1a; border: 0; color: #fff; font-size: 22px; width: 46px; height: 42px; border-radius: 10px; }

.banner { padding: 10px 14px; font-weight: 600; font-size: 15px; flex: none; }
.banner.warn { background: #fff4d6; color: #7a5600; border-bottom: 1px solid #f0dca0; }

/* the change waiting to be tried / approved */
.change { flex: none; background: var(--gold-l); border-bottom: 2px solid var(--gold); padding: 10px 12px 12px; }
.change .ct { font-weight: 700; margin-bottom: 8px; overflow-wrap: anywhere; }
.change .ct small { display: block; font-weight: 500; color: var(--mute); font-size: 14px; }
.change .row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.cb { border: 0; border-radius: 12px; min-height: 50px; font-weight: 700; font-size: 15px; padding: 6px 4px;
  background: #fff; box-shadow: 0 1px 0 #0000001a; }
.cb.try { background: var(--blue); color: #fff; }
.cb.ok { background: var(--green); color: #fff; }
.cb:disabled { opacity: .5; }
.change .prog { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.change .err { color: var(--red); font-weight: 600; margin-top: 8px; font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }

.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 12px 20px; overscroll-behavior: contain; }
.m { max-width: 88%; margin: 0 0 12px; padding: 11px 14px; border-radius: 18px; overflow-wrap: anywhere; }
.m.user { margin-left: auto; background: var(--ink); color: #fff; border-bottom-right-radius: 6px; white-space: pre-wrap; }
.m.assistant { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; box-shadow: 0 1px 2px #0000000d; }
.m.assistant p { margin: 0 0 8px; } .m.assistant p:last-child { margin-bottom: 0; }
.m.assistant ul, .m.assistant ol { margin: 4px 0 8px; padding-left: 22px; }
.m.assistant code { background: #f3f1ec; padding: 1px 5px; border-radius: 5px; font-size: 15px; }
.m.assistant h3 { font-size: 17px; margin: 6px 0; }
.m.error { background: #fdecea; color: #8e1c1c; border: 1px solid #f5c6c2; }
.m.system { margin: 4px auto 14px; text-align: center; background: transparent; color: var(--mute); font-weight: 600; font-size: 14px; max-width: 100%; }
.when { font-size: 12px; color: var(--mute); margin-top: 4px; }
.m.user .when { color: #ffffffa0; text-align: right; }

.working { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px dashed var(--gold);
  max-width: 92%; padding: 11px 14px; border-radius: 18px; margin-bottom: 12px; }
.working .txt { flex: 1; font-weight: 600; font-size: 15px; }
.working .el { color: var(--mute); font-size: 14px; font-variant-numeric: tabular-nums; }
.working .stop { border: 0; background: #f3f1ec; border-radius: 10px; padding: 8px 10px; font-weight: 600; font-size: 14px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--gold); flex: none; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(.7); opacity: .5; } 50% { transform: scale(1.15); opacity: 1; } }

.hello { text-align: center; padding: 18px 8px 4px; }
.hello h2 { margin: 6px 0 6px; font-size: 22px; }
.hello p { color: var(--mute); margin: 0 0 16px; }
.chips { display: flex; flex-direction: column; gap: 8px; }
.chip { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 12px 14px; font-weight: 600; }
.chip span { display: block; color: var(--mute); font-weight: 500; font-size: 14px; }

.composer { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(var(--safe-b) + 8px);
  background: #fff; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; border: 1.5px solid var(--line); border-radius: 22px; padding: 11px 16px;
  max-height: 160px; min-height: 46px; outline: none; background: var(--bg); font-size: 17px; }
.composer textarea:focus { border-color: var(--gold); background: #fff; }
.cbtn { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; font-size: 20px; }
.cbtn.send { background: var(--gold); font-weight: 700; }
.cbtn.mic { background: var(--bg); }
.cbtn.mic.on { background: var(--red); color: #fff; animation: pulse 1.1s infinite; }
.cbtn:disabled { opacity: .45; }

.drawer-bg { position: fixed; inset: 0; background: #0006; z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(88vw, 380px); background: var(--bg); z-index: 41;
  transform: translateX(105%); transition: transform .2s ease; padding: calc(var(--safe-t) + 12px) 14px 20px; overflow-y: auto; }
.drawer.open { transform: none; }
.dr-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 17px; }
.x { border: 0; background: #fff; width: 42px; height: 42px; border-radius: 10px; font-size: 18px; }
.dbtn { width: 100%; border: 0; border-radius: 12px; min-height: 48px; font-weight: 700; margin-bottom: 10px; background: #fff; }
.dbtn.gold { background: var(--gold); }
.dr-list .it { display: block; width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px; overflow-wrap: anywhere; }
.dr-list .it.on { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset; }
.dr-list .it small { display: block; color: var(--mute); font-size: 13px; }
.dr-list .undo { margin-top: 8px; border: 0; background: var(--bg); border-radius: 10px; padding: 8px 12px; font-weight: 700; }
.dr-note { color: var(--mute); font-size: 13px; }
.dr-empty { color: var(--mute); font-size: 14px; padding: 4px 2px 8px; }

.toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 80px); background: var(--ink); color: #fff;
  padding: 13px 16px; border-radius: 14px; z-index: 60; font-weight: 600; box-shadow: 0 6px 20px #0004; }

/* password sheets */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 18px; }
.sheet { background: #fff; color: #222; border-radius: 16px; padding: 20px; width: 100%; max-width: 380px; display: grid; gap: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.sheet b { font-size: 19px; }
.sheet p { margin: 0; color: #555; font-size: 15px; }
.sheet input { font-size: 17px; padding: 12px; border: 1px solid #ccc; border-radius: 10px; width: 100%; box-sizing: border-box; }
.sheet .row { display: grid; grid-auto-flow: column; gap: 8px; }
.sheet .err { color: #b3261e; font-size: 14px; }
.sheet .hidden { display: none; }
