*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #4f6ef7;
  --accent-hover: #3a58e0;
  --sidebar-bg: #1a1d23;
  --sidebar-text: #c9cdd6;
  --sidebar-hover: #23272f;
  --sidebar-active-border: #4f6ef7;
  --content-bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e2e4ea;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --danger: #e03e3e;
  --danger-hover: #c52f2f;
  --success: #16a34a;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 14px; color: var(--text); }

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
}

.sidebar-top { padding: 20px 0 12px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  font-weight: 600;
  font-size: 15px;
  color: #fff;
}

.nav-links { list-style: none; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link.active { background: var(--sidebar-hover); color: #fff; border-left-color: var(--sidebar-active-border); }

.nav-link i, .nav-link svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-bottom { padding: 16px 20px; border-top: 1px solid #2d3139; }

.user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}

.user-name { color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.logout-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px;
  background: none; border: none;
  color: var(--sidebar-text); cursor: pointer;
  border-radius: var(--radius); font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.logout-btn:hover { background: var(--sidebar-hover); color: #fff; }
.logout-btn i, .logout-btn svg { width: 15px; height: 15px; }

/* ── Content ── */
.content { background: var(--content-bg); overflow-y: auto; }

.section { padding: 32px 36px; }
.section.hidden { display: none; }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.section-header h2 { font-size: 20px; font-weight: 600; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: none; transition: background 0.15s;
}
.btn i, .btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #ecedf3; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px 8px; border-radius: 4px; font-size: 13px; transition: background 0.15s, color 0.15s; }
.btn-ghost:hover { background: var(--border); color: var(--text); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── Tables ── */
.table-wrap { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; box-shadow: var(--shadow); }

table { width: 100%; border-collapse: collapse; }
thead { position: sticky; top: 0; background: var(--surface); z-index: 1; }
th { padding: 11px 14px; text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fafb; }

.badge {
  display: inline-block; padding: 2px 8px;
  border-radius: 999px; font-size: 11px; font-weight: 600;
}
.badge-green { background: #dcfce7; color: #15803d; }
.badge-gray { background: #f1f2f5; color: #6b7280; }

.actions { display: flex; gap: 4px; }

.text-muted { color: var(--text-muted); }
.text-mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }

.empty-state { padding: 48px; text-align: center; color: var(--text-muted); }

/* ── Pagination ── */
.pagination {
  display: flex; align-items: center; gap: 12px;
  margin-top: 16px; justify-content: flex-end;
}
.pagination span { font-size: 13px; color: var(--text-muted); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  padding: 28px;
}

.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 20px; }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

.modal-error {
  background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca;
  border-radius: var(--radius); padding: 10px 14px;
  font-size: 13px; margin-top: 14px;
}
.modal-error.hidden { display: none; }

/* ── Forms ── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,110,247,0.12);
}
.field textarea { resize: vertical; min-height: 90px; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }
.field-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: block; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field input[type="checkbox"] { width: auto; }

/* ── Key reveal ── */
.key-reveal-box {
  background: #f0f4ff; border: 1px solid #c7d4fd;
  border-radius: var(--radius); padding: 14px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px; word-break: break-all;
  margin: 12px 0;
}
.key-reveal-warning {
  background: #fffbeb; border: 1px solid #fde68a;
  border-radius: var(--radius); padding: 10px 14px;
  font-size: 13px; color: #92400e;
  margin-bottom: 14px;
}

/* ── Login ── */
.login-page {
  background: var(--content-bg);
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 40px 36px;
  width: 100%; max-width: 400px;
}

.login-logo {
  display: flex; justify-content: center;
  margin-bottom: 16px; color: var(--accent);
}

.login-card h1 { text-align: center; font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.login-subtitle { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 28px; }

.login-card .field { margin-bottom: 18px; }
.login-card .field label { font-weight: 500; }

.login-card button[type="submit"] {
  width: 100%; padding: 10px;
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
  margin-top: 8px;
}
.login-card button[type="submit"]:hover { background: var(--accent-hover); }
.login-card button[type="submit"]:disabled { opacity: 0.6; cursor: not-allowed; }

.error-msg {
  background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca;
  border-radius: var(--radius); padding: 10px 14px;
  font-size: 13px; margin-bottom: 12px;
}
.error-msg.hidden { display: none; }

/* ── Log body expand ── */
.log-body-cell { max-width: 280px; }
.log-body-short { color: var(--text-muted); font-size: 12px; font-family: 'SF Mono', 'Fira Code', monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; cursor: pointer; }
.log-body-short:hover { color: var(--accent); }

/* ── Webhook Logs ── */
.header-controls { display: flex; align-items: center; gap: 8px; }

.autorefresh-select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; font-family: inherit; background: var(--surface); color: var(--text);
  cursor: pointer; outline: none;
}
.autorefresh-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,110,247,0.12); }

.filter-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 20px; box-shadow: var(--shadow);
}

.filter-datetime { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.filter-datetime label { color: var(--text-muted); white-space: nowrap; }
.filter-datetime input {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; font-family: inherit; outline: none;
}
.filter-datetime input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,110,247,0.12); }

.multiselect { position: relative; }
.multiselect-trigger { min-width: 160px; gap: 6px; }
.multiselect-trigger svg { width: 14px; height: 14px; flex-shrink: 0; }

.multiselect-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 200;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 200px; max-height: 280px; overflow-y: auto; padding: 6px 0;
}
.multiselect-dropdown.hidden { display: none; }

.multiselect-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; cursor: pointer; font-size: 13px; user-select: none;
}
.multiselect-item:hover { background: var(--content-bg); }
.multiselect-item input[type="checkbox"] { width: auto; margin: 0; cursor: pointer; }
.multiselect-item.all-item { border-bottom: 1px solid var(--border); font-weight: 500; }

/* ── Webhook log detail popup ── */
.modal-card.modal-wide { max-width: 820px; }

.modal-detail-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px; gap: 12px;
}
.modal-detail-header .modal-title { margin-bottom: 0; }

.modal-detail-meta {
  background: var(--content-bg); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 20px;
}
.modal-detail-row {
  display: grid; grid-template-columns: 130px 1fr;
  padding: 9px 16px; border-bottom: 1px solid var(--border); font-size: 13px;
  align-items: baseline;
}
.modal-detail-row:last-child { border-bottom: none; }
.modal-detail-label { font-weight: 500; color: var(--text-muted); }
.modal-detail-value { word-break: break-all; }

.modal-detail-section { margin-bottom: 20px; }
.modal-detail-section-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px;
}
.modal-detail-code {
  background: #f8f9fc; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px;
  line-height: 1.6; overflow-x: auto; overflow-y: auto; max-height: 380px;
  white-space: pre-wrap; word-break: break-all;
}
