*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #4f46e5; --primary-hover: #4338ca; --primary-light: #eef2ff;
  --danger: #ef4444; --danger-hover: #dc2626;
  --success: #10b981; --gray-50: #f9fafb; --gray-100: #f3f4f6;
  --gray-200: #e5e7eb; --gray-300: #d1d5db; --gray-400: #9ca3af;
  --gray-500: #6b7280; --gray-600: #4b5563; --gray-700: #374151;
  --gray-800: #1f2937; --gray-900: #111827;
  --radius: 8px; --shadow: 0 1px 3px rgba(0,0,0,.08),0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -2px rgba(0,0,0,.1);
}
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--gray-50); color: var(--gray-800); min-height: 100vh; }
.header { background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff; padding: 1.5rem 2rem; text-align: center; }
.header h1 { font-size: 1.75rem; font-weight: 700; }
.header p { margin-top: .25rem; opacity: .85; font-size: .95rem; }
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; margin-bottom: 1.5rem; border: 1px solid var(--gray-200); }
.card-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; color: var(--gray-800); display: flex; align-items: center; gap: .5rem; }
.card-title .badge { font-size: .75rem; font-weight: 500; background: var(--gray-100); color: var(--gray-600); padding: .125rem .5rem; border-radius: 999px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: .25rem; }
.form-group label { font-size: .85rem; font-weight: 500; color: var(--gray-700); }
.form-group input, .form-group select, .form-group textarea {
  padding: .5rem .75rem; border: 1px solid var(--gray-300); border-radius: var(--radius);
  font-size: .9rem; transition: border-color .15s; background: #fff; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.row { display: flex; gap: 1rem; align-items: start; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border: none;
  border-radius: var(--radius); font-size: .9rem; font-weight: 500; cursor: pointer;
  transition: all .15s; text-decoration: none; font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline { background: transparent; color: var(--gray-600); border: 1px solid var(--gray-300); }
.btn-outline:hover { background: var(--gray-100); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.variables-list { display: flex; flex-direction: column; gap: .75rem; margin-top: 1rem; }
.var-item {
  background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 1rem; transition: border-color .15s;
}
.var-item:hover { border-color: var(--gray-300); }
.var-item-header { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.var-item-name { font-weight: 600; color: var(--gray-800); }
.var-item-type { font-size: .8rem; color: var(--gray-500); background: var(--gray-100); padding: .125rem .5rem; border-radius: 999px; }
.var-item-params { margin-top: .5rem; font-size: .85rem; color: var(--gray-600); display: flex; flex-wrap: wrap; gap: .5rem; }
.var-item-params span { background: #fff; border: 1px solid var(--gray-200); padding: .125rem .5rem; border-radius: 4px; }
.var-item-actions { display: flex; gap: .25rem; }
.var-count { font-size: .9rem; color: var(--gray-500); }
.table-wrap { overflow-x: auto; border: 1px solid var(--gray-200); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead { background: var(--gray-50); }
th { padding: .625rem .75rem; text-align: left; font-weight: 600; color: var(--gray-700); border-bottom: 2px solid var(--gray-200); white-space: nowrap; }
td { padding: .5rem .75rem; border-bottom: 1px solid var(--gray-100); color: var(--gray-600); }
tr:hover td { background: var(--gray-50); }
.toast {
  position: fixed; bottom: 2rem; right: 2rem; padding: .75rem 1.25rem; border-radius: var(--radius);
  color: #fff; font-size: .9rem; font-weight: 500; box-shadow: var(--shadow-md);
  transform: translateY(100px); opacity: 0; transition: all .3s; z-index: 999;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--gray-200); margin-bottom: 1rem; }
.tab-btn { padding: .625rem 1.25rem; border: none; background: none; cursor: pointer; font-size: .9rem; font-weight: 500; color: var(--gray-500); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; font-family: inherit; }
.tab-btn:hover { color: var(--gray-700); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }
.empty-state { text-align: center; padding: 2rem; color: var(--gray-400); }
.empty-state p { font-size: .9rem; }
.settings-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.var-form { background: var(--primary-light); border: 1px dashed var(--primary); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.var-form-title { font-weight: 600; font-size: .95rem; margin-bottom: .75rem; color: var(--primary); }
.var-form .form-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.var-form .extra-params { margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--gray-200); display: none; }
.var-form .extra-params.show { display: block; }
.download-section { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
@media (max-width: 640px) {
  .container { padding: 1rem; }
  .card { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .settings-row { grid-template-columns: 1fr; }
  .download-section { flex-direction: column; }
}
#ai-btn { position:fixed; bottom:24px; left:24px; z-index:998; width:56px; height:56px; border-radius:50%; border:none; background:linear-gradient(135deg,#7c3aed,#4f46e5); color:#fff; font-size:24px; cursor:pointer; box-shadow:0 4px 20px rgba(124,58,237,0.4); transition:all .2s; display:flex; align-items:center; justify-content:center; }
#ai-btn:hover { transform:scale(1.1); box-shadow:0 6px 28px rgba(124,58,237,0.5); }
#ai-btn .badge-dot { position:absolute; top:-2px; right:-2px; width:14px; height:14px; background:#10b981; border-radius:50%; border:2px solid #fff; }
#ai-config { font-size:.8rem; }
#ai-config input:focus { border-color:var(--primary); outline:none; }
#ai-status { display:inline-flex; align-items:center; gap:.25rem; font-size:.7rem; color:var(--gray-400); padding:.15rem .5rem; border-radius:999px; background:var(--gray-100); }
#ai-status.active { color:#059669; background:#f0fdf4; }
#ai-thinking { display:none; align-items:center; gap:.5rem; padding:.5rem .75rem; font-size:.8rem; color:var(--gray-500); background:var(--gray-50); border-bottom:1px solid var(--gray-200); }
#ai-thinking.show { display:flex; }
.spinner { width:16px; height:16px; border:2px solid var(--gray-200); border-top-color:var(--primary); border-radius:50%; animation:spin .6s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }
#ai-panel { position:fixed; bottom:90px; left:24px; z-index:997; width:380px; max-width:calc(100vw - 48px); height:520px; max-height:calc(100vh - 140px); background:#fff; border-radius:16px; box-shadow:0 12px 48px rgba(0,0,0,0.18); display:none; flex-direction:column; overflow:hidden; border:1px solid var(--gray-200); }
#ai-panel.open { display:flex; }
#ai-header { background:linear-gradient(135deg,#7c3aed,#4f46e5); color:#fff; padding:.75rem 1rem; display:flex; align-items:center; justify-content:space-between; flex-shrink:0; }
#ai-header strong { font-size:.9rem; }
#ai-header button { background:none; border:none; color:#fff; cursor:pointer; font-size:1.1rem; opacity:.7; }
#ai-header button:hover { opacity:1; }
#ai-msgs { flex:1; overflow-y:auto; padding:.75rem; display:flex; flex-direction:column; gap:.5rem; font-size:.85rem; }
#ai-msgs .msg { padding:.55rem .8rem; border-radius:12px; max-width:88%; line-height:1.45; animation:fadeIn .2s; }
#ai-msgs .msg.user { background:var(--primary); color:#fff; align-self:flex-end; border-bottom-right-radius:4px; }
#ai-msgs .msg.assistant { background:var(--gray-100); color:var(--gray-800); align-self:flex-start; border-bottom-left-radius:4px; }
#ai-msgs .msg.system { background:#f0fdf4; color:#166534; align-self:center; font-size:.78rem; border-radius:8px; border:1px solid #86efac; }
#ai-msgs .msg .ts { font-size:.65rem; opacity:.55; margin-top:.2rem; display:block; }
#ai-input-row { display:flex; gap:.5rem; padding:.6rem .75rem; border-top:1px solid var(--gray-200); flex-shrink:0; background:var(--gray-50); }
#ai-input-row input { flex:1; border:1px solid var(--gray-300); border-radius:24px; padding:.45rem .85rem; font-size:.85rem; outline:none; font-family:inherit; }
#ai-input-row input:focus { border-color:var(--primary); }
#ai-input-row button { width:38px; height:38px; border-radius:50%; border:none; background:var(--primary); color:#fff; cursor:pointer; font-size:1rem; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
#ai-input-row button:hover { background:var(--primary-hover); }
#ai-input-row button:disabled { opacity:.4; }
@keyframes fadeIn { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }
