:root {
  --bg: #f0f8f2;
  --border: #d4edda;
  --text: #1b4332;
  --muted: #6a9c7b;
  --soft: #e8f5e9;
  --soft2: #c8e6c9;
  --card: #fff;
  --green: #2e7d32;
  --green-light: #66bb6a;
  --green-dark: #1b5e20;
  --shadow: 0 8px 32px rgba(46,125,50,.12);
  --toast-bg: #1b4332;
  --toast-text: #fff;
  --sidebar-width: 320px;
  --topbar-height: 64px;
  --radius: 16px;
  --danger: #c62828;
  --danger-light: #ffebee;
  --vh: 1vh;
}
* { font-family: 'Plus Jakarta Sans', sans-serif; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; height: -webkit-fill-available; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  display: flex; flex-direction: row;
  height: 100dvh; height: 100svh; height: calc(var(--vh, 1vh) * 100);
  min-height: -webkit-fill-available;
  overflow: hidden;
  padding-top: var(--topbar-height);
  position: fixed; width: 100%; top: 0; left: 0;
  overscroll-behavior: none;
}
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-height);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  flex-shrink: 0; gap: 8px;
}
.top-left { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.menu-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text); padding: 4px 8px; border-radius: 10px; }
.top-title {
  font-weight: 800; font-size: clamp(14px, 2.2vw, 18px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
  background: linear-gradient(135deg, var(--green-dark), var(--green-light));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.top-sub { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; font-weight: 500; }
.dot {
  width: 8px; height: 8px; background: var(--green-light); border-radius: 50%;
  box-shadow: 0 0 0 3px var(--soft2); animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 #a5d6a7; } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; }
}
.topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.topbar-right button {
  background: rgba(255,255,255,0.8); border: 1px solid var(--border);
  border-radius: 9999px; padding: 6px 14px; font-size: 12px; cursor: pointer;
  color: var(--text); transition: all 0.2s;
  display: flex; align-items: center; gap: 4px; white-space: nowrap; font-weight: 600;
}
.topbar-right button:hover { background: var(--soft); border-color: var(--green); transform: scale(1.02); }
#installBtn {
  display: none;
  background: linear-gradient(135deg, var(--green) 0%, var(--green-light) 100%);
  color: #fff; border: none; font-weight: 700;
  box-shadow: 0 4px 12px rgba(46,125,50,0.25);
}
#installBtn:hover { background: linear-gradient(135deg, var(--green-dark) 0%, var(--green) 100%); transform: translateY(-1px); color: #fff; }
#sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #fff 0%, #f0f8f2 100%);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 24px 18px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 20; flex-shrink: 0; overflow-y: auto;
  height: calc(100dvh - var(--topbar-height));
}
.sidebar-header { display: flex; justify-content: space-between; align-items: center; }
.sidebar-brand { display: flex; gap: 12px; align-items: center; }
.sidebar-brand img { width: 40px; height: 40px; border-radius: 12px; background: var(--soft); border: 2px solid var(--border); object-fit: cover; }
.sidebar-brand div {
  font-weight: 800; font-size: 15px;
  background: linear-gradient(135deg, var(--green-dark), var(--green-light));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.sidebar-brand small { font-size: 10px; color: var(--muted); display: block; font-weight: 600; -webkit-text-fill-color: var(--muted); }
.sidebar-close { display: none; background: none; border: none; font-size: 22px; cursor: pointer; }
.btn-new {
  margin-top: 20px;
  background: linear-gradient(135deg, var(--green) 0%, var(--green-light) 100%);
  color: #fff; border: none; padding: 14px; border-radius: 12px; width: 100%;
  font-weight: 700; font-size: 14px; cursor: pointer; transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(46,125,50,0.2);
}
.btn-new:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(46,125,50,0.3); }
.history-label { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; margin-top: 22px; margin-bottom: 8px; }
#history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.hist-item {
  padding: 10px 14px; border-radius: 10px; cursor: pointer; font-size: 13px;
  display: flex; justify-content: space-between; align-items: flex-start;
  font-weight: 500; border-left: 3px solid transparent; gap: 6px; min-height: 44px; transition: all 0.2s;
}
.hist-item:hover { background: var(--soft); }
.hist-item.active { background: var(--soft); border-left-color: var(--green); }
.hist-title { flex: 1; white-space: normal; line-height: 1.4; }
.hist-del-btn { opacity: .4; padding: 4px 6px; border-radius: 6px; font-size: 14px; background: none; border: none; cursor: pointer; transition: all 0.2s; }
.hist-del-btn:hover { opacity: 1; background: var(--danger-light); }
.sidebar-overlay {
  display: none; position: fixed;
  top: var(--topbar-height); left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3); z-index: 19; backdrop-filter: blur(4px);
}
#main {
  flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0;
  height: calc(100dvh - var(--topbar-height));
  height: calc(100svh - var(--topbar-height));
  height: calc(var(--vh, 1vh) * 100 - var(--topbar-height));
  background: radial-gradient(ellipse at top right, #e8f5e9 0%, transparent 60%), var(--bg);
  position: relative; overflow: hidden;
}
#main.drag-over { border: 3px dashed var(--green); background: rgba(46,125,50,0.08); }
#chat {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 18px 16px 10px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth; -webkit-overflow-scrolling: touch;
}
.bubble-wrap { width: 100%; display: flex; flex-direction: column; animation: bubble-in 0.3s ease-out; }
@keyframes bubble-in {
  0% { opacity: 0; transform: translateY(16px) scale(0.96); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.bubble-wrap.user { align-items: flex-end; }
.bubble-wrap.ai { align-items: flex-start; }
.bubble-wrap.system { align-items: center; }
.bubble {
  max-width: 82%; width: fit-content; min-width: 40px;
  padding: 12px 18px; border-radius: 20px;
  line-height: 1.65; white-space: pre-wrap;
  overflow-wrap: anywhere; word-break: break-word;
  font-size: 14px; box-shadow: 0 2px 12px rgba(0,0,0,0.05);
}
.bubble.user { background: linear-gradient(135deg, var(--green-dark) 0%, var(--green) 100%); color: #fff; border-bottom-right-radius: 6px; }
.bubble.ai { background: rgba(255,255,255,0.9); border: 1px solid var(--border); border-bottom-left-radius: 6px; color: var(--text); }
.bubble.system { background: var(--soft2); color: var(--green-dark); font-size: 12px; font-weight: 600; padding: 8px 14px; border-radius: 9999px; }
.msg-time { font-size: 10px; color: var(--muted); margin-top: 4px; padding: 0 6px; opacity: .7; }
.bubble-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.bubble-file { display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,0.08); border-radius: 10px; padding: 4px 10px 4px 6px; font-size: 11px; max-width: 220px; }
.bubble.user .bubble-file { background: rgba(255,255,255,0.22); color: #fff; }
.bubble-file img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid rgba(255,255,255,0.3); cursor: zoom-in; }
.bubble.user .bubble-file img { border-color: rgba(255,255,255,0.4); }
.bubble-file .file-icon { font-size: 20px; width: 28px; text-align: center; }
.bubble-file .file-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#imgLightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.88); display: none; align-items: center; justify-content: center; z-index: 500; padding: 20px; cursor: zoom-out; }
#imgLightbox.show { display: flex; }
#imgLightbox img { max-width: 95vw; max-height: 95vh; border-radius: 12px; box-shadow: 0 20px 80px rgba(0,0,0,0.6); }
.chat-footer {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: rgba(240,248,242,0.95);
  backdrop-filter: blur(10px);
  flex-shrink: 0; display: flex; flex-direction: column;
  position: relative; z-index: 5; border-top: 1px solid var(--border);
}
#filePreview { display: none; flex-wrap: wrap; gap: 8px; padding: 4px 4px 8px 4px; }
.file-chip { display: flex; align-items: center; gap: 6px; background: var(--soft); border-radius: 12px; padding: 4px 12px 4px 8px; font-size: 12px; border: 1px solid var(--border); }
.file-chip button { background: none; border: none; cursor: pointer; font-size: 14px; padding: 0 2px; }
.file-preview-thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.input-wrap {
  padding: 6px 6px 6px 16px;
  background: #fff; border: 1.5px solid var(--border);
  border-radius: 28px; display: flex; gap: 8px; align-items: flex-end;
  box-shadow: var(--shadow);
}
.input-wrap:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px var(--soft2); }
.input-wrap textarea {
  flex: 1; border: none; background: transparent; outline: none;
  padding: 10px 4px; font-size: 15px; color: var(--text);
  resize: none; max-height: 140px; min-height: 22px; line-height: 1.5; font-family: inherit;
}
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--border); background: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; font-size: 18px; transition: all 0.2s;
}
.icon-btn:hover { transform: scale(1.05); }
.icon-btn.primary { background: linear-gradient(135deg, var(--green) 0%, var(--green-light) 100%); color: #fff; border: none; }
#scrollDownBtn {
  position: absolute; bottom: 90px; right: 20px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 50%; width: 40px; height: 40px;
  box-shadow: var(--shadow); cursor: pointer;
  display: none; align-items: center; justify-content: center;
  font-size: 18px; color: var(--green); z-index: 10; transition: all 0.2s;
}
#scrollDownBtn:hover { transform: scale(1.1); }
#loginPage {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 30% 20%, #e8f5e9, #c8e6c9 70%);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.login-card {
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(16px) saturate(180%);
  padding: 36px 32px; border-radius: 40px;
  width: 100%; max-width: 420px;
  border: 1px solid rgba(255,255,255,0.5);
  box-shadow: 0 30px 80px rgba(46,125,50,0.15);
}
.login-card .logo-row { display: flex; gap: 16px; align-items: center; }
.login-card .logo-row img { width: 56px; height: 56px; border-radius: 16px; object-fit: cover; background: var(--soft); border: 2px solid var(--border); }
.login-card h2 { margin: 22px 0 4px; font-weight: 800; font-size: 26px; color: var(--green-dark); }
.login-card h2 small { font-weight: 400; font-size: 14px; color: var(--muted); display: block; margin-top: 2px; }
.login-card p { margin: 0 0 24px; font-size: 14px; color: var(--muted); font-weight: 500; }
.login-card .form-group { margin-top: 16px; }
.login-card .form-group label {
  display: block; font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px;
}
.input-wrapper, .password-wrapper { background: rgba(255,255,255,0.6); border: 1.5px solid var(--border); border-radius: 14px; transition: all 0.2s; }
.input-wrapper:focus-within, .password-wrapper:focus-within { border-color: var(--green); background: #fff; }
.input-wrapper input, .password-wrapper input {
  width: 100%; padding: 14px 16px; border: none; border-radius: 14px;
  font-size: 15px; background: transparent; outline: none; color: var(--text);
}
.password-wrapper { position: relative; }
.password-wrapper input { padding-right: 50px; }
.password-toggle { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 18px; cursor: pointer; padding: 6px 8px; }
.login-error {
  color: var(--danger); font-size: 13px; font-weight: 600;
  margin-top: 12px; display: none; text-align: center;
  background: var(--danger-light); padding: 8px 12px; border-radius: 8px;
}
.login-error.show { display: block; }
.btn-login {
  background: linear-gradient(135deg, var(--green) 0%, var(--green-light) 100%);
  color: #fff; border: none; padding: 16px; border-radius: 14px;
  width: 100%; font-weight: 700; font-size: 15px; cursor: pointer;
  margin-top: 20px; transition: all 0.2s;
}
.btn-login:hover { transform: translateY(-1px); }
.btn-login:disabled { opacity: .6; cursor: not-allowed; }
.login-footer { margin-top: 18px; font-size: 11px; color: var(--muted); text-align: center; border-top: 1px solid var(--border); padding-top: 14px; }
.toast-container { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--toast-bg); color: var(--toast-text);
  padding: 10px 22px; border-radius: 12px; font-size: 13px;
  font-weight: 600; white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  pointer-events: auto; animation: toast-in 0.3s ease-out;
}
@keyframes toast-in {
  0% { opacity: 0; transform: translateY(20px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.typing-indicator { display: inline-flex; align-items: center; gap: 5px; padding: 4px 6px; }
.typing-indicator span {
  width: 8px; height: 8px; background: var(--green-light);
  border-radius: 50%; animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-6px); opacity: 1; }
}
.table-wrapper { margin: 12px 0; border: 1.5px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; box-shadow: 0 4px 12px rgba(0,0,0,0.05); max-width: 100%; }
.table-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px;
  background: linear-gradient(135deg, #e8f5e9 0%, #f1f8e9 100%);
  border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 800; color: var(--green-dark);
}
.table-content { overflow-x: auto; }
.table-content table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-content th { background: linear-gradient(135deg, var(--green) 0%, var(--green-light) 100%); color: #fff; padding: 10px 12px; text-align: left; font-weight: 700; white-space: nowrap; }
.table-content td { padding: 9px 12px; border-bottom: 1px solid #e8f5e9; border-right: 1px solid #e8f5e9; }
.code-block-wrapper { margin: 12px 0; border: 1.5px solid #1e293b; border-radius: 12px; overflow: hidden; background: #0f172a; max-width: 100%; }
.code-block-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; background: #1e293b; color: #94a3b8; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.code-block-wrapper pre { margin: 0; padding: 14px; overflow-x: auto; color: #e2e8f0; font-family: monospace; font-size: 13px; line-height: 1.6; white-space: pre-wrap; }
.copy-code-btn, .copy-table-btn { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; font-size: 11px; font-weight: 700; cursor: pointer; }
.code-block-wrapper .copy-code-btn { background: #334155; color: #e2e8f0; border-color: #475569; }
.hidden { display: none !important; }
.brand-title { font-weight: 800; font-size: 20px; color: var(--green-dark); }
.brand-version { font-size: 11px; color: var(--muted); }
@media (max-width: 768px) {
  :root { --topbar-height: 56px; }
  .menu-toggle { display: block; }
  #sidebar {
    position: fixed;
    top: var(--topbar-height); left: 0; bottom: 0;
    transform: translateX(-100%); width: 320px;
    border-radius: 0 20px 20px 0;
    box-shadow: 4px 0 30px rgba(0,0,0,0.08);
    z-index: 30;
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar .sidebar-close { display: block; }
  .sidebar-overlay.active { display: block; }
  .bubble { max-width: 88%; }
  #main {
    width: 100%;
    height: calc(100dvh - var(--topbar-height));
    height: calc(100svh - var(--topbar-height));
    height: calc(var(--vh, 1vh) * 100 - var(--topbar-height));
  }
  .chat-footer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px) + 4px); }
  .input-wrap { border-radius: 24px; }
  .input-wrap textarea { font-size: 16px; }
  .bubble-file { max-width: 180px; }
}
