/* ===================== Base / Tokens ===================== */
:root{
  --bg: #f3f4f8;
  --surface: #ffffff;
  --surface-alt: #f8f9fc;
  --border: #e6e8f0;
  --text: #1c1e2b;
  --text-muted: #6b7080;
  --text-faint: #9498a8;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef0fe;
  --accent: #d97706;
  --accent-light: #fef3e2;
  --success: #16a34a;
  --success-light: #e8f8ee;
  --danger: #e11d48;
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(20,22,40,.06);
  --shadow: 0 6px 20px rgba(20,22,40,.08);
  --shadow-lg: 0 16px 40px rgba(20,22,40,.14);
  font-size: 16px;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3{margin:0 0 4px 0; letter-spacing:-.01em}
p{margin:0}
button{font-family:inherit}
.hidden{display:none !important}

/* ===================== Topbar ===================== */
.topbar{
  position:sticky; top:0; z-index:50;
  display:flex; align-items:center; justify-content:space-between;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-left{display:flex; align-items:center; gap:28px}
.brand{display:flex; align-items:center; gap:9px}
.brand-logo{width:30px; height:30px}
.brand-name{font-weight:800; font-size:18px; letter-spacing:-.02em}

.main-nav{display:flex; gap:4px; background:var(--surface-alt); padding:4px; border-radius: 999px; border:1px solid var(--border)}
.nav-btn{
  border:none; background:transparent; padding:8px 16px; border-radius:999px;
  font-weight:600; font-size:13.5px; color:var(--text-muted); cursor:pointer;
  transition:.15s;
}
.nav-btn:hover{color:var(--text)}
.nav-btn.active{background:var(--text); color:#fff}

.topbar-right{display:flex; align-items:center; gap:10px}
.icon-btn{border:1px solid var(--border); background:var(--surface); width:36px; height:36px; border-radius:10px; cursor:pointer; font-size:15px; display:flex; align-items:center; justify-content:center}
.icon-btn:hover{background:var(--surface-alt)}
.premium-pill{font-size:11px; font-weight:700; padding:3px 9px; border-radius:999px; background:var(--surface-alt); color:var(--text-muted); border:1px solid var(--border)}
.premium-pill.on{background:linear-gradient(135deg,#fbbf24,#f59e0b); color:#fff; border-color:transparent}
.user-chip{display:flex; align-items:center; gap:8px; padding:4px 12px 4px 4px; border:1px solid var(--border); border-radius:999px; background:var(--surface)}
.user-name{font-size:13px; font-weight:600}
.avatar{
  width:26px;height:26px;border-radius:50%;display:flex;align-items:center;justify-content:center;
  color:#fff; font-size:11px; font-weight:700; flex-shrink:0; border:2px solid #fff; box-shadow:0 0 0 1px rgba(0,0,0,.05);
}

/* ===================== Main / Views ===================== */
#app{padding: 22px 24px 60px}
.view-header{display:flex; align-items:flex-start; justify-content:space-between; gap:20px; margin-bottom:20px; flex-wrap:wrap}
.view-subtitle{color:var(--text-muted); font-size:14px; max-width:640px; margin-top:4px}

/* ===================== Agent Strip ===================== */
.agent-strip-wrap{margin-bottom:18px}
.agent-strip{
  display:flex; gap:12px; overflow-x:auto; padding: 4px 2px 10px;
  scroll-snap-type:x proximity;
}
.agent-strip::-webkit-scrollbar{height:6px}
.agent-strip::-webkit-scrollbar-thumb{background:#d7d9e6; border-radius:99px}

.agent-card{
  scroll-snap-align:start;
  flex: 0 0 auto;
  width: 190px;
  display:flex; flex-direction:column; gap:8px;
  background:var(--surface); border:1.5px solid var(--border); border-radius: var(--radius);
  padding:14px; cursor:pointer; transition:.15s; text-align:left; position:relative;
}
.agent-card:hover{border-color:var(--agent-color, var(--primary)); transform:translateY(-1px); box-shadow:var(--shadow-sm)}
.agent-card.active{
  border-color: var(--agent-color, var(--primary));
  background: var(--agent-tint, var(--primary-light));
  box-shadow: var(--shadow);
}
.agent-card .agent-icon{
  width:38px; height:38px; border-radius:11px; display:flex; align-items:center; justify-content:center;
  font-size:19px; background: var(--agent-tint, var(--primary-light));
}
.agent-card.active .agent-icon{background:#fff}
.agent-card .agent-name{font-weight:700; font-size:14px}
.agent-card .agent-desc{font-size:11.5px; color:var(--text-muted); line-height:1.4; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden}
.agent-card .agent-count{font-size:11px; font-weight:700; color:var(--agent-color,var(--primary))}

.agent-card-add{
  scroll-snap-align:start; flex:0 0 auto; width:150px;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:6px;
  border:1.5px dashed var(--border); border-radius:var(--radius); background:transparent;
  color:var(--text-muted); cursor:pointer; font-size:13px; font-weight:600;
}
.agent-card-add:hover{border-color:var(--primary); color:var(--primary); background:var(--primary-light)}
.agent-card-add .plus{font-size:22px; line-height:1}

/* ===================== Workspace body (list + detail) ===================== */
.workspace-body{display:grid; grid-template-columns: 380px 1fr; gap:18px; align-items:start}
.chat-list-panel, .mail-list-panel{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg);
  display:flex; flex-direction:column; max-height: calc(100vh - 210px); overflow:hidden;
}
.panel-header{padding:16px 16px 12px; border-bottom:1px solid var(--border)}
.panel-header .ph-top{display:flex; align-items:center; gap:10px}
.panel-header .ph-icon{width:36px;height:36px;border-radius:10px;display:flex;align-items:center;justify-content:center;font-size:18px;background:var(--agent-tint,var(--primary-light))}
.panel-header h2{font-size:16px}
.panel-header .ph-desc{font-size:12.5px; color:var(--text-muted); margin-top:6px; line-height:1.4}

.panel-toolbar{display:flex; gap:8px; padding:12px 16px}
.search-input{
  flex:1; border:1px solid var(--border); border-radius:10px; padding:8px 12px; font-size:13px; background:var(--surface-alt);
}
.search-input:focus{outline:2px solid var(--primary-light); border-color:var(--primary)}

.chat-list, .mail-list{overflow-y:auto; padding: 0 10px 14px; flex:1}

.chat-card{
  width:100%; text-align:left; background:var(--surface); border:1px solid var(--border); border-radius:12px;
  padding:12px 12px; margin-bottom:8px; cursor:pointer; transition:.12s;
}
.chat-card:hover{border-color:var(--agent-color,var(--primary)); background:var(--surface-alt)}
.chat-card.selected{border-color:var(--agent-color,var(--primary)); background:var(--agent-tint,var(--primary-light))}
.chat-card-top{display:flex; align-items:center; justify-content:space-between; gap:8px}
.chat-card-title{font-weight:700; font-size:13.5px; line-height:1.3}
.status-dot{width:8px;height:8px;border-radius:50%; flex-shrink:0}
.status-neu{background:#c7c9d9}
.status-entwurf{background:var(--accent)}
.status-fertig{background:var(--success)}
.chat-card-meta{display:flex; align-items:center; justify-content:space-between; margin-top:8px}
.chat-card-updated{font-size:11px; color:var(--text-faint)}
.badge{font-size:10px; font-weight:700; padding:2px 7px; border-radius:99px}
.badge-neu{background:var(--surface-alt); color:var(--text-muted); border:1px solid var(--border)}
.badge-entwurf{background:var(--accent-light); color:#9a5b00}
.badge-fertig{background:var(--success-light); color:#0f7a34}
.mini-avatars{display:flex}
.mini-avatars .avatar{width:20px;height:20px;font-size:9px; margin-left:-6px}
.mini-avatars .avatar:first-child{margin-left:0}
.source-tag{display:inline-flex; align-items:center; gap:4px; font-size:10.5px; color:var(--text-muted); margin-top:6px}

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

/* ===================== Chat detail ===================== */
.chat-detail-panel{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg);
  min-height: calc(100vh - 210px); max-height: calc(100vh - 210px);
  display:flex; flex-direction:column; overflow:hidden;
}
.empty-state{margin:auto; text-align:center; max-width:320px; color:var(--text-muted); padding:30px}
.empty-emoji{font-size:36px; margin-bottom:10px}
.empty-state h3{font-size:15px; color:var(--text)}
.empty-state p{font-size:13px; margin-top:6px; line-height:1.5}

.detail-header{padding:16px 20px; border-bottom:1px solid var(--border); display:flex; align-items:flex-start; justify-content:space-between; gap:12px}
.detail-title-row{display:flex; align-items:center; gap:10px}
.detail-title{font-size:16px; font-weight:800}
.detail-sub{display:flex; align-items:center; gap:10px; margin-top:6px; flex-wrap:wrap}
.detail-actions{display:flex; gap:8px; flex-shrink:0}

.detail-body{flex:1; overflow-y:auto; padding: 18px 20px; display:flex; flex-direction:column; gap:14px}

.msg-row{display:flex; gap:10px; max-width:78%}
.msg-row.user{align-self:flex-end; flex-direction:row-reverse}
.msg-row .avatar{margin-top:2px}
.msg-bubble{
  padding:11px 14px; border-radius:14px; font-size:13.5px; line-height:1.55; background:var(--surface-alt); border:1px solid var(--border);
}
.msg-row.agent .msg-bubble{border-top-left-radius:4px}
.msg-row.user .msg-bubble{background:var(--primary); color:#fff; border-color:transparent; border-top-right-radius:4px}
.msg-bubble ul{margin:6px 0 0; padding-left:18px}
.msg-bubble strong{font-weight:700}
.msg-time{font-size:10px; color:var(--text-faint); margin-top:4px}

.typing-indicator{display:flex; gap:4px; padding:12px 14px; background:var(--surface-alt); border:1px solid var(--border); border-radius:14px; width:fit-content}
.typing-indicator span{width:6px;height:6px;border-radius:50%;background:var(--text-faint); animation: blink 1.2s infinite ease-in-out}
.typing-indicator span:nth-child(2){animation-delay:.2s}
.typing-indicator span:nth-child(3){animation-delay:.4s}
@keyframes blink{0%,80%,100%{opacity:.25} 40%{opacity:1}}

.starter-box{margin:auto; text-align:center; max-width:380px; padding:20px}
.starter-box .starter-icon{font-size:30px; margin-bottom:10px}
.starter-box h3{font-size:15px}
.starter-box p{font-size:13px; color:var(--text-muted); margin-top:6px; line-height:1.5}

.detail-input{display:flex; gap:10px; padding:14px 16px; border-top:1px solid var(--border)}
.detail-input textarea{
  flex:1; resize:none; border:1px solid var(--border); border-radius:12px; padding:10px 12px; font-size:13.5px;
  font-family:inherit; background:var(--surface-alt); max-height:90px;
}
.detail-input textarea:focus{outline:2px solid var(--primary-light); border-color:var(--primary)}

/* ===================== Buttons ===================== */
.btn{
  border:none; border-radius:10px; padding:9px 16px; font-weight:700; font-size:13px; cursor:pointer;
  transition:.13s; display:inline-flex; align-items:center; gap:6px; white-space:nowrap;
}
.btn-sm{padding:7px 12px; font-size:12.5px; border-radius:8px}
.btn-primary{background:var(--primary); color:#fff}
.btn-primary:hover{background:var(--primary-dark)}
.btn-accent{background:linear-gradient(135deg,#fbbf24,#f59e0b); color:#fff}
.btn-accent:hover{filter:brightness(1.05)}
.btn-ghost{background:var(--surface-alt); color:var(--text); border:1px solid var(--border)}
.btn-ghost:hover{background:#eef0f5}
.btn-outline{background:transparent; border:1.5px solid var(--border); color:var(--text)}
.btn-outline:hover{border-color:var(--primary); color:var(--primary)}
.btn-success{background:var(--success); color:#fff}
.btn-success:hover{filter:brightness(1.06)}
.btn:disabled{opacity:.55; cursor:not-allowed}
.btn-icon-only{padding:8px; border-radius:8px}

/* ===================== Mail view ===================== */
.mail-body{display:grid; grid-template-columns: 380px 1fr; gap:18px}
.mail-detail-panel{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg);
  min-height: calc(100vh - 210px); max-height: calc(100vh - 210px); overflow-y:auto;
}
.mail-item{width:100%; text-align:left; border:none; border-bottom:1px solid var(--border); background:var(--surface); padding:14px 16px; cursor:pointer; display:flex; gap:11px}
.mail-item:hover{background:var(--surface-alt)}
.mail-item.selected{background:var(--primary-light)}
.mail-item .mi-body{flex:1; min-width:0}
.mail-item .mi-top{display:flex; justify-content:space-between; gap:8px}
.mail-item .mi-from{font-weight:700; font-size:13px}
.mail-item .mi-time{font-size:11px; color:var(--text-faint); flex-shrink:0}
.mail-item .mi-subject{font-size:12.5px; font-weight:600; margin-top:2px}
.mail-item .mi-snippet{font-size:12px; color:var(--text-muted); margin-top:3px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.unread-dot{width:8px;height:8px;border-radius:50%;background:var(--primary); margin-top:4px; flex-shrink:0}

.mail-thread{padding:20px 24px}
.mail-orig{background:var(--surface-alt); border:1px solid var(--border); border-radius:14px; padding:16px}
.mail-orig-head{display:flex; justify-content:space-between; align-items:center; margin-bottom:10px}
.mail-orig-from{font-size:13px}
.mail-orig-from b{font-weight:800}
.mail-orig-body{font-size:13.5px; line-height:1.65; color:var(--text)}

.ai-draft-wrap{margin-top:18px; border:1.5px solid var(--primary); border-radius:14px; overflow:hidden}
.ai-draft-head{background:var(--primary-light); padding:10px 16px; display:flex; align-items:center; justify-content:space-between}
.ai-draft-head .adh-label{font-size:12px; font-weight:800; color:var(--primary-dark); display:flex; align-items:center; gap:6px}
.ai-draft-body textarea{width:100%; border:none; padding:16px; font-family:inherit; font-size:13.5px; line-height:1.6; resize:vertical; min-height:180px}
.ai-draft-body textarea:focus{outline:none}
.ai-draft-actions{display:flex; justify-content:space-between; align-items:center; padding:12px 16px; border-top:1px solid var(--border); background:var(--surface-alt)}

.collab-strip{display:flex; align-items:center; gap:10px; margin-top:14px; padding:10px 14px; background:var(--success-light); border-radius:12px; font-size:12.5px; color:#0f7a34}
.collab-strip.hidden{display:none}
.collab-dot{width:7px;height:7px;border-radius:50%; background:#16a34a; animation:pulse 1.4s infinite}
@keyframes pulse{0%{box-shadow:0 0 0 0 rgba(22,163,74,.5)} 70%{box-shadow:0 0 0 6px rgba(22,163,74,0)} 100%{box-shadow:0 0 0 0 rgba(22,163,74,0)}}

/* ===================== Workflows ===================== */
.workflow-grid{display:grid; grid-template-columns:repeat(auto-fill, minmax(300px,1fr)); gap:16px; margin-bottom:26px}
.workflow-card{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg); padding:18px}
.workflow-card h3{font-size:15px}
.workflow-card .wf-desc{font-size:12.5px; color:var(--text-muted); margin-top:4px; margin-bottom:14px; line-height:1.5}
.wf-steps{display:flex; flex-direction:column; gap:0}
.wf-step{display:flex; align-items:center; gap:10px; position:relative; padding-bottom:16px}
.wf-step:last-child{padding-bottom:0}
.wf-step:not(:last-child)::before{content:""; position:absolute; left:15px; top:32px; bottom:-4px; width:2px; background:var(--border)}
.wf-step-btn{
  display:flex; align-items:center; gap:10px; width:100%; text-align:left; background:none; border:none; cursor:pointer; padding:2px 0;
}
.wf-step-icon{width:32px;height:32px; border-radius:9px; display:flex; align-items:center; justify-content:center; font-size:15px; background:var(--agent-tint,var(--primary-light)); flex-shrink:0; z-index:1}
.wf-step-text .wf-step-agent{font-size:10.5px; font-weight:800; text-transform:uppercase; letter-spacing:.03em; color:var(--agent-color,var(--primary))}
.wf-step-text .wf-step-task{font-size:12.5px; font-weight:600}
.wf-step-btn:hover .wf-step-task{color:var(--primary)}

.diagram-card{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg); padding:22px;
  display:grid; grid-template-columns: 1fr 1.3fr; gap:24px; align-items:center;
}
.diagram-text h3{font-size:16px}
.diagram-text p{font-size:13.5px; color:var(--text-muted); line-height:1.6; margin-top:8px}
.diagram-img{width:100%; border-radius:12px; border:1px solid var(--border); box-shadow:var(--shadow-sm)}

/* ===================== Marketplace ===================== */
.premium-banner{display:flex; align-items:center; gap:14px; background:linear-gradient(135deg,#fff7e6,#fef0d6); border:1px solid #f3d69b; padding:10px 16px; border-radius:14px; font-size:13px; font-weight:600; color:#8a5a00}
.marketplace-filters{display:flex; gap:8px; flex-wrap:wrap; margin-bottom:18px}
.filter-chip{border:1px solid var(--border); background:var(--surface); padding:7px 14px; border-radius:999px; font-size:12.5px; font-weight:700; color:var(--text-muted); cursor:pointer}
.filter-chip.active{background:var(--text); color:#fff; border-color:var(--text)}

.marketplace-grid{display:grid; grid-template-columns:repeat(auto-fill, minmax(280px,1fr)); gap:16px}
.mp-card{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg); padding:18px; display:flex; flex-direction:column; gap:10px}
.mp-card-top{display:flex; align-items:center; justify-content:space-between}
.mp-card-icon{width:36px;height:36px;border-radius:10px; display:flex; align-items:center; justify-content:center; font-size:17px; background:var(--agent-tint,var(--primary-light))}
.mp-premium-badge{font-size:10px; font-weight:800; padding:3px 9px; border-radius:99px; background:linear-gradient(135deg,#fbbf24,#f59e0b); color:#fff}
.mp-free-badge{font-size:10px; font-weight:800; padding:3px 9px; border-radius:99px; background:var(--success-light); color:#0f7a34}
.mp-card h4{font-size:14px; margin:0}
.mp-card-desc{font-size:12.5px; color:var(--text-muted); line-height:1.5; flex:1}
.mp-card-agent{font-size:11px; font-weight:700; color:var(--agent-color,var(--primary))}
.mp-card-footer{display:flex; justify-content:flex-end; margin-top:4px}

/* ===================== Modals ===================== */
.modal-overlay{
  position:fixed; inset:0; background:rgba(20,22,35,.5); display:flex; align-items:center; justify-content:center;
  z-index:200; padding:20px;
}
.modal{background:var(--surface); border-radius:var(--radius-lg); width:100%; max-width:480px; max-height:88vh; display:flex; flex-direction:column; box-shadow:var(--shadow-lg)}
.modal-sm{max-width:400px}
.modal-header{display:flex; align-items:center; justify-content:space-between; padding:18px 20px; border-bottom:1px solid var(--border)}
.modal-header h3{font-size:16px}
.modal-close{border:none; background:var(--surface-alt); width:30px; height:30px; border-radius:8px; cursor:pointer; font-size:13px}
.modal-body{padding:18px 20px; overflow-y:auto}
.modal-hint{font-size:13px; color:var(--text-muted); line-height:1.5; margin-bottom:12px}
.modal-footer{display:flex; justify-content:flex-end; gap:10px; padding:16px 20px; border-top:1px solid var(--border)}

.field-label{display:block; font-size:12px; font-weight:700; color:var(--text-muted); margin:14px 0 6px}
.field-label:first-child{margin-top:0}
.text-input, .text-area{
  width:100%; border:1px solid var(--border); border-radius:10px; padding:9px 12px; font-size:13.5px; font-family:inherit; background:var(--surface-alt);
}
.text-area{resize:vertical}
.text-input:focus, .text-area:focus{outline:2px solid var(--primary-light); border-color:var(--primary)}

.chip-toggle-row{display:flex; flex-wrap:wrap; gap:8px}
.chip-toggle{
  display:flex; align-items:center; gap:6px; border:1.5px solid var(--border); border-radius:999px; padding:5px 12px 5px 6px;
  cursor:pointer; font-size:12.5px; font-weight:600; background:var(--surface);
}
.chip-toggle.on{border-color:var(--primary); background:var(--primary-light); color:var(--primary-dark)}
.chip-toggle .avatar{width:20px;height:20px;font-size:9px}

.premium-list{list-style:none; padding:0; margin:0; display:flex; flex-direction:column; gap:8px; font-size:13px}

.wf-step-row{display:flex; gap:8px; margin-bottom:8px; align-items:center}
.wf-step-row select{flex:1; border:1px solid var(--border); border-radius:8px; padding:7px 9px; font-size:12.5px; background:var(--surface-alt)}
.wf-step-remove{border:none; background:var(--surface-alt); width:28px; height:28px; border-radius:8px; cursor:pointer; flex-shrink:0}

/* ===================== Toasts ===================== */
.toast-container{position:fixed; bottom:22px; right:22px; z-index:400; display:flex; flex-direction:column; gap:10px}
.toast{
  background:#1c1e2b; color:#fff; padding:12px 18px; border-radius:12px; font-size:13px; font-weight:600;
  box-shadow:var(--shadow-lg); animation: toast-in .18s ease-out; display:flex; align-items:center; gap:8px;
}
@keyframes toast-in{from{opacity:0; transform:translateY(8px)} to{opacity:1; transform:translateY(0)}}

/* ===================== Responsive ===================== */
@media (max-width: 980px){
  .workspace-body, .mail-body{grid-template-columns:1fr}
  .chat-list-panel, .mail-list-panel{max-height:340px}
  .chat-detail-panel, .mail-detail-panel{min-height:420px; max-height:none}
  .diagram-card{grid-template-columns:1fr}
  .main-nav{display:none}
}
@media (max-width: 640px){
  .topbar{padding:10px 14px}
  .user-name{display:none}
  #app{padding:16px}
}
