/* ============================================================
   Agent UI — InsightAgent Studio
   Styles for agent-app.js timeline, history, approval, etc.
   ============================================================ */

/* ---- Runtime badge ---- */
.runtime-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  gap: 6px;
  white-space: nowrap;
}
.runtime-badge.ready {
  background: #d6f3e9;
  color: #0d5c3b;
}
.runtime-badge.warning {
  background: #fff3d6;
  color: #7a5800;
}

/* ---- Shared buttons ---- */
.secondary-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 36px;
  border-radius: 7px;
  padding: 0 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.secondary-button:hover {
  background: #eef3f6;
}
.secondary-button:disabled {
  opacity: 0.5;
  cursor: wait;
}
.danger-button {
  border: 1px solid #f0c0c0;
  background: #fff5f5;
  color: #b91c1c;
  min-height: 36px;
  border-radius: 7px;
  padding: 0 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.danger-button:hover {
  background: #fde8e8;
}
.danger-button:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* ---- History button in topbar ---- */
.history-button {
  margin-right: 8px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.interest-button {
  border-color: #9bc9c2;
  background: #f0faf8;
  color: #0f665d;
}
.account-button { color: var(--ink); }

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 10%, #dcefea, transparent 36%), #eef3f5;
}
.auth-gate[hidden] { display: none; }
.auth-card {
  width: min(430px, 100%);
  display: grid;
  gap: 18px;
  padding: 30px;
  border: 1px solid #ccd9de;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(23, 32, 42, .18);
}
.auth-brand { display: flex; align-items: center; gap: 12px; font-size: 18px; }
.auth-card h1 { margin: 0; font-size: 28px; }
.auth-card > p { margin: -7px 0 0; color: var(--muted); line-height: 1.55; }
.auth-form { display: grid; gap: 14px; }
.auth-field { display: grid; gap: 7px; color: var(--ink); font-size: 13px; font-weight: 700; }
.auth-field input,
.auth-field select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}
.auth-submit { width: 100%; justify-content: center; }
.auth-error,
.account-message { min-height: 20px; color: #b91c1c; font-size: 13px; }

.account-drawer { width: min(860px, 96vw); }
.account-body { padding: 18px 20px 32px; overflow-y: auto; display: grid; gap: 18px; }
.account-section {
  display: grid;
  gap: 11px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
}
.account-section h3,
.account-section p { margin: 0; }
.account-section p { color: var(--muted); font-size: 13px; line-height: 1.55; }
.account-summary { font-weight: 800; }
.required-password-change { border-color: #d6a63e; background: #fffaf0; }
.account-inline-form,
.account-create-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; }
.account-inline-form .account-message,
.account-create-form .account-message { grid-column: 1 / -1; }
.account-user-list { display: grid; gap: 8px; }
.account-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 12px;
  border: 1px solid #dce5e8;
  border-radius: 7px;
  background: #f8fafb;
}
.account-user-copy { display: grid; gap: 3px; }
.account-user-copy small { color: var(--muted); }
.account-user-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }

.smtp-help {
  border: 1px solid #bfd6e8;
  border-radius: 8px;
  background: #f4f9fd;
}
.smtp-help > summary { cursor: pointer; padding: 12px 14px; color: #24588a; font-weight: 800; }
.smtp-help-body { display: grid; gap: 12px; padding: 0 14px 14px; color: var(--ink); line-height: 1.58; }
.smtp-help-body p,
.smtp-help-body ol { margin: 0; }
.smtp-provider-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.smtp-provider-card { display: grid; gap: 4px; padding: 10px; border: 1px solid #d6e4ef; border-radius: 6px; background: #fff; }
.smtp-provider-card code { overflow-wrap: anywhere; color: #174e79; }
.smtp-provider-card small { color: var(--muted); }
.smtp-warning { padding: 10px; border-radius: 6px; background: #fff1f1; color: #8f1d1d; }

.interest-drawer {
  width: min(760px, 94vw);
}

.interest-body {
  padding: 18px 20px 28px;
  overflow-y: auto;
}

.member-interest-form {
  display: grid;
  gap: 16px;
}

.member-interest-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid #cfe2df;
  border-radius: 8px;
  background: #f7fbfa;
}

.member-interest-status small { color: var(--muted); text-align: right; }

.member-interest-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.member-interest-field {
  display: grid;
  align-content: start;
  gap: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.member-interest-field.full { grid-column: 1 / -1; }
.member-interest-field input,
.member-interest-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 11px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
  resize: vertical;
}

.member-interest-switches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
}

.member-interest-switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.member-interest-result {
  display: grid;
  gap: 10px;
  color: var(--ink);
}

.member-digest-item {
  display: grid;
  gap: 5px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.member-digest-item > a { color: #2458b8; font-weight: 800; text-decoration: none; }
.member-digest-item small { color: var(--muted); }
.member-digest-item ul { margin: 5px 0 0; padding-left: 20px; line-height: 1.55; }
.member-preview-files { display: flex; flex-wrap: wrap; gap: 10px; }
.member-preview-files a { color: #2458b8; font-weight: 700; }

@media (max-width: 720px) {
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .member-interest-grid { grid-template-columns: 1fr; }
  .member-interest-field.full { grid-column: auto; }
  .member-interest-status { align-items: flex-start; flex-direction: column; }
  .member-interest-status small { text-align: left; }
  .account-inline-form,
  .account-create-form,
  .smtp-provider-grid { grid-template-columns: 1fr; }
  .account-user-row { align-items: flex-start; flex-direction: column; }
}

/* ---- Run actions row ---- */
.run-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---- Approval policy ---- */
.approval-policy {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.approval-policy select {
  width: auto;
  min-width: 180px;
}

.timeline-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.timeline-log-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}
.timeline-log-actions a {
  color: var(--accent, #2f6fed);
  text-decoration: none;
}
.timeline-log-actions a:hover { text-decoration: underline; }
.log-file-item {
  border-left: 3px solid #6b7f92;
}

/* ---- Skill intro ---- */
.skill-intro p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

/* ---- Daily intelligence push ---- */
.daily-push-controls {
  border: 1px solid #b9d8d4;
  border-radius: 9px;
  padding: 16px;
  background: #f3fbfa;
  display: grid;
  gap: 12px;
}
.daily-push-control-header,
.daily-push-actions,
.daily-push-detail {
  display: flex;
  align-items: center;
  gap: 10px;
}
.daily-push-control-header,
.daily-push-detail {
  justify-content: space-between;
}
.daily-push-status {
  display: inline-grid;
  place-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e7edf2;
  color: #526270;
  font-size: 12px;
  font-weight: 800;
}
.daily-push-status.enabled { background: #d6f3e9; color: #0d5c3b; }
.daily-push-status.disabled { background: #fff3d6; color: #7a5800; }
.daily-push-status.error { background: #fde8e8; color: #b91c1c; }
.daily-push-note {
  margin: 0;
  color: #465666;
  font-size: 13px;
  line-height: 1.55;
}
.daily-push-actions { flex-wrap: wrap; }
.daily-push-details {
  display: grid;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid #cae3e0;
}
.daily-push-detail {
  align-items: flex-start;
  font-size: 12px;
}
.daily-push-detail span { color: var(--muted); }
.daily-push-detail strong { text-align: right; overflow-wrap: anywhere; }
.daily-push-audit {
  display: grid;
  gap: 9px;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid #cae3e0;
}
.daily-audit-batch {
  border: 1px solid #c8deda;
  border-radius: 7px;
  background: #fff;
}
.daily-audit-batch > summary {
  cursor: pointer;
  padding: 11px 12px;
  font-weight: 800;
}
.daily-audit-member {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-top: 1px solid #e2ecea;
}
.daily-audit-member > small,
.daily-audit-item > small { color: var(--muted); }
.daily-audit-item {
  display: grid;
  gap: 3px;
  margin-top: 6px;
  padding: 9px 10px;
  border-radius: 6px;
  background: #f5f9f8;
}
.daily-audit-item > a { color: #2458b8; font-weight: 700; text-decoration: none; }
.daily-audit-item ul { margin: 4px 0 0; padding-left: 20px; line-height: 1.5; }

/* ---- Agent Timeline ---- */
.agent-timeline {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafcfd;
  overflow: hidden;
}
.agent-timeline.resizable-height,
.console-box.resizable-height,
.files-box.resizable-height {
  display: flex;
  flex-direction: column;
}
.agent-timeline.resizable-height .timeline-body,
.console-box.resizable-height pre,
.files-box.resizable-height .file-list {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
}
.agent-timeline .console-title {
  padding: 13px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--line);
}
.timeline-body {
  min-height: 200px;
  max-height: 520px;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
}
.timeline-body .empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px 0;
}

/* Timeline cards */
.timeline-card {
  border-left: 3px solid #c6d2dd;
  background: #ffffff;
  border-radius: 6px;
  padding: 12px 14px;
  box-shadow: 0 2px 8px rgba(23,32,42,0.04);
}
.timeline-card-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--muted);
  margin-bottom: 6px;
}
.timeline-card-content {
  color: var(--ink);
  line-height: 1.55;
  word-break: break-word;
}
.timeline-card-content pre {
  background: #f4f6f8;
  border-radius: 6px;
  padding: 10px;
  font-size: 12px;
  max-height: 280px;
  overflow: auto;
  margin: 6px 0 0;
}

/* Card variants */
.timeline-card.user {
  border-left-color: var(--blue);
  background: #f5f9ff;
}
.timeline-card.assistant {
  border-left-color: var(--green);
  background: #f6fdfa;
}
.timeline-card.tool {
  border-left-color: var(--amber);
  background: #fffcf5;
}
.timeline-card.result {
  border-left-color: var(--violet);
  background: #faf8ff;
}
.timeline-card.error {
  border-left-color: var(--rose);
  background: #fff8f8;
}
.timeline-card.request {
  border-left-color: var(--blue);
  border-top: 1px solid #c9d8ee;
  border-right: 1px solid #c9d8ee;
  border-bottom: 1px solid #c9d8ee;
  background: #f8fbff;
  box-shadow: 0 4px 16px rgba(47, 111, 237, 0.1);
}
.timeline-card.request .timeline-card-title {
  color: #334250;
}
.timeline-card.notice {
  border-left-color: #93a5b7;
  background: #fafcfd;
}
.timeline-card.notice.success {
  border-left-color: var(--green);
}
.timeline-card.resolved {
  opacity: 0.6;
}

/* Timeline content styling */
.timeline-card-content p { margin: 4px 0; }
.timeline-card-content h1,
.timeline-card-content h2,
.timeline-card-content h3 { margin: 10px 0 4px; font-size: 15px; }
.timeline-card-content ul,
.timeline-card-content ol { margin: 4px 0; padding-left: 20px; }
.timeline-card-content code {
  background: #eef3f6;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}
.timeline-card-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 6px 0;
}
.timeline-card-content th,
.timeline-card-content td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}
.timeline-card-content th { background: #eef3f6; }

/* ---- Permission request cards ---- */
.timeline-card.request .request-tool {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid #9fbae4;
  border-radius: 6px;
  background: #e6efff;
  font-size: 13px;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-weight: 800;
  color: #163e82;
  margin-bottom: 8px;
  opacity: 1;
}
.timeline-card.request .request-prompt {
  font-size: 13px;
  font-weight: 700;
  color: #17202a;
  margin-bottom: 4px;
  line-height: 1.5;
}
.timeline-card.request .request-description {
  font-size: 12px;
  color: #465666;
  margin-bottom: 8px;
  line-height: 1.45;
}
.timeline-card.request .timeline-card-content pre.request-input {
  border: 1px solid #263747;
  background: #0d141c;
  color: #edf5fb;
  border-radius: 6px;
  padding: 12px;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
  line-height: 1.55;
  max-height: 200px;
  overflow: auto;
  margin: 8px 0;
  white-space: pre-wrap;
  word-break: break-word;
  opacity: 1;
  text-shadow: none;
}
.request-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.request-question {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0;
  font-size: 13px;
  font-weight: 700;
}
.request-question input {
  width: 100%;
}

/* ---- Follow-up form ---- */
.followup-form {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.followup-form textarea {
  flex: 1;
  min-height: 44px;
  max-height: 100px;
  resize: vertical;
}
.followup-form button {
  flex-shrink: 0;
}

/* ---- History overlay & drawer ---- */
.history-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(17, 25, 34, 0.45);
  display: flex;
  justify-content: flex-end;
}
.history-overlay[hidden] {
  display: none;
}
.history-drawer {
  width: 460px;
  max-width: 92vw;
  height: 100%;
  background: #ffffff;
  box-shadow: -12px 0 48px rgba(23, 32, 42, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideIn 0.2s ease-out;
}
@keyframes slideIn {
  from { transform: translateX(40px); opacity: 0.7; }
  to { transform: translateX(0); opacity: 1; }
}
body.history-open { overflow: hidden; }

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 22px 22px 14px;
  border-bottom: 1px solid var(--line);
}
.history-header h2 {
  margin: 4px 0 0;
  font-size: 24px;
}
.history-user { display: block; }
.history-close {
  width: 36px;
  height: 36px;
  font-size: 20px;
}

.history-toolbar {
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
}

.history-legacy {
  padding: 14px 22px;
  background: #fff8e6;
  border-bottom: 1px solid #f0d78c;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.history-legacy strong { font-size: 14px; }
.history-legacy small { color: var(--muted); }

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 22px 22px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.history-item {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 12px 14px;
  text-align: left;
  display: grid;
  gap: 4px;
}
.history-item:hover {
  border-color: var(--blue);
  box-shadow: 0 3px 12px rgba(47,111,237,0.08);
}
.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.history-item-header strong {
  font-size: 14px;
  line-height: 1.35;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.history-status {
  flex-shrink: 0;
  min-width: 56px;
  height: 22px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  padding: 0 8px;
  font-weight: 700;
}
.status-queued     { background: #eef3f6; color: #657282; }
.status-running    { background: #d6f3e9; color: #0d5c3b; }
.status-completed  { background: #e3f2fd; color: #0d47a1; }
.status-incomplete { background: #fff3d6; color: #8a5800; }
.status-failed     { background: #fde8e8; color: #b91c1c; }
.status-cancelled  { background: #fef3c7; color: #92400e; }
.status-interrupted{ background: #fce7f3; color: #9d174d; }

.history-meta {
  font-size: 12px;
  color: var(--muted);
}
.history-footer {
  font-size: 11px;
  color: var(--muted);
}

/* ---- File list (agent version) ---- */
.file-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.file-item:last-child { border-bottom: 0; }
.file-info strong,
.file-name-link {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 2px;
}
.file-name-link {
  color: var(--ink);
  text-decoration: none;
}
.file-name-link:hover {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.file-info small {
  font-size: 11px;
  color: var(--muted);
}
.file-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.file-actions a {
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--blue);
  background: var(--panel);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
}
.file-actions a:hover {
  border-color: var(--blue);
  background: #f5f8ff;
}

/* ---- Misc utilities ---- */
.error-text { color: var(--rose); }

/* ---- Responsive ---- */
@media (max-width: 760px) {
  .history-drawer {
    width: 100%;
    max-width: 100%;
  }
  .run-actions {
    flex-wrap: wrap;
  }
  .agent-timeline .timeline-body {
    max-height: 360px;
  }
}
.daily-processing-note { margin-top: 7px; color: #24588a; font-size: 12px; line-height: 1.5; }
.daily-warning-note { margin-top: 7px; color: #9a5b00; font-size: 12px; line-height: 1.5; }
