/* ============================================================
   Ziekly — global styles
   Mobile-first; desktop layout via media queries (min-width).
   ============================================================ */

:root {
  --bg: #f1f3f8;
  --surface: #f8f9fb; /* light grey, never pure white */
  --surface-alt: #f0f2f6;
  --text: #1a1f2e;
  --muted: #5b6472;
  --faint: #8b93a3;
  --border: #e2e6ee;
  --border-strong: #c9cfdb;
  --primary: #d97706; /* amber brand */
  --primary-rgb: 217, 119, 6;
  --primary-strong: #b45309;
  --primary-soft: #fef7ed;
  --on-accent: #f4f6f8; /* light grey text on colored/dark backgrounds */
  --accent: var(--primary);
  --accent-bg: var(--primary-soft);
  --success: #0f9d58;
  --success-bg: #e6f6ec;
  --danger: #d32f2f;
  --danger-bg: #fdeaea;
  --warning: #b26a00;
  --warning-bg: #fdf3e0;
  --neutral-bg: #eef0f4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.08), 0 4px 14px rgba(20, 30, 60, 0.06);
  --shadow-lg: 0 10px 30px rgba(20, 30, 60, 0.14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* Mobile-first: just the mark. The wordmark appears on wider screens. */
.brand-name { display: none; }
@media (min-width: 480px) {
  .brand-name { display: inline; }
}

.brand-logo {
  flex-shrink: 0;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(var(--primary-rgb), 0.25), 0 2px 8px rgba(var(--primary-rgb), 0.18);
  transition: transform 0.15s ease;
}
.brand:hover .brand-logo { transform: translateY(-1px); }

.nav {
  display: flex;
  gap: 6px;
}

.nav a {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.nav a:hover { background: var(--neutral-bg); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-strong); }

.header-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* ---------- Profile menu ---------- */
.profile-menu { position: relative; }
.profile-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text);
}
.profile-trigger:hover { background: var(--neutral-bg); }
.profile-name { font-weight: 600; }

.profile-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 7px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.profile-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  display: none;
  z-index: 50;
}
.profile-dropdown.show { display: block; }
.profile-dropdown-info {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.profile-dropdown-info .email { font-weight: 600; font-size: 0.9rem; word-break: break-all; }
.profile-dropdown-info .org { color: var(--muted); font-size: 0.8rem; margin-top: 2px; text-transform: capitalize; }
.profile-link {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}
.profile-link:hover { background: var(--neutral-bg); text-decoration: none; }
.profile-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 0.9rem;
  text-align: left;
}
.profile-logout:hover { background: var(--danger-bg); }

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

.page-title { font-size: 1.35rem; margin: 0 0 4px; letter-spacing: -0.01em; }
.page-sub { color: var(--muted); margin: 0 0 20px; font-size: 0.95rem; }

/* ---------- Search box ---------- */
.search-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 18px 0;
}

.search-box input {
  width: 100%;
  padding: 13px 15px;
  font-size: 1.05rem;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--primary-strong); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-alt); }

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }

.btn-sm { padding: 7px 12px; font-size: 0.85rem; }

.search-actions {
  display: flex;
  gap: 10px;
}
.search-actions .btn { flex: 1; }

/* ---------- Summary bar ---------- */
.summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin: 8px 0 18px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.92rem;
}

.summary .pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
}

.pill-success { background: var(--success-bg); color: var(--success); }
.pill-error { background: var(--danger-bg); color: var(--danger); }
.pill-neutral { background: var(--neutral-bg); color: var(--muted); }

/* ---------- Results grid ---------- */
.results-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 4px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.panel-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--neutral-bg);
  font-size: 1.1rem;
}

.panel-title { font-weight: 700; font-size: 0.98rem; flex: 1; }

.panel-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-found { background: var(--success-bg); color: var(--success); }
.status-notfound { background: var(--neutral-bg); color: var(--muted); }
.status-error { background: var(--danger-bg); color: var(--danger); }
.status-loading { background: var(--warning-bg); color: var(--warning); }
.status-disconnected { background: var(--neutral-bg); color: var(--faint); }

.panel-body { padding: 14px; flex: 1; }

.panel-body.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  color: var(--muted);
  font-size: 0.9rem;
}

.spinner {
  width: 22px;
  height: 22px;
  margin-right: 10px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.empty-state {
  color: var(--faint);
  font-size: 0.9rem;
  text-align: center;
  padding: 24px 8px;
}

.error-state {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.86rem;
  word-break: break-word;
}

/* ---------- Panel content (per system) ---------- */
.kv-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.kv-row:last-child { border-bottom: none; }
.kv-row .k { color: var(--muted); flex-shrink: 0; }
.kv-row .v { font-weight: 600; text-align: right; word-break: break-word; }

.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  margin: 14px 0 6px;
}

.section-label:first-child { margin-top: 0; }

.list-item {
  padding: 8px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.list-item:last-child { margin-bottom: 0; }

.list-item .li-main {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-weight: 600;
}

.list-item .li-sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}

.badge-green { background: var(--success-bg); color: var(--success); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-gray { background: var(--neutral-bg); color: var(--muted); }

.tag {
  display: inline-block;
  margin: 2px 4px 2px 0;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 0.82rem;
  font-weight: 600;
}

/* Progress bar */
.progress-track {
  height: 8px;
  background: var(--neutral-bg);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
}
.progress-fill.complete { background: var(--success); }

/* ClickUp task rows */
.task-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.task-row:last-child { border-bottom: none; }

.task-check {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  border-radius: 6px;
  border: 2px solid var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  color: var(--on-accent);
}
.task-check.closed { background: var(--success); border-color: var(--success); }

.task-info { flex: 1; min-width: 0; }
.task-name { font-weight: 600; word-break: break-word; }
.task-meta { color: var(--muted); font-size: 0.82rem; margin-top: 1px; }
.task-meta .overdue { color: var(--danger); font-weight: 700; }

/* ---------- Setup page ---------- */
.setup-list { display: flex; flex-direction: column; gap: 14px; }

.setup-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.setup-row-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.setup-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--neutral-bg);
  font-size: 1.25rem;
  flex-shrink: 0;
}

.setup-row-heading {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.setup-name-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.setup-name { font-weight: 700; font-size: 1rem; line-height: 1.2; }
.setup-desc { color: var(--muted); font-size: 0.85rem; line-height: 1.35; }

.setup-status {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.setup-row-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.setup-tip {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}
.setup-tip strong { color: var(--text); }

.api-key-form { display: flex; flex-direction: column; gap: 8px; }

.api-key-form input {
  padding: 11px 13px;
  font-size: 0.95rem;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.api-key-form input:focus { outline: none; border-color: var(--primary); }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--text);
  color: var(--on-accent);
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.92rem;
  z-index: 60;
  transition: transform 0.25s ease;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ---------- Impersonation banner ---------- */
.impersonate-banner {
  display: none;
  align-items: center;
  gap: 10px;
  background: var(--warning-bg);
  color: var(--warning);
  border-bottom: 1px solid #f0d9a8;
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 600;
}
.impersonate-banner.show { display: flex; }

.impersonate-banner .btn { margin-left: auto; }

/* ---------- Footer hint ---------- */
.footer-hint {
  margin-top: 24px;
  color: var(--faint);
  font-size: 0.82rem;
  text-align: center;
}

/* ============================================================
   Auth (setup page: create org / login)
   ============================================================ */
/* Ensure the `hidden` attribute always wins over display rules
   (e.g. .auth-form uses display:flex which would override it). */
[hidden] { display: none !important; }

.auth-notice {
  background: var(--neutral-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 20px;
  font-size: 0.95rem;
}
.auth-notice a { color: var(--accent); }

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.auth-tab {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
}
.auth-tab.active {
  background: var(--accent-bg, rgba(var(--primary-rgb), 0.12));
  border-color: var(--accent);
  color: var(--accent);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.auth-form input {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  font-size: 0.95rem;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.auth-form input:focus { outline: none; border-color: var(--primary); }
.auth-form .btn { width: 100%; justify-content: center; }
.auth-form .footer-hint { margin-top: 8px; text-align: left; }
.auth-panel { max-width: 460px; margin: 0 auto; }

/* ============================================================
   Desktop layout (>= 720px)
   ============================================================ */
@media (min-width: 720px) {
  .app-header { padding: 14px 28px; }
  .container { padding: 28px 32px 72px; }

  .page-title { font-size: 1.6rem; }

  .search-box {
    flex-direction: row;
    align-items: stretch;
    max-width: 760px;
  }
  .search-box input { flex: 1; }
  .search-actions { flex-shrink: 0; }
  .search-actions .btn { flex: initial; min-width: 120px; }

  /* 2x2 panel grid on desktop */
  .results-grid {
    grid-template-columns: 1fr 1fr;
    gap: 18px;
  }

  .panel-body { padding: 18px; }

  /* Integrations: 2-column grid on desktop */
  .setup-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
  }
  /* Provider cards stack vertically within their column */
  .setup-row { flex-direction: column; align-items: stretch; }
  .setup-row-actions {
    flex-direction: column;
    align-items: stretch;
    margin-left: 0;
  }
  .api-key-form { flex-direction: row; align-items: center; }
  .api-key-form input { flex: 1; width: auto; min-width: 0; }
}

/* ============================================================
   Team page — member list
   ============================================================ */
.member-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.member-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 700;
  font-size: 1rem;
  text-transform: uppercase;
  flex-shrink: 0;
}

.member-info {
  flex: 1;
  min-width: 0;
}

.member-name {
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.member-email {
  color: var(--muted);
  font-size: 0.85rem;
  word-break: break-all;
  margin-top: 1px;
}

.member-side {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

@media (max-width: 480px) {
  .member-row {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .member-side {
    width: 100%;
    justify-content: space-between;
    padding-left: 50px;
  }
}
