/* === AI Image Master · responsive layout === */

:root {
  color-scheme: dark;
  --bg-base: #08090a;
  --rose-500: #f43f5e;
  --rose-600: #e11d48;
  --rose-700: #be123c;
  --rose-300: #fda4af;
  --rose-200: #fecdd3;
  --zinc-100: #f4f4f5;
  --zinc-300: #d4d4d8;
  --zinc-400: #a1a1aa;
  --zinc-500: #71717a;
  --border: rgba(255,255,255,0.10);
  --glass-bg: linear-gradient(135deg, rgba(20,20,24,0.72), rgba(28,28,35,0.42));
  --tap: 44px;
  --sat: env(safe-area-inset-top);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);
  --sar: env(safe-area-inset-right);
}

* { box-sizing: border-box; }
[v-cloak] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  min-height: 100%;
  background: radial-gradient(1000px 700px at 15% 10%, rgba(190,18,60,0.20), transparent 60%),
              radial-gradient(900px 600px at 85% 90%, rgba(225,29,72,0.18), transparent 55%),
              linear-gradient(120deg, #08090a 0%, #111214 45%, #0c0d10 100%);
  color: var(--zinc-100);
  font-family: system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans CJK TC", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button, input, select, textarea, label {
  font: inherit; color: inherit;
}
button { cursor: pointer; }
input, select, textarea {
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  box-shadow: 0 0 0 1px rgba(244,63,94,0.7);
}
textarea { resize: vertical; min-height: 64px; }

/* === Login overlay === */
.login-shell {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  padding-top: max(24px, var(--sat));
  padding-bottom: max(24px, var(--sab));
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--glass-bg);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 18px;
  padding: 28px 22px;
}
.login-card h1 {
  margin: 0 0 4px; font-size: 20px; color: var(--rose-300);
}
.login-card p { margin: 0 0 16px; color: var(--zinc-400); font-size: 13px; }
.login-card .err { color: #fda4af; font-size: 12px; margin-top: 8px; min-height: 16px; }
.login-card button {
  margin-top: 14px; width: 100%; min-height: var(--tap);
  background: var(--rose-600); border: 0; border-radius: 10px;
  font-weight: 600;
}
.login-card button:hover { background: var(--rose-500); }
.login-card button:disabled { opacity: 0.5; cursor: not-allowed; }

/* === App shell === */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 8px;
  padding-top: max(8px, var(--sat));
  padding-bottom: max(8px, var(--sab));
  padding-left: max(8px, var(--sal));
  padding-right: max(8px, var(--sar));
}
.shell {
  display: flex;
  background: var(--glass-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  min-height: calc(100vh - 16px);
  min-height: calc(100dvh - 16px);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* === Sidebar === */
.sidebar {
  width: 320px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar-head {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.sidebar-head h1 { margin: 0; font-size: 16px; color: var(--rose-300); }
.btn-primary {
  background: var(--rose-600); border: 0; border-radius: 10px;
  padding: 8px 12px; font-size: 13px; min-height: 36px;
}
.btn-primary:hover { background: var(--rose-500); }
.btn-ghost {
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 12px; min-height: 32px;
}
.btn-ghost:hover { background: rgba(0,0,0,0.45); }
.btn-danger {
  background: rgba(190,18,60,0.5);
  border: 1px solid rgba(253,164,175,0.3);
  border-radius: 8px; padding: 6px 10px; font-size: 12px; min-height: 32px;
}
.btn-danger:hover { background: rgba(225,29,72,0.6); }

.config-card {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.config-card .label { color: var(--zinc-400); font-size: 11px; }
.config-card .mode-box {
  margin-top: 8px;
  padding: 8px;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(253,164,175,0.2);
  border-radius: 8px;
}
.config-card .mode-box .title { color: var(--rose-200); font-weight: 600; font-size: 11px; margin-bottom: 6px; }
.modes { display: flex; gap: 10px; font-size: 11px; color: var(--zinc-300); }
.modes label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.modes input[disabled] + span { color: var(--zinc-500); }
.usage {
  margin-top: 10px;
  font-size: 11px; color: var(--zinc-400);
  display: grid; gap: 2px;
}
.usage strong { color: var(--zinc-300); font-weight: 500; }

.sidebar-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.conv-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.conv-item {
  text-align: left; width: 100%;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: var(--tap);
}
.conv-item:hover { background: rgba(0,0,0,0.35); }
.conv-item.active { box-shadow: 0 0 0 1px rgba(253,164,175,0.7); }
.conv-item .title { font-size: 13px; font-weight: 500; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.conv-item .meta { margin-top: 4px; font-size: 11px; color: var(--zinc-400); }
.conv-item .date { margin-top: 2px; font-size: 10px; color: var(--zinc-500); }
.empty-hint { color: var(--zinc-400); font-size: 13px; padding: 12px; text-align: center; }

/* === Main area === */
.main {
  flex: 1; min-width: 0;
  padding: 12px;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.main-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--zinc-400); }

.panes {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 0;
}
.pane {
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.25);
  border-radius: 14px;
  display: flex; flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.pane-head {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.pane-head .title { font-weight: 600; color: var(--rose-300); font-size: 14px; }
.pane-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 12px;
}
.pane-foot {
  border-top: 1px solid var(--border);
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-1 { display: grid; grid-template-columns: 1fr; gap: 8px; }

.checks { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--zinc-300); }
.checks label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; min-height: 28px; }

.msg {
  border-radius: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.3);
}
.msg.user { background: rgba(159,18,57,0.18); border-color: rgba(253,164,175,0.2); margin-left: 24px; }
.msg.assistant { margin-right: 24px; }
.msg .role { font-size: 11px; margin-bottom: 4px; color: var(--zinc-400); }
.msg.user .role { color: var(--rose-200); }
.msg .content { font-size: 13px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.msg .imgs { margin-top: 8px; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.msg .imgs img { width: 100%; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }
.msg .usage-line { margin-top: 6px; font-size: 11px; color: #6ee7b7; }

.upload-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.upload-btn {
  display: block; text-align: center;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 13px;
  cursor: pointer;
  min-height: var(--tap);
}
.upload-btn:hover { background: rgba(0,0,0,0.4); }
.upload-btn input { display: none; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; }
.thumb img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }
.thumb button {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--rose-600); border: 0; color: #fff; font-size: 11px;
}

.files-list { display: flex; flex-direction: column; gap: 4px; }
.files-list .row-file {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; background: rgba(0,0,0,0.3); padding: 6px 8px; border-radius: 6px;
}
.files-list .row-file button { background: none; border: 0; color: var(--rose-300); font-size: 12px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn-primary { min-height: var(--tap); padding: 10px 16px; }
.actions .btn-secondary {
  background: rgba(63,63,70,0.7); border: 0; border-radius: 10px; padding: 10px 16px; min-height: var(--tap); font-size: 13px;
}
.actions .btn-secondary:hover { background: rgba(82,82,91,0.7); }
.actions button:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Mobile burger / drawer === */
.mobile-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(8,9,10,0.85);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 10;
}
.mobile-bar h1 { margin: 0; font-size: 15px; color: var(--rose-300); }
.icon-btn {
  width: var(--tap); height: var(--tap);
  background: rgba(0,0,0,0.4); border: 1px solid var(--border);
  border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.icon-btn:hover { background: rgba(0,0,0,0.55); }

.scrim {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 50;
}

/* === Image preview === */
.preview {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.preview img { max-width: 96vw; max-height: 92vh; object-fit: contain; border-radius: 12px; border: 1px solid var(--border); }
.preview .close {
  position: absolute; top: max(16px, var(--sat)); right: max(16px, var(--sar));
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0,0,0,0.7); border: 1px solid var(--border); color: #fff;
}

/* === Toast === */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(20px, var(--sab));
  background: rgba(20,20,24,0.95); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 16px; font-size: 13px;
  z-index: 300; max-width: 90vw;
}

/* === Install banner === */
.install-banner {
  position: fixed;
  left: 12px; right: 12px;
  bottom: max(12px, var(--sab));
  background: var(--glass-bg);
  border: 1px solid rgba(253,164,175,0.3);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
  z-index: 90;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.install-banner .txt { flex: 1; font-size: 13px; }
.install-banner .txt strong { color: var(--rose-200); }
.install-banner button { white-space: nowrap; }

/* === Petals (kept from original) === */
.petal-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 70; }
.petal {
  position: absolute; top: -8vh; left: 0;
  width: var(--petal-size, 14px);
  height: calc(var(--petal-size, 14px) * 0.68);
  border-radius: 60% 40% 58% 42% / 62% 38% 62% 38%;
  background: linear-gradient(135deg, rgba(251,113,133,0.95), rgba(225,29,72,0.85));
  opacity: 0;
  animation: petalFall var(--fall-duration, 5.4s) ease-in forwards;
  animation-delay: var(--fall-delay, 0s);
  filter: drop-shadow(0 0 6px rgba(244,63,94,0.45));
}
@keyframes petalFall {
  0%   { opacity: 0; transform: translate3d(0,-4vh,0) rotate(0); }
  12%  { opacity: 0.95; }
  100% { opacity: 0; transform: translate3d(var(--petal-drift,0), 112vh, 0) rotate(var(--petal-rotate,540deg)); }
}

/* === Scrollbar === */
.scroll::-webkit-scrollbar, .pane-body::-webkit-scrollbar, .conv-list::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll::-webkit-scrollbar-thumb, .pane-body::-webkit-scrollbar-thumb, .conv-list::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(244,63,94,0.55), rgba(136,19,55,0.65));
  border-radius: 999px;
}
.scroll::-webkit-scrollbar-track, .pane-body::-webkit-scrollbar-track, .conv-list::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.06); border-radius: 999px;
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   - Desktop  : >= 1280px  → dual pane + 320px sidebar
   - Tablet   : 768-1279px → single pane (stacked), sidebar 280px
   - Mobile   : < 768px    → sidebar becomes drawer, single pane
   ============================================================ */

/* Tablet & below: stack panes vertically, narrower sidebar */
@media (max-width: 1279px) {
  .panes { grid-template-columns: 1fr; overflow-y: auto; }
  .pane { min-height: 480px; }
  .sidebar { width: 280px; }
  .app { padding: 6px; }
}

/* Mobile: sidebar becomes off-canvas drawer */
@media (max-width: 767px) {
  .app { padding: 0; }
  .shell {
    flex-direction: column;
    border-radius: 0;
    border: 0;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .mobile-bar { display: flex; }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: min(84vw, 340px);
    z-index: 60;
    background: #0c0d10;
    border-right: 1px solid var(--border);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.6);
    padding-top: var(--sat);
    padding-bottom: var(--sab);
  }
  .sidebar.open { transform: translateX(0); }
  .scrim.open { display: block; }

  .main { padding: 8px; }
  .panes { gap: 8px; }
  .pane-body { padding: 10px; gap: 8px; }
  .msg .imgs { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
  .msg .imgs img { height: 80px; }
  .msg.user { margin-left: 8px; }
  .msg.assistant { margin-right: 8px; }
  .actions { gap: 6px; }
  .row { grid-template-columns: 1fr; }
  textarea { font-size: 16px; } /* prevents iOS zoom */
  input { font-size: 16px; }
}

/* Touch-friendly: bigger tap targets on coarse pointers */
@media (pointer: coarse) {
  .btn-ghost, .btn-danger { min-height: 36px; padding: 8px 12px; }
  .conv-item { padding: 12px; }
}

/* Larger screens: a touch more breathing room */
@media (min-width: 1536px) {
  .sidebar { width: 360px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .petal { animation: none; display: none; }
  .sidebar { transition: none; }
}
