/* CF Analytics — Dark Theme Investigation Tool */

/* Ensure the hidden attribute always works, even when CSS sets display */
[hidden] {
  display: none !important;
}

/* -- CSS Custom Properties -- */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --bg-input: #0d1117;
  --bg-hover: #252c35;
  --bg-selected: #1f3a5f;

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --text-link: #58a6ff;

  --border-color: #30363d;
  --border-subtle: #21262d;

  --accent-blue: #58a6ff;
  --accent-green: #3fb950;
  --accent-red: #f85149;
  --accent-orange: #d29922;
  --accent-purple: #bc8cff;

  --anomaly-bg: rgba(248, 81, 73, 0.1);
  --anomaly-border: rgba(248, 81, 73, 0.4);

  --btn-primary-bg: #238636;
  --btn-primary-hover: #2ea043;
  --btn-danger-bg: #da3633;
  --btn-danger-hover: #f85149;

  --radius: 6px;
  --radius-lg: 8px;

  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4);

  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
}

/* -- Reset & Base -- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--text-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* -- Header -- */
.app-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-blue);
  letter-spacing: -0.5px;
}

.tagline {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.header-nav {
  display: flex;
  gap: 1rem;
}

.nav-link {
  color: var(--text-secondary);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover, .nav-link.active {
  color: var(--text-primary);
  background: var(--bg-hover);
  text-decoration: none;
}

/* -- Footer -- */
.app-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: auto;
}

/* -- Layout -- */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
  flex: 1;
}

.investigate-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* -- Cards -- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card.full-width {
  width: 100%;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.card-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
}

/* -- Buttons -- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-bg);
  color: #fff;
}

.btn-primary:hover {
  background: var(--btn-primary-hover);
  border-color: var(--btn-primary-hover);
}

.btn-danger {
  background: var(--btn-danger-bg);
  border-color: var(--btn-danger-bg);
  color: #fff;
}

.btn-danger:hover {
  background: var(--btn-danger-hover);
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.btn-large {
  padding: 0.65rem 1.5rem;
  font-size: 0.95rem;
}

.btn-active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* -- Inputs -- */
input[type="text"],
input[type="datetime-local"],
select,
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-blue);
}

.input-datetime {
  width: auto;
  min-width: 200px;
}

.input-select {
  width: auto;
  min-width: 120px;
}

/* -- Search Bar -- */
.search-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.search-bar input {
  flex: 1;
  max-width: 500px;
}

/* -- Zone Grid -- */
.zone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.zone-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.zone-card:hover {
  border-color: var(--accent-blue);
  background: var(--bg-hover);
}

.zone-card .zone-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.zone-card .zone-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.zone-card .zone-status {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.zone-status.active {
  background: rgba(63, 185, 80, 0.15);
  color: var(--accent-green);
}

.zone-status.pending {
  background: rgba(210, 153, 34, 0.15);
  color: var(--accent-orange);
}

.zone-status.moved,
.zone-status.initializing {
  background: rgba(139, 148, 158, 0.15);
  color: var(--text-secondary);
}

/* -- Timeline Controls -- */
.timeline-controls {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.control-group label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.preset-buttons {
  display: flex;
  gap: 0.25rem;
  flex-direction: row;
  align-items: flex-end;
}

/* -- Chart -- */
.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
  margin: 1rem 0;
  cursor: crosshair;
}

/* -- Spike Selection -- */
.spike-selection {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  margin-top: 1rem;
}

.spike-selection h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.spike-controls {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.help-text {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* -- Analysis Summary -- */
.analysis-summary {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.analysis-summary strong {
  color: var(--text-primary);
}

.analysis-summary .spike-count {
  color: var(--accent-red);
  font-weight: 700;
}

.analysis-summary .baseline-count {
  color: var(--accent-green);
  font-weight: 700;
}

/* -- Tabs -- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1rem;
  overflow-x: auto;
}

.tab-btn {
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
}

.tab-btn .anomaly-count {
  background: var(--accent-red);
  color: #fff;
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 99px;
  margin-left: 0.35rem;
  font-weight: 700;
}

/* -- Signature Tables -- */
.signature-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.signature-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid var(--border-color);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.signature-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.signature-table tr:hover {
  background: var(--bg-hover);
}

.signature-table tr.anomalous {
  background: var(--anomaly-bg);
  border-left: 3px solid var(--anomaly-border);
}

.signature-table tr.anomalous:hover {
  background: rgba(248, 81, 73, 0.18);
}

.signature-table .value-cell {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.signature-table .number-cell {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.signature-table .ratio-cell {
  font-weight: 700;
}

.ratio-high {
  color: var(--accent-red);
}

.ratio-medium {
  color: var(--accent-orange);
}

.ratio-low {
  color: var(--text-secondary);
}

.tag-anomalous {
  background: rgba(248, 81, 73, 0.2);
  color: var(--accent-red);
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.tag-spike-only {
  background: rgba(188, 140, 255, 0.2);
  color: var(--accent-purple);
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.tag-normal {
  background: rgba(63, 185, 80, 0.15);
  color: var(--accent-green);
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  cursor: help;
}

/* Checkbox column for rule generation */
.signature-table .checkbox-cell {
  width: 30px;
  text-align: center;
}

.signature-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-blue);
  cursor: pointer;
}

/* -- Firewall Grid -- */
.firewall-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 1rem;
}

.firewall-group {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1rem;
}

.firewall-group h3 {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.firewall-item {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.8rem;
}

.firewall-item:last-child {
  border-bottom: none;
}

.firewall-item .item-value {
  font-family: var(--font-mono);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 250px;
}

.firewall-item .item-count {
  font-family: var(--font-mono);
  color: var(--accent-orange);
  font-weight: 600;
}

/* Action badges */
.action-block { color: var(--accent-red); }
.action-challenge { color: var(--accent-orange); }
.action-log { color: var(--text-secondary); }
.action-allow { color: var(--accent-green); }

/* -- Rules List -- */
.rules-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.rule-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1rem;
}

.rule-card .rule-description {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.rule-card .rule-dimension {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.rule-expression {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent-blue);
  white-space: pre-wrap;
  word-break: break-all;
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.copy-btn:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.copy-btn.copied {
  color: var(--accent-green);
}

/* -- Bookmarks -- */
.bookmarks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 1rem;
}

.bookmark-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.bookmark-card:hover {
  border-color: var(--accent-blue);
}

.bookmark-card .bookmark-zone {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.bookmark-card .bookmark-times {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  margin-bottom: 0.25rem;
}

.bookmark-card .bookmark-notes {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.bookmark-card .bookmark-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.bookmark-form {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.bookmark-form textarea {
  flex: 1;
  resize: vertical;
}

/* -- Loading / Spinner -- */
.loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* -- Error / Status Messages -- */
.error-message {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.3);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  color: var(--accent-red);
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

.status-message {
  font-size: 0.85rem;
  color: var(--accent-green);
}

.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

/* -- Badge -- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(210, 153, 34, 0.15);
  color: var(--accent-orange);
}

/* -- Responsive -- */
@media (max-width: 1024px) {
  .timeline-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .spike-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .input-datetime, .input-select {
    width: 100%;
    min-width: unset;
  }

  .bookmark-form {
    flex-direction: column;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  .zone-grid,
  .bookmarks-grid {
    grid-template-columns: 1fr;
  }

  .firewall-grid {
    grid-template-columns: 1fr;
  }
}

/* -- Scrollbar styling (Webkit) -- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* -- Utility -- */
.hidden { display: none !important; }
.text-mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mb-1 { margin-bottom: 0.5rem; }

/* -- Baseline Advanced Toggle -- */
.baseline-advanced {
  margin-top: 1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
}

.baseline-advanced summary {
  cursor: pointer;
  user-select: none;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.baseline-advanced summary:hover {
  color: var(--text-secondary);
}

.baseline-advanced .spike-controls {
  margin-top: 0.75rem;
}

/* ==========================================
   AI Chat Panel
   ========================================== */

.analysis-header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn-ai {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: linear-gradient(135deg, #58a6ff 0%, #bc8cff 100%);
  color: #fff;
  border: none;
  font-weight: 600;
  padding: 0.45rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-ai:hover {
  opacity: 0.85;
}

.btn-danger {
  background: var(--accent-red);
  color: #fff;
  border: none;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-status {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

.chat-messages {
  max-height: 500px;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  scroll-behavior: smooth;
}

.chat-msg {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
  line-height: 1.55;
  font-size: 0.9rem;
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--bg-selected);
  border: 1px solid rgba(88, 166, 255, 0.25);
  color: var(--text-primary);
}

.chat-msg-assistant {
  align-self: flex-start;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.chat-msg-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.chat-msg-content {
  word-break: break-word;
}

.chat-msg-content p {
  margin: 0.4em 0;
}

.chat-msg-content h3.chat-h3,
.chat-msg-content h4.chat-h4 {
  margin: 0.8em 0 0.3em;
  color: var(--accent-blue);
  font-size: 0.95rem;
}

.chat-msg-content h4.chat-h4 {
  font-size: 0.88rem;
}

.chat-msg-content ul,
.chat-msg-content ol {
  margin: 0.3em 0;
  padding-left: 1.4em;
}

.chat-msg-content li {
  margin: 0.2em 0;
}

.chat-msg-content strong {
  color: var(--text-primary);
}

.chat-msg-content code.chat-inline-code {
  background: var(--bg-input);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--accent-orange);
}

.chat-msg-content pre.chat-code {
  background: var(--bg-input);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 0.5em 0;
  border: 1px solid var(--border-color);
}

.chat-msg-content pre.chat-code code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-primary);
}

.chat-error {
  color: var(--accent-red);
}

.chat-input-area {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 0.6rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  resize: vertical;
  min-height: 2.4rem;
  max-height: 8rem;
  line-height: 1.45;
}

.chat-input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
}

.chat-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-input-area .btn {
  min-height: 2.4rem;
  align-self: flex-end;
}
