/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #d0d0d0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --text: #111827;
  --text-muted: #6b7280;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,.12);
}

body { font: 14px/1.5 system-ui, sans-serif; background: var(--bg); color: var(--text); }

.hidden { display: none !important; }

/* ── Login ── */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 100;
}
.login-box {
  background: var(--surface); padding: 32px 40px;
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); width: 320px;
}
.login-box h2 { margin-bottom: 20px; font-size: 16px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.login-box input {
  padding: 7px 9px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px;
}
.login-box button[type=submit] {
  padding: 8px; background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius); cursor: pointer; font-size: 14px;
}
.login-box button[type=submit]:hover { background: var(--primary-hover); }
.login-error {
  background: #fee2e2; border: 1px solid #fca5a5;
  border-radius: var(--radius); padding: 8px 10px;
  font-size: 13px; color: var(--danger); margin-bottom: 8px;
}

/* ── Header ── */
.app-header {
  display: flex; align-items: center; gap: 0;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 16px; height: 42px;
  position: sticky; top: 0; z-index: 10;
}
.nav-tabs { display: flex; height: 100%; }
.nav-tab {
  display: flex; align-items: center; padding: 0 14px;
  text-decoration: none; color: var(--text-muted); font-size: 13px;
  border-bottom: 2px solid transparent; white-space: nowrap;
  transition: color .15s;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.nav-tab.disabled { opacity: .4; pointer-events: none; }

.header-project {
  margin-left: 24px; font-size: 13px; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px; flex: 1;
}
.header-project-label { font-weight: 500; }
#current-project-name { color: var(--text); font-weight: 500; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.header-user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-muted); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 13px; color: var(--text); transition: background .12s; }
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; padding: 0; }
.btn-link:hover { text-decoration: underline; }
.btn:disabled, .btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ── Main view ── */
#view { padding: 20px 24px; max-width: 1200px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 10px; }
.card-title { font-weight: 600; font-size: 14px; margin-bottom: 6px; }

/* ── Tables ── */
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; padding: 7px 10px; background: var(--bg); border-bottom: 1px solid var(--border); font-weight: 600; white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f9fafb; }

/* ── Tags ── */
.tag { display: inline-block; background: #e0e7ff; color: #3730a3; border-radius: 3px; padding: 1px 6px; font-size: 11px; margin: 1px 2px 1px 0; cursor: default; position: relative; }
.tag[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute; bottom: 110%; left: 0;
  background: #1f2937; color: #fff; padding: 4px 8px;
  border-radius: var(--radius); font-size: 11px; white-space: nowrap; z-index: 20;
}

/* ── Badges ── */
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 500; }
.badge-draft     { background: #f3f4f6; color: var(--text-muted); }
.badge-configured { background: #dbeafe; color: #1d4ed8; }
.badge-done      { background: #dcfce7; color: var(--success); }
.badge-processed { background: #dcfce7; color: var(--success); }
.badge-inbox     { background: #fef9c3; color: var(--warning); }
.badge-executable { background: #ede9fe; color: #6d28d9; }
.badge-static    { background: #f3f4f6; color: var(--text-muted); }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-group label { font-size: 13px; font-weight: 500; }
.form-group input, .form-group textarea, .form-group select {
  padding: 7px 9px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13px; font-family: inherit;
}
.form-group textarea { resize: vertical; min-height: 80px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.18); padding: 24px 28px;
  min-width: 360px; max-width: 560px; width: 100%; max-height: 90vh; overflow-y: auto;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 18px; color: var(--text-muted); line-height: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ── Toolbar ── */
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=text] { padding: 6px 9px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; min-width: 200px; }

/* ── Section heading ── */
.section-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; }

/* ── Placeholder / empty ── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state p { margin-bottom: 16px; }

/* ── SSE log ── */
.log-box { background: #111827; color: #d1fae5; font: 12px/1.6 monospace; padding: 12px; border-radius: var(--radius); max-height: 260px; overflow-y: auto; }
.log-box .log-err { color: #fca5a5; }

/* ── Subtabs ── */
.subtabs { display: flex; gap: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 3px; }
.subtab { padding: 5px 14px; border: none; background: none; border-radius: calc(var(--radius) - 1px); cursor: pointer; font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.subtab:hover { color: var(--text); background: var(--surface); }
.subtab.active { background: var(--surface); color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }

/* ── Spinner ── */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Markdown body ── */
.markdown-body { font-size: 14px; line-height: 1.7; color: var(--text); }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { font-weight: 700; margin: 18px 0 8px; }
.markdown-body h1 { font-size: 20px; }
.markdown-body h2 { font-size: 17px; }
.markdown-body h3 { font-size: 15px; }
.markdown-body p  { margin: 8px 0; }
.markdown-body code { font-family: monospace; background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.markdown-body pre { background: #111827; color: #d1fae5; padding: 12px; border-radius: var(--radius); overflow-x: auto; }
.markdown-body pre code { background: none; color: inherit; }
.markdown-body ul, .markdown-body ol { padding-left: 24px; margin: 8px 0; }
.markdown-body li { margin: 3px 0; }
.markdown-body blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--text-muted); margin: 10px 0; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.markdown-body a { color: var(--primary); }
.markdown-body table { margin: 10px 0; }
