/* =========================================================
   Design Tokens — Dark (default)
   ========================================================= */
:root {
  --bg:            #0a0c12;
  --bg-2:          #10131c;
  --bg-3:          #181c27;
  --surface:       #1b1f2e;
  --surface-2:     #222638;
  --surface-3:     #2a3046;
  --border:        rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);

  --text:          #eaecf4;
  --text-2:        #9ba4be;
  --text-3:        #626b8a;

  --indigo:        #6366f1;
  --indigo-dim:    rgba(99, 102, 241, 0.13);
  --indigo-glow:   rgba(99, 102, 241, 0.30);
  --purple:        #8b5cf6;
  --purple-dim:    rgba(139, 92, 246, 0.13);
  --teal:          #14b8a6;
  --teal-dim:      rgba(20, 184, 166, 0.13);
  --amber:         #f59e0b;
  --amber-dim:     rgba(245, 158, 11, 0.13);
  --rose:          #f43f5e;
  --rose-dim:      rgba(244, 63, 94, 0.13);
  --sky:           #38bdf8;
  --sky-dim:       rgba(56, 189, 248, 0.13);
  --emerald:       #10b981;
  --emerald-dim:   rgba(16, 185, 129, 0.13);

  /* Gradients */
  --grad-primary:  linear-gradient(135deg, #6366f1, #8b5cf6);
  --grad-teal:     linear-gradient(135deg, #14b8a6, #06b6d4);
  --grad-rose:     linear-gradient(135deg, #f43f5e, #f97316);

  /* Code editor area */
  --code-bg:       #07090d;
  --code-text:     #6ee7b7;
  --computed-text: #a5b4fc;

  --sidebar-w:     224px;
  --topbar-h:      64px;
  --radius:        10px;
  --radius-sm:     6px;
  --radius-lg:     14px;

  --shadow-sm:     0 1px 4px rgba(0,0,0,.45);
  --shadow-md:     0 4px 20px rgba(0,0,0,.55);
  --shadow-lg:     0 8px 40px rgba(0,0,0,.65);
  --shadow-glow:   0 0 20px rgba(99,102,241,.18);

  --transition:    160ms cubic-bezier(.4,0,.2,1);
}

/* =========================================================
   Design Tokens — Light
   ========================================================= */
[data-theme="light"] {
  --bg:            #f1f3f8;
  --bg-2:          #ffffff;
  --bg-3:          #eaecf4;
  --surface:       #ffffff;
  --surface-2:     #f5f6fa;
  --surface-3:     #e8eaf2;
  --border:        rgba(0, 0, 0, 0.07);
  --border-strong: rgba(0, 0, 0, 0.13);

  --text:          #0f1117;
  --text-2:        #4b5568;
  --text-3:        #9ca3b8;

  --indigo:        #4f46e5;
  --indigo-dim:    rgba(79, 70, 229, 0.08);
  --indigo-glow:   rgba(79, 70, 229, 0.20);
  --purple:        #7c3aed;
  --purple-dim:    rgba(124, 58, 237, 0.08);
  --teal:          #0d9488;
  --teal-dim:      rgba(13, 148, 136, 0.09);
  --amber:         #d97706;
  --amber-dim:     rgba(217, 119, 6, 0.09);
  --rose:          #e11d48;
  --rose-dim:      rgba(225, 29, 72, 0.08);
  --sky:           #0284c7;
  --sky-dim:       rgba(2, 132, 199, 0.09);
  --emerald:       #059669;
  --emerald-dim:   rgba(5, 150, 105, 0.09);

  --grad-primary:  linear-gradient(135deg, #4f46e5, #7c3aed);
  --grad-teal:     linear-gradient(135deg, #0d9488, #0891b2);
  --grad-rose:     linear-gradient(135deg, #e11d48, #ea580c);

  /* Code editor area */
  --code-bg:       #f6f8fc;
  --code-text:     #166534;
  --computed-text: #4338ca;

  --shadow-sm:     0 1px 4px rgba(0,0,0,.07);
  --shadow-md:     0 4px 16px rgba(0,0,0,.09);
  --shadow-lg:     0 8px 32px rgba(0,0,0,.12);
  --shadow-glow:   0 0 20px rgba(79,70,229,.12);

  /* Login panel -- light-specific overrides */
  --login-panel-bg:     rgba(255, 255, 255, 0.92);
  --login-panel-border: rgba(0, 0, 0, 0.09);
}

/* =========================================================
   Reset & Base
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Noto Sans JP', 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

[hidden] { display: none !important; }

button, select, input, textarea { font: inherit; }

/* =========================================================
   Scrollbar
   ========================================================= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  white-space: nowrap;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,.06) 50%, transparent 100%);
  transform: translateX(-100%);
  transition: transform 0.5s ease;
  pointer-events: none;
}

.btn:hover::before { transform: translateX(100%); }

.btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: rgba(255,255,255,.16);
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0) scale(0.98);
  box-shadow: none;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: .45;
  transform: none;
  box-shadow: none;
}

.btn:disabled:hover {
  background: var(--surface-2);
  color: var(--text-2);
  transform: none;
}

.btn-primary {
  background: var(--grad-primary);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 12px rgba(99,102,241,.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #5254cc, #7c3aed);
  color: #fff;
  box-shadow: 0 4px 20px rgba(99,102,241,.45);
  transform: translateY(-1px);
}

.btn-primary::before {
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,.12) 50%, transparent 100%);
}

.btn-chatwork {
  background: var(--teal-dim);
  border-color: rgba(20,184,166,.25);
  color: var(--teal);
}

.btn-chatwork:hover {
  background: rgba(20,184,166,.25);
  color: #fff;
}

.btn-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 11px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.btn-close:hover {
  background: var(--rose-dim);
  color: var(--rose);
  border-color: rgba(244,63,94,.2);
}

/* =========================================================
   Login View
   ========================================================= */
.login-view {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  z-index: 999;
}

.login-bg-blur {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 55% at 15% 25%, rgba(99,102,241,.18) 0%, transparent 65%),
    radial-gradient(ellipse 55% 65% at 85% 75%, rgba(139,92,246,.14) 0%, transparent 65%),
    radial-gradient(ellipse 40% 40% at 50% 50%, rgba(20,184,166,.05) 0%, transparent 70%);
  pointer-events: none;
  animation: bgShift 8s ease-in-out infinite alternate;
}

@keyframes bgShift {
  from { opacity: 0.8; }
  to   { opacity: 1; }
}

.login-panel {
  position: relative;
  width: min(420px, 100%);
  background: var(--login-panel-bg, rgba(27, 31, 46, 0.88));
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--login-panel-border, rgba(255,255,255,.10));
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(99,102,241,.12), var(--shadow-glow);
  animation: fadeUp .45s cubic-bezier(.34,1.56,.64,1);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.login-logo-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--indigo), var(--purple));
  flex-shrink: 0;
}

.login-logo h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.login-logo p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-3);
}

.login-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 20px;
}

#loginMessage {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-2);
}

.google-btn-wrap {
  display: flex;
  justify-content: center;
  min-height: 44px;
}

.dev-login-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  height: 36px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
}

.dev-login-button:hover {
  background: var(--surface-3);
  color: var(--text);
}

/* =========================================================
   Layout — Sidebar + Main
   ========================================================= */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* =========================================================
   Sidebar
   ========================================================= */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--grad-primary);
  box-shadow: 0 2px 10px var(--indigo-glow);
  flex-shrink: 0;
  transition: box-shadow var(--transition), transform var(--transition);
}

.sidebar-logo-icon:hover {
  transform: scale(1.08) rotate(-4deg);
  box-shadow: 0 4px 16px var(--indigo-glow);
}

.sidebar-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .02em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-label {
  display: block;
  padding: 4px 6px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  position: relative;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.nav-item.active {
  background: var(--indigo-dim);
  color: #c7d2fe;
  border-color: rgba(99,102,241,.22);
  box-shadow: inset 3px 0 0 var(--indigo), 0 0 12px rgba(99,102,241,.08);
}

.nav-item.active svg {
  color: var(--indigo);
}

.sidebar-footer {
  padding: 12px 10px 16px;
  border-top: 1px solid var(--border);
}

/* Auth area in sidebar */
.auth-area {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
}

.auth-area img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
}

.auth-area span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-2);
}

.auth-area #logoutButton {
  flex-shrink: 0;
  height: 26px;
  padding: 0 8px;
  font-size: 11px;
  border-radius: 4px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.auth-area #logoutButton:hover {
  background: var(--rose-dim);
  color: var(--rose);
}

/* =========================================================
   Main Content
   ========================================================= */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 24px;
  gap: 16px;
}

.screen-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.screen-view[hidden] {
  display: none !important;
}

/* =========================================================
   Topbar
   ========================================================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar-left { flex-shrink: 0; }

.page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
}

.page-sub {
  display: block;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.language-switch {
  display: inline-flex;
  height: 34px;
  padding: 3px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.language-switch button {
  min-width: 54px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.language-switch button:hover {
  color: var(--text);
}

.language-switch button.active {
  background: var(--indigo);
  color: #fff;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-label {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

select#templateSelect {
  height: 34px;
  padding: 0 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  appearance: auto;
}

select#templateSelect:hover {
  border-color: rgba(255,255,255,.2);
  background: var(--surface-3);
}

select#templateSelect:focus {
  outline: 2px solid rgba(99,102,241,.4);
  outline-offset: 1px;
}

/* File upload button */
.file-upload-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.file-upload-label:hover {
  background: var(--surface-3);
  color: var(--text);
}

.file-upload-label input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* =========================================================
   Status Line
   ========================================================= */
.status-line {
  min-height: 20px;
  font-size: 12px;
  color: var(--text-3);
  padding: 0 2px;
  margin: -8px 0 0;
}

.workflow-status {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: -8px;
}

.workflow-step {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-3);
  transition: border-color var(--transition), background var(--transition), color var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}

.workflow-step::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--surface-3);
  transition: background var(--transition);
}

.workflow-step b,
.workflow-step span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workflow-step b {
  color: var(--text-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.workflow-step span:not(.workflow-dot) {
  margin-top: 1px;
  font-size: 12px;
}

.workflow-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--surface-3);
  box-shadow: 0 0 0 3px rgba(255,255,255,.03);
}

.workflow-step.active {
  border-color: rgba(56,189,248,.35);
  background: linear-gradient(135deg, var(--sky-dim), rgba(56,189,248,.05));
  color: var(--sky);
  box-shadow: 0 0 16px rgba(56,189,248,.08);
}

.workflow-step.active::before { background: var(--sky); }

.workflow-step.active .workflow-dot {
  background: var(--sky);
  box-shadow: 0 0 8px var(--sky);
  animation: pulseDot 1s ease-in-out infinite;
}

.workflow-step.done {
  border-color: rgba(16,185,129,.32);
  background: linear-gradient(135deg, var(--emerald-dim), rgba(16,185,129,.04));
  color: var(--emerald);
}

.workflow-step.done::before { background: var(--emerald); }

.workflow-step.done .workflow-dot {
  background: var(--emerald);
  box-shadow: 0 0 6px var(--emerald);
}

.workflow-step.error {
  border-color: rgba(244,63,94,.35);
  background: linear-gradient(135deg, var(--rose-dim), rgba(244,63,94,.04));
  color: var(--rose);
}

.workflow-step.error::before { background: var(--rose); }

.workflow-step.error .workflow-dot {
  background: var(--rose);
  box-shadow: 0 0 6px var(--rose);
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(.72); opacity: .55; }
}

.upload-console-grid {
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(300px, 1fr) minmax(360px, 1.05fr);
  gap: 14px;
  align-items: stretch;
}

.upload-dropzone {
  min-height: 130px;
  position: relative;
  display: flex;
  align-items: center;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.upload-dropzone:hover,
.upload-dropzone.drag-over,
.upload-dropzone:focus {
  border-color: rgba(56,189,248,.6);
  border-style: solid;
  background: var(--sky-dim);
  box-shadow: 0 0 0 3px rgba(56,189,248,.10), inset 0 0 40px rgba(56,189,248,.04);
}

.upload-dropzone.drag-over {
  animation: dropzonePulse 0.8s ease-in-out infinite alternate;
}

@keyframes dropzonePulse {
  from { box-shadow: 0 0 0 3px rgba(56,189,248,.10); }
  to   { box-shadow: 0 0 0 6px rgba(56,189,248,.20); }
}

.upload-dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-empty,
.selected-file {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
}

.upload-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--sky-dim);
  color: var(--sky);
}

.upload-empty b,
.selected-file b {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.upload-empty span,
.selected-file span {
  display: block;
  margin-top: 2px;
  color: var(--text-3);
  font-size: 12px;
}

.upload-empty .btn {
  margin-left: auto;
}

.selected-file-main {
  min-width: 0;
  flex: 1;
}

.selected-file-main b,
.selected-file-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gemini-console {
  min-height: 130px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--code-bg);
}

.drive-panel {
  min-height: 130px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.drive-panel header {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}

.drive-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sky);
  box-shadow: 0 0 6px rgba(56, 189, 248, .45);
  flex-shrink: 0;
}

.drive-status {
  max-width: 42%;
  color: var(--text-3);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drive-status.connected {
  color: var(--emerald);
}

.drive-status.error {
  color: var(--rose);
}

.drive-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 32px;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.drive-folder-select {
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  outline: none;
}

.drive-file-list {
  flex: 1;
  min-height: 0;
  max-height: 202px;
  overflow: auto;
  padding: 6px;
}

.drive-file-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

.drive-file-row:hover {
  border-color: var(--border);
  background: var(--surface-2);
}

.drive-file-main {
  min-width: 0;
}

.drive-file-main b,
.drive-file-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drive-file-main b {
  color: var(--text);
  font-size: 12px;
}

.drive-file-main span {
  margin-top: 1px;
  color: var(--text-3);
  font-size: 11px;
}

.drive-empty {
  height: 100%;
  min-height: 80px;
  display: grid;
  place-items: center;
  padding: 12px;
  color: var(--text-3);
  font-size: 12px;
  text-align: center;
}

.manual-rag-grid {
  display: grid;
  grid-template-columns: minmax(280px, .75fr) minmax(340px, .95fr) minmax(380px, 1.3fr);
  grid-template-rows: minmax(420px, 1fr) minmax(150px, auto);
  gap: 14px;
  min-height: calc(100vh - 132px);
}

.manual-drive-panel,
.manual-docs-panel,
.manual-chat-panel {
  min-height: 0;
}

.manual-drive-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.manual-folder-status {
  min-height: 34px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-3);
  background: var(--surface);
  font-size: 11px;
  line-height: 1.5;
}

.manual-folder-status.ready {
  color: var(--success);
}

.manual-folder-status.error {
  color: var(--danger);
}

.manual-file-list,
.manual-document-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.manual-file-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

.manual-file-row:hover {
  border-color: var(--border);
  background: var(--surface-2);
}

.drive-file-main .manual-file-mode {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  margin-top: 5px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  background: var(--surface);
  font-size: 10px;
  line-height: 1.2;
}

.drive-file-main .manual-file-mode.recommended {
  border-color: rgba(48, 209, 88, 0.45);
  color: var(--success);
}

.drive-file-main .manual-file-mode.best-effort {
  border-color: rgba(255, 204, 102, 0.45);
  color: var(--warning);
}

.manual-document-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: 8px;
}

.manual-document-card header {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}

.manual-document-card header div {
  min-width: 0;
}

.manual-document-card b,
.manual-document-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manual-document-card b {
  color: var(--text);
  font-size: 12px;
}

.manual-document-card span {
  color: var(--text-3);
  font-size: 11px;
}

.manual-document-card pre {
  max-height: 170px;
  margin: 0;
  overflow: auto;
  padding: 10px;
  color: var(--text-2);
  font-family: 'Cascadia Code', 'Fira Code', Consolas, 'Courier New', monospace;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.manual-document-card-processing {
  border-color: rgba(109, 94, 255, 0.55);
}

.manual-processing-body {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 12px;
  color: var(--text-2);
  font-size: 12px;
}

.manual-spinner {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 2px solid rgba(166, 181, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: manual-spin 0.9s linear infinite;
}

@keyframes manual-spin {
  to {
    transform: rotate(360deg);
  }
}

.manual-chat-panel {
  grid-row: span 2;
}

.manual-chat-messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  background: var(--code-bg);
}

.manual-chat-message {
  max-width: 92%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.manual-chat-message.user {
  margin-left: auto;
  background: var(--indigo-dim);
  border-color: rgba(99,102,241,.2);
}

.manual-chat-message b {
  display: block;
  margin-bottom: 4px;
  color: var(--text-2);
  font-size: 11px;
}

.manual-chat-message p {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  white-space: pre-wrap;
}

.manual-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}

.manual-chat-form textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  padding: 9px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

.manual-log-panel {
  grid-column: span 2;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--code-bg);
}

.manual-log-panel header {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}

#manualLogOutput {
  flex: 1;
  margin: 0;
  overflow: auto;
  padding: 12px 14px;
  color: var(--code-text);
  font-family: 'Cascadia Code', 'Fira Code', Consolas, 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.gemini-console header,
.salesforce-log-panel header {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}

.console-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
}

.console-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 6px rgba(16, 185, 129, .5);
  flex-shrink: 0;
  animation: dotGlow 2s ease-in-out infinite alternate;
}

@keyframes dotGlow {
  from { box-shadow: 0 0 4px rgba(16, 185, 129, .35); }
  to   { box-shadow: 0 0 10px rgba(16, 185, 129, .65); }
}

#geminiConsoleOutput {
  flex: 1;
  margin: 0;
  min-height: 92px;
  max-height: 240px;
  overflow: auto;
  padding: 12px 14px;
  color: var(--code-text);
  font-family: 'Cascadia Code', 'Fira Code', Consolas, 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

/* =========================================================
   Summary Metrics Strip
   ========================================================= */
.summary-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(100px, 1fr));
  gap: 10px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  animation: fadeIn .35s ease both;
  position: relative;
  overflow: hidden;
}

.metric::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--grad-primary);
  opacity: 0;
  transition: opacity var(--transition);
}

.metric:hover {
  border-color: rgba(99,102,241,.25);
  box-shadow: 0 4px 16px rgba(0,0,0,.3), 0 0 0 1px rgba(99,102,241,.08);
  transform: translateY(-2px);
}

.metric:hover::after { opacity: 1; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.summary-strip .metric:nth-child(1) { animation-delay: 0ms; }
.summary-strip .metric:nth-child(2) { animation-delay: 40ms; }
.summary-strip .metric:nth-child(3) { animation-delay: 80ms; }
.summary-strip .metric:nth-child(4) { animation-delay: 120ms; }
.summary-strip .metric:nth-child(5) { animation-delay: 160ms; }
.summary-strip .metric:nth-child(6) { animation-delay: 200ms; }

.metric b {
  display: block;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}

.metric span {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
  letter-spacing: .03em;
  text-transform: uppercase;
  margin-top: 2px;
  display: block;
}

/* =========================================================
   Workspace review flow
   ========================================================= */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

/* =========================================================
   Panel
   ========================================================= */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.panel:focus-within {
  border-color: rgba(99,102,241,.2);
  box-shadow: 0 0 0 2px rgba(99,102,241,.06);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}

.panel-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.panel-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: .01em;
}

.panel-icon {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.panel-icon-blue    { background: var(--sky-dim);    color: var(--sky); }
.panel-icon-purple  { background: var(--purple-dim); color: var(--purple); }
.panel-icon-green   { background: var(--emerald-dim); color: var(--emerald); }
.panel-icon-chatwork { background: var(--teal-dim);  color: var(--teal); }

.panel-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-3);
}

.icon-action-button {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.icon-action-button:hover {
  background: var(--emerald-dim);
  color: var(--emerald);
  border-color: rgba(16,185,129,.25);
}

.json-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--purple-dim);
  color: var(--purple);
  letter-spacing: .06em;
}

.quote-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.source-select {
  width: 132px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  outline: none;
}

.quote-input {
  width: min(210px, 36vw);
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.quote-input:hover {
  background: var(--surface-3);
}

.quote-input:focus {
  border-color: var(--indigo);
  box-shadow: 0 0 0 2px rgba(99,102,241,.2);
}

.quote-input::placeholder {
  color: var(--text-3);
}

.salesforce-status {
  min-height: 34px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-3);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.salesforce-status.loaded {
  color: var(--emerald);
}

.salesforce-status.error {
  color: var(--rose);
}

/* =========================================================
   Table
   ========================================================= */
.table-wrap {
  overflow: auto;
  flex: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 9px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  background: var(--bg-2);
  color: var(--text-3);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--border-strong);
}

td { color: var(--text); }

tr:last-child td { border-bottom: 0; }

tr:hover td {
  background: rgba(99,102,241,.04);
  transition: background var(--transition);
}

.col-no     { width: 44px; text-align: center; }
.col-num    { width: 90px; text-align: right; }
.col-check  { width: 54px; text-align: center; }
.col-action { width: 58px; text-align: center; }
.col-status { width: 110px; }
.computed-col { background: rgba(99,102,241,.04); }

td.col-num { text-align: right; font-variant-numeric: tabular-nums; }

/* Editable cell inputs */
input.cell-input {
  width: 100%;
  min-width: 70px;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

input.cell-input:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

input.cell-input:focus {
  outline: none;
  border-color: var(--indigo);
  background: var(--surface-2);
  box-shadow: 0 0 0 2px rgba(99,102,241,.2);
}

.computed {
  font-weight: 600;
  color: var(--computed-text);
  font-variant-numeric: tabular-nums;
}

/* =========================================================
   Salesforce table and log
   ========================================================= */
.estimate-panel {
  display: flex;
  flex-direction: column;
  min-height: 480px;
}

.estimate-panel .panel-header {
  flex-wrap: wrap;
}

.salesforce-data-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, .55fr);
  gap: 10px;
  padding: 10px;
  background: var(--code-bg);
}

.salesforce-lines-card,
.salesforce-log-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.salesforce-subheader {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-2);
  font-size: 12px;
}

.salesforce-subheader span {
  color: var(--text-3);
  font-size: 11px;
}

.salesforce-table-wrap {
  min-height: 0;
}

.salesforce-table-wrap table {
  min-width: 720px;
}

.salesforce-table-wrap td {
  height: 38px;
  font-size: 12px;
}

.line-id {
  color: var(--text-3);
  font-family: 'Cascadia Code', 'Fira Code', Consolas, 'Courier New', monospace;
  font-size: 11px;
}

.salesforce-empty {
  color: var(--text-3);
  text-align: center;
}

#salesforceLogOutput {
  flex: 1;
  margin: 0;
  min-height: 92px;
  overflow: auto;
  padding: 10px 12px;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: 'Cascadia Code', 'Fira Code', Consolas, 'Courier New', monospace;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.estimate-json-source {
  display: none;
}

/* =========================================================
   Results Panel
   ========================================================= */
.results-panel {
  margin-top: 0;
}

/* =========================================================
   OCR Layout Manager
   ========================================================= */
.layout-manager-grid {
  display: grid;
  grid-template-columns: minmax(260px, .32fr) minmax(0, .68fr);
  gap: 14px;
  align-items: start;
}

.layout-list-panel {
  min-height: 560px;
}

.layout-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
}

.layout-list-item {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition), transform var(--transition);
  animation: fadeIn .25s ease both;
}

.layout-list-item:hover {
  border-color: rgba(99,102,241,.2);
  background: var(--surface-3);
  transform: translateX(2px);
}

.layout-list-item.active {
  border-color: rgba(99,102,241,.42);
  background: var(--indigo-dim);
  box-shadow: 0 0 0 2px rgba(99,102,241,.10), inset 3px 0 0 var(--indigo);
}

.layout-list-item b,
.layout-list-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layout-list-item b {
  font-size: 13px;
  font-weight: 700;
}

.layout-list-item span {
  margin-top: 2px;
  color: var(--text-3);
  font-size: 11px;
}

.layout-list-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.layout-source-badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text-3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.layout-source-badge.custom {
  background: var(--teal-dim);
  color: var(--teal);
}

.layout-editor-panel {
  min-height: 560px;
}

.layout-editor-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
}

.layout-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.form-field-wide {
  grid-column: 1 / -1;
}

.form-field > span,
.layout-section-header b {
  color: var(--text-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.form-field input,
.form-field select,
.form-field textarea,
.layout-field-row input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.form-field input,
.form-field select,
.layout-field-row input {
  height: 34px;
  padding: 0 10px;
}

.form-field textarea {
  min-height: 132px;
  padding: 10px;
  resize: vertical;
  line-height: 1.55;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus,
.layout-field-row input:focus {
  border-color: var(--indigo);
  background: var(--surface);
  box-shadow: 0 0 0 2px rgba(99,102,241,.18);
}

.layout-fields-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.layout-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}

.layout-section-header span {
  color: var(--text-3);
  font-size: 12px;
}

.layout-field-rows {
  display: flex;
  flex-direction: column;
}

.layout-field-row {
  display: grid;
  grid-template-columns: 150px minmax(120px, .6fr) minmax(160px, 1fr) 82px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.layout-field-row:last-child {
  border-bottom: 0;
}

.layout-field-toggle,
.layout-required-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
}

.layout-field-toggle input,
.layout-required-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--indigo);
  flex-shrink: 0;
}

.layout-field-toggle span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layout-required-toggle {
  justify-content: flex-end;
  color: var(--text-3);
  font-size: 12px;
}

.layout-text-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.layout-editor-status {
  min-height: 20px;
  color: var(--text-3);
  font-size: 13px;
}

.layout-editor-status.success {
  color: var(--emerald);
}

.layout-editor-status.error {
  color: var(--rose);
}

.danger-button:hover {
  background: var(--rose-dim);
  color: var(--rose);
  border-color: rgba(244,63,94,.25);
}

/* =========================================================
   Chatwork Groups
   ========================================================= */
.chatwork-manager-grid {
  display: grid;
  grid-template-columns: minmax(260px, .32fr) minmax(0, .68fr);
  gap: 14px;
  align-items: start;
}

.chatwork-room-list-panel,
.chatwork-room-editor-panel {
  min-height: 420px;
}

.chatwork-room-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
}

.chatwork-room-list-item {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.chatwork-room-list-item:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
}

.chatwork-room-list-item.active {
  border-color: rgba(20,184,166,.42);
  background: var(--teal-dim);
  box-shadow: 0 0 0 2px rgba(20,184,166,.10);
}

.chatwork-room-list-item b,
.chatwork-room-list-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chatwork-room-list-item b {
  font-size: 13px;
  font-weight: 700;
}

.chatwork-room-list-item span {
  margin-top: 2px;
  color: var(--text-3);
  font-size: 11px;
}

.chatwork-room-editor-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
}

.chatwork-enabled-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 600;
}

.chatwork-enabled-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.chatwork-target-panel {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chatwork-target-panel .layout-section-header {
  border-bottom: 1px solid var(--border);
}

.chatwork-target-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
  padding: 10px 16px 12px;
}

.chatwork-target-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.chatwork-target-option input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--teal);
  flex-shrink: 0;
}

.chatwork-target-option b,
.chatwork-target-option span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chatwork-target-option b {
  font-size: 13px;
}

.chatwork-target-option span {
  margin-top: 1px;
  color: var(--text-3);
  font-size: 11px;
}

.chatwork-target-empty {
  padding: 10px 16px 12px;
  color: var(--text-3);
  font-size: 13px;
}

/* =========================================================
   Status Badges
   ========================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: .03em;
  transition: transform var(--transition), box-shadow var(--transition);
}

.badge:hover {
  transform: scale(1.06);
}

.badge.matched {
  background: var(--emerald-dim);
  color: var(--emerald);
  border: 1px solid rgba(16,185,129,.2);
}

.badge.missing_in_estimate {
  background: var(--sky-dim);
  color: var(--sky);
  border: 1px solid rgba(56,189,248,.2);
}

.badge.quantity_mismatch {
  background: var(--amber-dim);
  color: var(--amber);
  border: 1px solid rgba(245,158,11,.2);
}

.badge.unit_price_mismatch {
  background: var(--amber-dim);
  color: var(--amber);
  border: 1px solid rgba(245,158,11,.2);
}

.badge.unit_price_and_quantity_mismatch {
  background: var(--rose-dim);
  color: var(--rose);
  border: 1px solid rgba(244,63,94,.2);
}

.review-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--rose-dim);
  color: var(--rose);
  font-size: 11px;
  font-weight: 800;
  border: 1px solid rgba(244,63,94,.25);
}

.row-delete-button {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.row-delete-button:hover {
  background: var(--rose-dim);
  color: var(--rose);
  border-color: rgba(244,63,94,.25);
}

/* =========================================================
   Dialog
   ========================================================= */
dialog {
  width: min(700px, calc(100% - 32px));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

dialog::backdrop {
  background: rgba(5, 7, 12, 0.75);
  backdrop-filter: blur(8px) saturate(140%);
}

dialog[open] {
  animation: dialogIn .25s cubic-bezier(.34,1.56,.64,1);
}

@keyframes dialogIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}

.dialog-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

dialog h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

dialog textarea {
  display: block;
  width: 100%;
  min-height: 320px;
  border: 0;
  resize: vertical;
  padding: 14px 16px;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: 'Cascadia Code', 'Fira Code', Consolas, 'Courier New', monospace;
  font-size: 12.5px;
  line-height: 1.6;
}

dialog textarea:focus { outline: none; }

.dialog-status {
  min-height: 34px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-3);
  font-size: 13px;
}

.dialog-status.success {
  color: var(--emerald);
}

.dialog-status.error {
  color: var(--rose);
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}

.update-dialog {
  width: min(920px, calc(100% - 32px));
}

.update-dialog-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
}

.update-plan-summary {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
}

.update-plan-summary.error {
  color: var(--rose);
  border-color: rgba(244,63,94,.25);
  background: var(--rose-dim);
}

.update-plan-table-wrap {
  max-height: min(44vh, 420px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.update-plan-table-wrap table {
  min-width: 760px;
}

.update-plan-table-wrap td {
  vertical-align: top;
}

.update-action {
  display: inline-flex;
  align-items: center;
  min-width: 58px;
  justify-content: center;
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.update-action.update {
  color: var(--sky);
  background: var(--sky-dim);
}

.update-action.create {
  color: var(--emerald);
  background: var(--emerald-dim);
}

.update-confirm-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 600;
}

.update-confirm-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--indigo);
}

.update-warning,
.empty-update-plan {
  color: var(--text-2);
}

.update-apply-status {
  min-height: 20px;
  color: var(--text-2);
  font-size: 13px;
}

.update-apply-status.success {
  color: var(--emerald);
}

.update-apply-status.error,
.update-warning {
  color: var(--rose);
}

.muted-value {
  color: var(--text-3);
}

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1100px) {
  .upload-console-grid {
    grid-template-columns: 1fr;
  }

  .salesforce-data-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 1fr) minmax(132px, .58fr);
  }

  .layout-manager-grid,
  .chatwork-manager-grid,
  .manual-rag-grid,
  .layout-text-grid {
    grid-template-columns: 1fr;
  }

  .manual-rag-grid {
    grid-template-rows: auto;
  }

  .manual-chat-panel,
  .manual-log-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .layout-field-row {
    grid-template-columns: 150px minmax(120px, 1fr);
  }

  .layout-required-toggle {
    justify-content: flex-start;
  }
}

@media (max-width: 820px) {
  :root { --sidebar-w: 0px; }

  .sidebar { display: none; }

  .main-content { margin-left: 0; padding: 16px; }

  .summary-strip {
    grid-template-columns: repeat(3, 1fr);
  }

  .workflow-status {
    grid-template-columns: 1fr;
  }

  .topbar { flex-direction: column; align-items: flex-start; }

  .topbar-actions { width: 100%; }

  .layout-form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .summary-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .layout-field-row {
    grid-template-columns: 1fr;
  }
}

/* =========================================================
   Theme Toggle Button
   ========================================================= */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  margin-bottom: 8px;
}

.theme-toggle:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-strong);
}

.theme-toggle-track {
  position: relative;
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
  transition: background var(--transition);
}

[data-theme="light"] .theme-toggle-track {
  background: var(--indigo);
  border-color: transparent;
}

.theme-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform var(--transition), background var(--transition);
}

[data-theme="light"] .theme-toggle-thumb {
  transform: translateX(13px);
  background: #ffffff;
}

.theme-toggle-label { flex: 1; }

.theme-toggle-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* dark mode: show sun, hide moon */
.theme-icon-moon { display: none; }
.theme-icon-sun  { display: block; }

/* light mode: show moon, hide sun */
[data-theme="light"] .theme-icon-sun  { display: none; }
[data-theme="light"] .theme-icon-moon { display: block; }
