/* maili assistant - shared styles */
:root {
  --brand: #ff6b37;
  --brand-dark: #e8562a;
  --brand-soft: #fff0e8;
  --bg: #fff9f4;
  --surface: #ffffff;
  --surface-2: #fdf4ec;
  --text: #241a15;
  --text-muted: #8b7a71;
  --border: #f0e2d6;
  --shadow: 0 1px 2px rgba(36, 26, 21, .05), 0 8px 24px rgba(36, 26, 21, .06);
  --shadow-lg: 0 12px 40px rgba(36, 26, 21, .14);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-width: 268px;
  --font: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
          "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #ff7d4d;
    --brand-dark: #ff6b37;
    --brand-soft: #33211a;
    --bg: #17110e;
    --surface: #201814;
    --surface-2: #271d18;
    --text: #f6ece5;
    --text-muted: #a8968c;
    --border: #342620;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --brand: #ff7d4d;
  --brand-dark: #ff6b37;
  --brand-soft: #33211a;
  --bg: #17110e;
  --surface: #201814;
  --surface-2: #271d18;
  --text: #f6ece5;
  --text-muted: #a8968c;
  --border: #342620;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--brand-dark); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1000px 480px at 50% -12%, var(--brand-soft), transparent 70%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 40px 32px 32px;
  text-align: center;
}
.login-card .avatar { width: 96px; height: 96px; margin: 0 auto 18px; }
.login-card h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -.5px; }
.login-card p.sub { margin: 0 0 28px; color: var(--text-muted); font-size: 14px; }
.field { text-align: left; margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(255, 107, 55, .16);
}
.btn-primary {
  width: 100%;
  padding: 13px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:active { transform: scale(.99); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.form-error {
  margin: 14px 0 0;
  font-size: 13px;
  color: #d93025;
  min-height: 18px;
}
.login-hint { margin-top: 22px; font-size: 12px; color: var(--text-muted); line-height: 1.7; }

.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--brand);
  display: block;
}

/* ---------- app shell ---------- */
.app { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left .22s ease;
}
.sidebar.collapsed { margin-left: calc(var(--sidebar-width) * -1); }
.sidebar-head { padding: 16px 14px 10px; display: flex; align-items: center; gap: 10px; }
.sidebar-head .avatar { width: 32px; height: 32px; }
.sidebar-head strong { font-size: 15px; }
.new-chat {
  margin: 4px 12px 12px;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.new-chat:hover { background: var(--brand-dark); }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.conv-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted); padding: 12px 8px 6px;
}
.conv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  font-size: 14px; color: var(--text);
}
.conv-item:hover { background: rgba(255, 107, 55, .1); }
.conv-item.active { background: var(--brand-soft); font-weight: 600; }
.conv-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .menu-btn { opacity: 0; padding: 2px 6px; border-radius: 6px; color: var(--text-muted); }
.conv-item:hover .menu-btn, .conv-item.active .menu-btn { opacity: 1; }
.conv-item .menu-btn:hover { background: rgba(0, 0, 0, .08); }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px 12px; display: grid; gap: 6px; }
.sidebar-foot .row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }
.link-btn {
  padding: 8px 10px; border-radius: 8px; font-size: 13px; text-align: left;
  color: var(--text-muted); width: 100%;
}
.link-btn:hover { background: rgba(255, 107, 55, .1); color: var(--text); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; color: var(--text-muted);
}
.icon-btn:hover { background: rgba(255, 107, 55, .12); color: var(--text); }
.topbar .spacer { flex: 1; }
.model-select {
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 13px; cursor: pointer;
}

/* profile header */
.profile-header {
  display: flex; flex-direction: column; align-items: center;
  padding: 26px 20px 18px; text-align: center;
}
.profile-header .avatar {
  width: 92px; height: 92px;
  box-shadow: 0 8px 24px rgba(255, 107, 55, .3);
  border: 3px solid var(--surface);
}
.profile-header h1 { margin: 14px 0 4px; font-size: 22px; letter-spacing: -.4px; }
.profile-header p { margin: 0; font-size: 13.5px; color: var(--text-muted); }
.status-pill {
  margin-top: 12px; font-size: 12px; padding: 5px 12px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-dark); font-weight: 600;
}
.status-pill.warn { background: #fff2cc; color: #8a6100; }

.chat-scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.chat-inner { max-width: 780px; margin: 0 auto; padding: 0 20px 40px; }

.msg { display: flex; gap: 12px; margin: 22px 0; align-items: flex-start; }
.msg .avatar { width: 34px; height: 34px; flex: 0 0 34px; }
.msg .who { font-size: 12.5px; font-weight: 700; color: var(--text-muted); margin-bottom: 5px; }
.msg .body { min-width: 0; flex: 1; }
.msg.user { flex-direction: row-reverse; }
.msg.user .body { display: flex; flex-direction: column; align-items: flex-end; }
.bubble-user {
  background: var(--brand);
  color: #fff;
  padding: 11px 16px;
  border-radius: 18px 18px 4px 18px;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}
.user-avatar {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--text-muted);
}
.assistant-body { line-height: 1.75; font-size: 15.2px; word-break: break-word; }
.assistant-body > *:first-child { margin-top: 0; }
.assistant-body > *:last-child { margin-bottom: 0; }
.assistant-body h1, .assistant-body h2, .assistant-body h3 {
  margin: 22px 0 10px; line-height: 1.35; letter-spacing: -.3px;
}
.assistant-body h1 { font-size: 21px; }
.assistant-body h2 { font-size: 18.5px; }
.assistant-body h3 { font-size: 16.5px; }
.assistant-body p { margin: 11px 0; }
.assistant-body ul, .assistant-body ol { margin: 11px 0; padding-left: 22px; }
.assistant-body li { margin: 5px 0; }
.assistant-body hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.assistant-body blockquote {
  margin: 14px 0; padding: 8px 14px; border-left: 3px solid var(--brand);
  background: var(--surface-2); border-radius: 0 8px 8px 0; color: var(--text-muted);
}
.assistant-body code {
  font-family: var(--mono); font-size: .89em;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 5px;
}
.assistant-body pre {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 14px; border-radius: 12px; overflow-x: auto; margin: 14px 0;
}
.assistant-body pre code { background: none; border: none; padding: 0; }
.table-scroll { overflow-x: auto; margin: 14px 0; }
.assistant-body table { border-collapse: collapse; width: 100%; font-size: 14px; }
.assistant-body th, .assistant-body td {
  border: 1px solid var(--border); padding: 9px 11px; text-align: left; vertical-align: top;
}
.assistant-body th { background: var(--surface-2); font-weight: 700; }
.msg-actions { display: flex; gap: 6px; margin-top: 10px; }
.msg-actions button {
  font-size: 12px; padding: 5px 10px; border-radius: 8px;
  color: var(--text-muted); border: 1px solid var(--border); background: var(--surface);
}
.msg-actions button:hover { color: var(--text); border-color: var(--brand); }

.typing { display: inline-flex; gap: 4px; align-items: center; padding: 6px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--brand);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

.error-note {
  background: #fdecea; color: #b3261e; border: 1px solid #f5c6c2;
  padding: 10px 14px; border-radius: 10px; font-size: 14px; margin: 8px 0;
}
:root[data-theme="dark"] .error-note {
  background: #3a1c19; color: #ffb4ab; border-color: #5a2a24;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .error-note {
    background: #3a1c19; color: #ffb4ab; border-color: #5a2a24;
  }
}

/* quick prompts */
.quick-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 10px; margin: 8px 0 20px;
}
.quick-card {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 14px; padding: 13px 14px; text-align: left;
  display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.quick-card:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: var(--shadow); }
.quick-card .emoji { font-size: 19px; }

/* composer */
.composer-wrap {
  padding: 10px 16px 18px;
  background: linear-gradient(to top, var(--bg) 62%, transparent);
  position: sticky; bottom: 0;
}
.composer {
  max-width: 780px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255, 107, 55, .14); }
.attach-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 2px 8px; }
.attach-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 8px; font-size: 12.5px; max-width: 230px;
}
.attach-chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 7px; }
.attach-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .remove { color: var(--text-muted); font-size: 15px; line-height: 1; padding: 0 2px; }
.attach-chip.uploading { opacity: .6; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1; border: none; background: none; outline: none; resize: none;
  padding: 9px 6px; max-height: 220px; line-height: 1.55; font-size: 15px;
}
.tool-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text-muted); flex: 0 0 38px;
}
.tool-btn:hover { background: var(--brand-soft); color: var(--brand-dark); }
.tool-btn.recording { background: #ffe5e0; color: #d93025; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
.send-btn {
  width: 38px; height: 38px; border-radius: 50%; background: var(--brand); color: #fff;
  display: grid; place-items: center; flex: 0 0 38px; transition: background .15s;
}
.send-btn:hover { background: var(--brand-dark); }
.send-btn:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }
.composer-hint { max-width: 780px; margin: 8px auto 0; font-size: 11.5px; color: var(--text-muted); text-align: center; }
.recording-bar {
  display: none; align-items: center; gap: 10px; padding: 6px 4px 10px;
  font-size: 13px; color: #d93025; font-weight: 600;
}
.recording-bar.on { display: flex; }
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: #d93025; animation: pulse 1.2s infinite; }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 12, 8, .55);
  display: none; align-items: center; justify-content: center; z-index: 60; padding: 18px;
  backdrop-filter: blur(3px);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg);
  width: min(560px, 100%); max-height: 90dvh; overflow: auto; padding: 22px;
}
.modal h2 { margin: 0 0 4px; font-size: 19px; }
.modal .modal-sub { margin: 0 0 16px; font-size: 13px; color: var(--text-muted); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.btn {
  padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface);
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: #d93025; }
#camera-video, #camera-canvas { width: 100%; border-radius: 14px; background: #000; }
.camera-preview { width: 100%; border-radius: 14px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(12px);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 999px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 90;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* admin */
.admin-page { max-width: 980px; margin: 0 auto; padding: 26px 20px 60px; }
.admin-head { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.admin-head .avatar { width: 44px; height: 44px; }
.admin-head h1 { font-size: 21px; margin: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 16.5px; }
.card .card-sub { margin: 0 0 16px; font-size: 13px; color: var(--text-muted); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.tag { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.tag.admin { background: var(--brand-soft); color: var(--brand-dark); border-color: transparent; }
.tag.off { color: var(--text-muted); }
.inline-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.credential-box {
  margin-top: 14px; padding: 12px 14px; border-radius: 10px;
  background: var(--brand-soft); font-family: var(--mono); font-size: 13px; word-break: break-all;
}
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions button { font-size: 12px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); }
.row-actions button:hover { border-color: var(--brand); }

@media (max-width: 860px) {
  .sidebar {
    position: fixed; z-index: 50; top: 0; bottom: 0; left: 0;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.collapsed { margin-left: calc(var(--sidebar-width) * -1); }
  .scrim { position: fixed; inset: 0; background: rgba(20, 12, 8, .4); z-index: 45; display: none; }
  .scrim.on { display: block; }
  .profile-header { padding: 18px 16px 12px; }
  .profile-header .avatar { width: 72px; height: 72px; }
  .chat-inner { padding: 0 14px 30px; }
  .composer-wrap { padding: 8px 10px 12px; }
}
