:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #f7f7f8;
  --panel-hover: #ececee;
  --text: #202123;
  --muted: #6f7075;
  --border: #e4e4e7;
  --soft: #f3f3f4;
  --accent: #111111;
  --accent-text: #ffffff;
  --danger: #c83838;
  --sidebar-w: 268px;
  --content-w: 780px;
  --shadow: 0 18px 55px rgba(0, 0, 0, .15);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #212121;
  --panel: #171717;
  --panel-hover: #2a2a2a;
  --text: #ececec;
  --muted: #a5a5a5;
  --border: #373737;
  --soft: #2f2f2f;
  --accent: #f4f4f4;
  --accent-text: #171717;
  --danger: #ff7474;
  --shadow: 0 18px 55px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
.mobile-only { display: none; }

.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100%; }

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid color-mix(in srgb, var(--border), transparent 45%);
}

.sidebar-top { padding: 10px 10px 6px; }

.new-chat-button {
  width: 100%;
  height: 42px;
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.new-chat-button:hover, .nav-item:hover, .project-row:hover, .text-button:hover { background: var(--panel-hover); }
.brand-mark { font-size: 18px; }
kbd { color: var(--muted); font-size: 11px; font-weight: 400; border: 0; background: none; }

.navigation { flex: 1; overflow-y: auto; padding: 6px 10px 18px; scrollbar-width: thin; }
.navigation section + section { margin-top: 18px; }
.section-heading { height: 30px; display: flex; align-items: center; justify-content: space-between; padding: 0 8px; color: var(--muted); font-size: 12px; font-weight: 600; }
.mini-button { width: 26px; height: 26px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; font-size: 18px; line-height: 1; }
.mini-button:hover { background: var(--panel-hover); }
.nav-list, .project-list { display: grid; gap: 2px; }

.nav-item, .project-row {
  position: relative;
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.nav-item.active, .project-row.active { background: var(--panel-hover); }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-icon { width: 19px; color: var(--muted); text-align: center; }
.project-block { border-radius: 9px; }
.project-head { display: flex; align-items: center; gap: 2px; }
.project-head .project-row { flex: 1; min-width: 0; }
.project-action { flex: 0 0 auto; width: 27px; height: 27px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; opacity: 0; }
.project-head:hover .project-action, .project-action:focus-visible { opacity: 1; }
.project-action:hover { background: var(--panel-hover); color: var(--text); }
.project-chats { margin-left: 18px; display: grid; gap: 1px; }
.project-chats .nav-item { color: color-mix(in srgb, var(--text), var(--muted) 22%); font-size: 13px; }
.project-meta { color: var(--muted); font-size: 11px; }

.sidebar-footer { padding: 10px; border-top: 1px solid color-mix(in srgb, var(--border), transparent 35%); }
.usage-card { width: 100%; min-height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; text-align: left; }
.usage-card:hover { background: var(--panel-hover); }
.usage-card strong, .usage-card small { display: block; }
.usage-card strong { font-size: 14px; }
.usage-card small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.usage-dot { width: 8px; height: 8px; border-radius: 99px; background: #22a06b; box-shadow: 0 0 0 4px color-mix(in srgb, #22a06b, transparent 84%); }
.footer-actions { display: flex; gap: 4px; }
.text-button { flex: 1; padding: 7px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }

.main { position: relative; min-width: 0; display: grid; grid-template-rows: 56px minmax(0, 1fr) auto; height: 100%; overflow: hidden; background: var(--bg); }
.topbar { display: flex; align-items: center; gap: 8px; padding: 7px 18px; z-index: 3; }
.topbar-spacer { flex: 1; }
.model-select { max-width: 230px; height: 38px; padding: 0 31px 0 11px; border: 0; border-radius: 9px; background: transparent; color: var(--text); font-weight: 600; cursor: pointer; }
.model-select:hover { background: var(--soft); }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; font-weight: 700; }
.icon-button:hover { background: var(--soft); }

.welcome { align-self: center; justify-self: center; margin-top: -6vh; text-align: center; padding: 24px; }
.welcome-mark { width: 52px; height: 52px; display: grid; place-items: center; margin: 0 auto 18px; border: 1px solid var(--border); border-radius: 16px; font-size: 25px; }
.welcome h1 { margin: 0; font-size: clamp(24px, 4vw, 31px); letter-spacing: -.035em; }
.welcome p { margin: 11px 0 0; color: var(--muted); }

.conversation { min-height: 0; overflow-y: auto; padding: 24px max(24px, calc((100% - var(--content-w)) / 2)) 42px; scrollbar-width: thin; }
.message { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 14px; margin: 0 auto 28px; max-width: var(--content-w); }
.message.user { grid-template-columns: minmax(0, 1fr); justify-items: end; }
.avatar { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 9px; font-size: 13px; }
.message-body { min-width: 0; width: 100%; line-height: 1.72; font-size: 15px; }
.message.user .message-body { width: auto; max-width: min(82%, 620px); padding: 10px 15px; border-radius: 20px; background: var(--soft); line-height: 1.55; }
.message-content { overflow-wrap: anywhere; }
.message-content p { margin: 0 0 12px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content h1, .message-content h2, .message-content h3 { margin: 24px 0 10px; line-height: 1.3; }
.message-content h1 { font-size: 22px; } .message-content h2 { font-size: 19px; } .message-content h3 { font-size: 16px; }
.message-content ul, .message-content ol { padding-left: 24px; }
.message-content code { padding: 2px 5px; border-radius: 5px; background: var(--soft); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.message-content pre { position: relative; overflow-x: auto; margin: 14px 0; padding: 16px; border-radius: 10px; background: #161616; color: #e7e7e7; }
.message-content pre code { padding: 0; background: transparent; color: inherit; }
.message-content blockquote { margin-left: 0; padding-left: 15px; border-left: 3px solid var(--border); color: var(--muted); }
.message-actions { margin-top: 9px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.message:hover .message-actions { opacity: 1; }
.message-action { padding: 4px 7px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.message-action:hover { background: var(--soft); }
.asset-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 9px; }
.asset-image { display: block; max-width: min(100%, 520px); max-height: 520px; border-radius: 13px; border: 1px solid var(--border); object-fit: contain; background: var(--soft); }
.asset-file { display: flex; align-items: center; gap: 8px; max-width: 320px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px; color: inherit; text-decoration: none; background: var(--bg); }
.asset-file small { display: block; color: var(--muted); }
.typing { display: flex; gap: 5px; padding-top: 8px; }
.typing i { width: 6px; height: 6px; border-radius: 99px; background: var(--muted); animation: bounce 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 70%, 100% { transform: translateY(0); opacity: .4; } 35% { transform: translateY(-5px); opacity: 1; } }

.composer-wrap { width: min(calc(100% - 36px), var(--content-w)); margin: 0 auto; padding: 0 0 max(10px, env(safe-area-inset-bottom)); background: var(--bg); }
.composer { padding: 10px 11px 9px; border: 1px solid var(--border); border-radius: 24px; background: var(--bg); box-shadow: 0 2px 10px rgba(0,0,0,.045); }
.composer:focus-within { border-color: color-mix(in srgb, var(--border), var(--text) 20%); }
.composer textarea { width: 100%; max-height: 180px; resize: none; padding: 3px 6px 9px; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.5; }
.composer textarea::placeholder { color: var(--muted); }
.composer-actions { display: flex; align-items: center; gap: 6px; }
.attach-button, .mode-button { min-width: 34px; height: 34px; display: grid; place-items: center; padding: 0 9px; border: 1px solid var(--border); border-radius: 99px; background: transparent; cursor: pointer; }
.attach-button { font-size: 20px; }
.mode-button { font-size: 12px; }
.mode-button.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.composer-hint { flex: 1; text-align: right; color: var(--muted); font-size: 11px; }
.send-button { width: 34px; height: 34px; border: 0; border-radius: 99px; background: var(--accent); color: var(--accent-text); cursor: pointer; font-size: 18px; }
.send-button:disabled { opacity: .35; cursor: default; }
.disclaimer { margin: 7px 0 0; text-align: center; color: var(--muted); font-size: 10px; }
.attachment-preview { display: flex; gap: 8px; overflow-x: auto; padding: 0 3px 8px; }
.attachment-chip { flex: 0 0 auto; display: flex; align-items: center; gap: 7px; max-width: 250px; padding: 7px 8px 7px 11px; border: 1px solid var(--border); border-radius: 11px; background: var(--bg); }
.attachment-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip button { border: 0; background: transparent; color: var(--muted); cursor: pointer; }

.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(0,0,0,.46); backdrop-filter: blur(3px); }
.modal { width: min(100%, 520px); max-height: min(88vh, 760px); overflow-y: auto; padding: 22px; border: 1px solid var(--border); border-radius: 16px; background: var(--bg); box-shadow: var(--shadow); }
.modal.wide { width: min(100%, 700px); }
.modal-header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.modal-header h2 { flex: 1; margin: 0; font-size: 19px; }
.modal-header button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 22px; }
.form-grid { display: grid; gap: 15px; }
.field { display: grid; gap: 7px; }
.field label { font-weight: 600; font-size: 13px; }
.field small { color: var(--muted); line-height: 1.45; }
.field input, .field textarea, .field select { width: 100%; padding: 10px 11px; border: 1px solid var(--border); border-radius: 9px; outline: 0; background: var(--bg); color: var(--text); }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--text); }
.field textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.button { min-height: 38px; padding: 0 15px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); cursor: pointer; }
.button.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.button.danger { border-color: color-mix(in srgb, var(--danger), transparent 45%); color: var(--danger); }
.button:disabled { opacity: .5; cursor: default; }
.requirements { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin: 14px 0; }
.requirement { padding: 8px 10px; border-radius: 8px; background: var(--soft); color: var(--muted); font-size: 12px; }
.requirement.ok { color: #1c875b; }
.file-list { display: grid; gap: 7px; margin-top: 10px; }
.file-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 9px; }
.file-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-error { grid-column: 1 / -1; color: var(--danger); line-height: 1.45; overflow-wrap: anywhere; }
.status { padding: 3px 7px; border-radius: 99px; background: var(--soft); color: var(--muted); font-size: 10px; }
.status.completed { color: #16734c; }.status.failed { color: var(--danger); }
.status.processing, .status.in_progress { color: #946200; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { padding: 14px; border: 1px solid var(--border); border-radius: 11px; }
.stat strong, .stat small { display: block; }.stat strong { font-size: 20px; }.stat small { margin-top: 4px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 26px; z-index: 40; transform: translate(-50%, 20px); padding: 9px 14px; border-radius: 9px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.sidebar-backdrop { display: none; }

@media (max-width: 760px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .app { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 12; width: min(88vw, 310px); transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 11; background: rgba(0,0,0,.38); }
  .sidebar-backdrop.open { display: block; }
  .sidebar-top { display: grid; grid-template-columns: 38px 1fr; gap: 5px; }
  .main { height: 100%; }
  .topbar { padding: 7px 10px; }
  .conversation { padding: 18px 16px 28px; }
  .message { gap: 10px; margin-bottom: 24px; }
  .message.user .message-body { max-width: 90%; }
  .composer-wrap { width: calc(100% - 20px); }
  .composer-hint { display: none; }
  .mode-button { margin-right: auto; }
  .welcome { margin-top: -12vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
