:root{
  --bg: #FFFFFF;
  --bg-sidebar: #F0F4F9;
  --bg-hover: #E4EAF2;
  --bg-active: #D3E3FD;
  --border: #DDE3EA;
  --border-soft: #E7EBF0;
  --text-primary: #1F1F1F;
  --text-secondary: #5F6368;
  --text-tertiary: #80868B;
  --accent: #0B57D0;
  --accent-hover: #0842A0;
  --accent-soft: #E8F0FE;
  --danger: #C5221F;
  --danger-hover: #A50E0E;
  --danger-soft: #FCE8E6;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --shadow-card: 0 1px 2px rgba(15,23,42,.06), 0 1px 6px rgba(15,23,42,.06);
  --shadow-pop: 0 8px 24px rgba(15,23,42,.14);
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'Roboto Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --cat-haikus: #9334E6;   --cat-haikus-bg: #F5EAFD;
  --cat-ias: #1A73E8;      --cat-ias-bg: #E8F0FE;
  --cat-estudio: #1E8E3E;  --cat-estudio-bg: #E6F4EA;
  --cat-meshy: #E37400;    --cat-meshy-bg: #FEF3E0;
  --cat-default: #5F6368;  --cat-default-bg: #EEF1F4;

  --fav: #B7791F;          --fav-bg: #FFF6DC;
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: var(--font-ui);
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select{ font-family: inherit; }
button{ cursor:pointer; }

.app-shell{
  display:grid;
  grid-template-columns: 300px 1fr;
  height:100vh;
  overflow:hidden;
}

/* ---------- Sidebar ---------- */
.sidebar{
  background: var(--bg-sidebar);
  display:flex;
  flex-direction:column;
  height:100%;
  padding: 14px 12px 12px;
  border-right: 1px solid var(--border-soft);
  min-height:0;
}

.sidebar-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 4px 6px 14px;
}
.brand{ display:flex; align-items:center; gap:10px; }
.brand-spark{
  width:22px; height:22px; border-radius:50%;
  background: conic-gradient(from 210deg, #4285F4, #9334E6 35%, #EA4335 65%, #F9AB00 85%, #4285F4);
  flex-shrink:0;
}
.brand-name{ font-weight:600; font-size:17px; letter-spacing:-.01em; }
.icon-btn{
  border:none; background:transparent; color: var(--text-secondary);
  width:32px; height:32px; border-radius:50%;
  display:none; align-items:center; justify-content:center;
}
.icon-btn:hover{ background: var(--bg-hover); }

.new-prompt-btn{
  display:flex; align-items:center; gap:10px;
  background:#fff; border:1px solid var(--border);
  color: var(--text-primary);
  font-size:14px; font-weight:500;
  padding:11px 16px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  margin: 0 4px 14px;
  transition: box-shadow .15s ease, background .15s ease;
}
.new-prompt-btn:hover{ background:#fafbfc; box-shadow: var(--shadow-pop); }
.new-prompt-btn svg{ color: var(--accent); flex-shrink:0; }

.search-wrap{
  position:relative;
  margin: 0 4px 12px;
}
.search-icon{
  position:absolute; left:14px; top:50%; transform:translateY(-50%);
  color: var(--text-tertiary); pointer-events:none;
}
.search-input{
  width:100%;
  padding:10px 36px 10px 40px;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  background:#fff;
  font-size:14px;
  color: var(--text-primary);
  outline:none;
  transition: box-shadow .18s ease, border-color .18s ease;
}
.search-input::placeholder{ color: var(--text-tertiary); }
.search-input:focus{
  border-color:transparent;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(66,133,244,.35), 0 2px 10px rgba(147,52,230,.18);
}
.search-clear{
  position:absolute; right:8px; top:50%; transform:translateY(-50%);
  border:none; background: var(--bg-hover); color: var(--text-secondary);
  width:22px; height:22px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
}
.search-clear:hover{ background:var(--bg-active); }

.cat-filters{
  display:flex; flex-wrap:wrap; gap:6px;
  padding: 0 4px 12px;
}
.cat-chip{
  border:none;
  font-size:12.5px; font-weight:500;
  padding:6px 12px;
  border-radius:999px;
  background: var(--cat-default-bg);
  color: var(--text-secondary);
  display:flex; align-items:center; gap:6px;
  transition: background .15s ease, color .15s ease, transform .1s ease;
  white-space:nowrap;
}
.cat-chip:hover{ filter:brightness(0.97); }
.cat-chip .dot{ width:7px; height:7px; border-radius:50%; background:currentColor; opacity:.9; }
.cat-chip.active{ background: var(--accent); color:#fff; }
.cat-chip.active .dot{ background:#fff; }

.list-meta{
  padding: 2px 10px 8px;
  font-size:12px;
  color: var(--text-tertiary);
  font-weight:500;
}

.dock-section{ margin: 0 4px 10px; }
.dock-header{
  display:flex; align-items:center; justify-content:space-between;
  font-size:11px; font-weight:700;
  color: var(--text-tertiary);
  text-transform:uppercase; letter-spacing:.05em;
  padding: 2px 8px 6px;
}
.dock-list{ display:flex; flex-direction:column; gap:2px; }
.dock-item{
  display:flex; align-items:center; gap:8px;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 8px 8px 8px 12px;
}
.dock-item:hover{ filter:brightness(0.98); }
.dock-item-title{
  flex:1; min-width:0;
  font-size:13px; font-weight:500;
  color: var(--text-primary);
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
  cursor:pointer;
}
.dock-unpin{
  border:none; background:transparent;
  color: var(--accent); opacity:.6;
  width:22px; height:22px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0;
}
.dock-unpin:hover{ opacity:1; background:rgba(11,87,208,.12); }

.prompt-list{
  flex:1;
  overflow-y:auto;
  min-height:0;
  padding: 0 4px;
  display:flex; flex-direction:column; gap:2px;
}
.prompt-item{
  display:flex; flex-direction:column; gap:3px;
  padding:10px 12px;
  border-radius: var(--radius-md);
  border:none;
  background:transparent;
  text-align:left;
  width:100%;
  color: var(--text-primary);
  transition: background .12s ease;
}
.prompt-item:hover{ background: var(--bg-hover); }
.prompt-item.active{ background: var(--bg-active); }
.prompt-item-top{ display:flex; align-items:center; gap:8px; }
.fav-btn{
  border:none; background:transparent; padding:2px;
  color: var(--text-tertiary); flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  border-radius:50%;
  cursor:pointer;
}
.fav-btn:hover{ background: var(--bg-active); color: var(--fav); }
.fav-btn.active{ color: var(--fav); }
.prompt-item-title{
  font-size:13.5px; font-weight:500;
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
  flex:1;
}
.prompt-item-snippet{
  font-size:12px; color: var(--text-tertiary);
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.cat-tag{
  font-size:10.5px; font-weight:600;
  padding:2px 7px;
  border-radius:999px;
  flex-shrink:0;
  letter-spacing:.02em;
}

.empty-list{
  padding: 30px 16px;
  text-align:center;
  color: var(--text-tertiary);
  font-size:13px;
}

.sidebar-footer{
  padding: 10px 6px 2px;
  border-top:1px solid var(--border-soft);
  margin-top:6px;
}
.footer-actions{
  display:flex; gap:2px;
}
.ghost-btn{
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:5px;
  border:none; background:transparent;
  color: var(--text-tertiary);
  font-size:11px; font-weight:500;
  padding:8px 4px;
  border-radius: var(--radius-sm);
  flex:1;
  white-space:nowrap;
}
.ghost-btn:hover{ background: var(--bg-hover); color: var(--text-secondary); }

/* ---------- Main ---------- */
.main{
  height:100%;
  overflow-y:auto;
  background: var(--bg);
}
#mainContent{
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 40px 80px;
  min-height:100%;
}

.mobile-toggle{
  display:none;
  position:fixed; top:14px; left:14px; z-index:20;
  width:38px; height:38px; border-radius:50%;
  align-items:center; justify-content:center;
  background:#fff; border:1px solid var(--border);
  box-shadow: var(--shadow-card);
  color: var(--text-primary);
}
.sidebar-scrim{ display:none; }

/* Empty state */
.state-empty{
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  text-align:center;
  min-height:70vh;
  gap:18px;
}
.state-empty .spark-big{
  width:56px; height:56px; border-radius:50%;
  background: conic-gradient(from 210deg, #4285F4, #9334E6 35%, #EA4335 65%, #F9AB00 85%, #4285F4);
}
.state-empty h2{ font-size:22px; font-weight:600; margin:0; letter-spacing:-.01em; }
.state-empty p{ font-size:14px; color: var(--text-secondary); margin:0; max-width:360px; line-height:1.6; }
.state-empty .new-prompt-btn{ margin:6px 0 0; }

/* Detail / view */
.detail-top{
  display:flex; align-items:flex-start; justify-content:space-between;
  gap:16px;
  margin-bottom: 22px;
}
.detail-heading{ display:flex; flex-direction:column; gap:10px; min-width:0; }
.detail-title{
  font-size:26px; font-weight:600; letter-spacing:-.015em;
  line-height:1.25; word-break:break-word;
}
.detail-cat-row{ display:flex; align-items:center; gap:8px; }

.action-row{ display:flex; gap:8px; flex-shrink:0; flex-wrap:wrap; justify-content:flex-end; }
.icon-action{
  display:flex; align-items:center; gap:7px;
  border:1px solid var(--border);
  background:#fff;
  color: var(--text-secondary);
  font-size:13px; font-weight:500;
  padding:8px 13px;
  border-radius: var(--radius-lg);
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.icon-action:hover{ background: var(--bg-hover); }
.icon-action.primary{ background: var(--accent); border-color: var(--accent); color:#fff; }
.icon-action.primary:hover{ background: var(--accent-hover); border-color: var(--accent-hover); }
.icon-action.danger:hover{ background: var(--danger-soft); border-color: var(--danger-soft); color: var(--danger); }
.icon-action.fav-toggle.favorited{ background: var(--fav-bg); border-color: #F0DCA0; color: var(--fav); }
.icon-action.pin-toggle.docked{ background: var(--accent-soft); border-color: #C7DBFB; color: var(--accent); }

.content-card{
  background:#fff;
  border:1px solid var(--border-soft);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 22px 24px;
}
.content-text{
  font-family: var(--font-mono);
  font-size:13.5px;
  line-height:1.75;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  margin:0;
}

.meta-line{
  font-size:12.5px; color: var(--text-tertiary);
  margin: 14px 4px 0;
}

.var-token{
  background: var(--accent-soft);
  color: var(--accent-hover);
  padding: 1px 4px;
  border-radius: 5px;
  font-weight:600;
}

/* Confirm delete inline bar */
.confirm-bar{
  display:flex; align-items:center; gap:10px;
  background: var(--danger-soft);
  border: 1px solid #F6C6C4;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size:13.5px; font-weight:500;
  margin-bottom:18px;
}
.confirm-bar .spacer{ flex:1; }
.confirm-bar button{
  border:none; background:#fff;
  padding:6px 13px; border-radius:999px;
  font-size:12.5px; font-weight:600;
}
.confirm-bar button.confirm-yes{ background: var(--danger); color:#fff; }
.confirm-bar button.confirm-yes:hover{ background: var(--danger-hover); }
.confirm-bar button.confirm-no:hover{ background: #f4f4f5; }

/* ---------- Edit form ---------- */
.form-field{ margin-bottom:18px; }
.form-label{
  display:block; font-size:12.5px; font-weight:600;
  color: var(--text-secondary); margin-bottom:7px;
  text-transform: uppercase; letter-spacing:.04em;
}
.form-input, .form-textarea{
  width:100%;
  border:1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size:14.5px;
  color: var(--text-primary);
  background:#fff;
  outline:none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-input:focus, .form-textarea:focus{
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11,87,208,.13);
}
.form-textarea{
  font-family: var(--font-mono);
  font-size:13.5px;
  line-height:1.7;
  min-height: 340px;
  resize: vertical;
}
.cat-picker{ display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.cat-picker .cat-chip{ padding:7px 14px; }
.cat-picker input.form-input{ max-width:180px; padding:7px 12px; font-size:13px; }

.form-actions{
  display:flex; gap:10px; margin-top:24px;
}
.btn{
  border:none; border-radius: var(--radius-lg);
  padding: 10px 20px;
  font-size:14px; font-weight:600;
  transition: background .12s ease, opacity .12s ease;
}
.btn-primary{ background: var(--accent); color:#fff; }
.btn-primary:hover{ background: var(--accent-hover); }
.btn-primary:disabled{ opacity:.45; cursor:default; }
.btn-secondary{ background: var(--bg-hover); color: var(--text-primary); }
.btn-secondary:hover{ background: var(--bg-active); }

/* ---------- Modal ---------- */
.modal-overlay{
  position:fixed; inset:0;
  background: rgba(15,23,42,.45);
  display:flex; align-items:center; justify-content:center;
  padding:20px;
  z-index:200;
}
.modal-card{
  background:#fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  max-width:440px; width:100%;
  max-height:82vh; overflow-y:auto;
  padding:24px;
}
.modal-card h3{ margin:0 0 6px; font-size:18px; font-weight:600; letter-spacing:-.01em; }
.modal-hint{ font-size:12.5px; color: var(--text-tertiary); margin:0 0 18px; line-height:1.5; }
.modal-field{ margin-bottom:14px; }
.modal-field label{
  display:block; font-size:12.5px; font-weight:600;
  color: var(--text-secondary); margin-bottom:6px;
}
.modal-textarea{
  min-height:44px; max-height:220px;
  resize:vertical;
  line-height:1.5;
  overflow-y:auto;
}
.modal-actions{
  display:flex; gap:10px; justify-content:flex-end;
  margin-top:8px;
}

/* ---------- Toast ---------- */
.toast{
  position:fixed;
  bottom:24px; left:50%; transform:translateX(-50%) translateY(20px);
  background:#1F1F1F; color:#fff;
  font-size:13.5px; font-weight:500;
  padding:12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow-pop);
  opacity:0; pointer-events:none;
  transition: opacity .2s ease, transform .2s ease;
  z-index:100;
  display:flex; align-items:center; gap:8px;
}
.toast.show{ opacity:1; transform:translateX(-50%) translateY(0); }

/* ---------- Scrollbar ---------- */
.prompt-list::-webkit-scrollbar, .main::-webkit-scrollbar{ width:8px; }
.prompt-list::-webkit-scrollbar-thumb{ background: #C6CDD6; border-radius:4px; }
.main::-webkit-scrollbar-thumb{ background: #E1E5EA; border-radius:4px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px){
  .app-shell{ grid-template-columns: 1fr; }
  .mobile-toggle{ display:flex; }
  .sidebar{
    position:fixed; top:0; left:0; bottom:0; width:300px; max-width:84vw;
    z-index:30;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-pop);
  }
  .sidebar.open{ transform: translateX(0); }
  .icon-btn{ display:flex; }
  .sidebar-scrim.show{
    display:block; position:fixed; inset:0; background:rgba(15,23,42,.35); z-index:25;
  }
  #mainContent{ padding: 72px 20px 60px; }
  .detail-top{ flex-direction:column; }
  .action-row{ width:100%; }
  .icon-action{ flex:1; justify-content:center; }
}

@media (prefers-reduced-motion: reduce){
  *{ transition:none !important; }
}
