/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #1a1a1a;
  background: #f5f5f5;
  line-height: 1.5;
}

/* Header */
header {
  background: #fff;
  border-bottom: 1px solid #ddd;
  padding: 12px 0;
}
.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header h1 { font-size: 18px; font-weight: 600; }

/* Main content */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* Buttons */
.btn-link {
  background: none;
  border: none;
  color: #2563eb;
  cursor: pointer;
  font-size: 13px;
}
.btn-link:hover { text-decoration: underline; }
.btn-small {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.btn-small:hover { background: #f0f0f0; }

/* Search form */
#search-form {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.search-row input {
  flex: 1;
  padding: 10px 14px;
  font-size: 15px;
  border: 1px solid #ccc;
  border-radius: 6px;
  outline: none;
}
.search-row input:focus { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
#search-btn {
  padding: 10px 24px;
  font-size: 15px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}
#search-btn:hover { background: #1d4ed8; }

/* Filter row */
.filter-row {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}
.filter-row label {
  font-size: 13px;
  color: #555;
  display: flex;
  align-items: center;
  gap: 4px;
}
.filter-row select {
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
}
.extra-filters { margin-top: 10px; }

/* Results */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 13px;
  color: #555;
}

.result-card {
  background: #fff;
  border: 1px solid #ddd;
  border-left: 4px solid #2563eb;
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: box-shadow .15s;
}
.result-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.result-card.attachment { border-left-color: #ea580c; }

.result-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.result-title { font-weight: 600; font-size: 14px; color: #1a1a1a; }
.result-score { font-size: 11px; color: #888; font-family: monospace; }
.result-type {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 3px;
  margin-right: 6px;
}
.result-type.email { background: #dbeafe; color: #1e40af; }
.result-type.attachment { background: #ffedd5; color: #9a3412; }
.result-meta { font-size: 12px; color: #666; margin-bottom: 4px; }
.result-snippet { font-size: 13px; color: #444; }
.result-snippet mark { background: #fef08a; padding: 0 2px; border-radius: 2px; }

/* Pagination */
#pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}
#pagination button {
  padding: 6px 14px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}
#pagination button:disabled { opacity: .4; cursor: default; }
.page-jump {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #555;
}
#page-input {
  width: 52px;
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
  -moz-appearance: textfield;
}
#page-input::-webkit-outer-spin-button,
#page-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#page-go-btn {
  padding: 4px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}
#page-go-btn:hover { background: #f0f0f0; }

/* Result card actions */
.result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.card-download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 4px;
  color: #666;
  text-decoration: none;
  font-size: 16px;
  line-height: 1;
}
.card-download-btn:hover { background: #f0f0f0; color: #2563eb; }
.card-att-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fafafa;
  cursor: pointer;
  font-size: 12px;
  color: #555;
  line-height: 1.4;
}
.card-att-btn:hover { background: #f0f0f0; border-color: #bbb; }
.card-att-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 10;
  min-width: 240px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  margin-top: 4px;
  padding: 4px 0;
}
.card-att-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12px;
}
.card-att-item:hover { background: #f8f8f8; }
.card-att-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #333;
}
.card-att-size { color: #888; white-space: nowrap; }
.card-att-dl {
  color: #666;
  text-decoration: none;
  font-size: 15px;
  line-height: 1;
}
.card-att-dl:hover { color: #2563eb; }

/* Loading */
#loading {
  text-align: center;
  padding: 40px 0;
  color: #666;
  font-size: 14px;
}
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid #ddd;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin-bottom: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
#empty-state {
  text-align: center;
  padding: 60px 0;
  color: #888;
  font-size: 15px;
}

/* Stats view */
.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.stats-header h2 { font-size: 18px; }
#stats-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 13px;
}
#stats-content th, #stats-content td {
  padding: 6px 12px;
  border-bottom: 1px solid #eee;
  text-align: left;
}
#stats-content th { font-weight: 600; color: #555; background: #fafafa; }
.stat-number { font-family: monospace; text-align: right !important; }
.stat-big {
  font-size: 28px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 4px;
}
.stat-label { font-size: 12px; color: #888; }
.stat-cards {
  display: flex;
  gap: 20px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 16px 24px;
  flex: 1;
  text-align: center;
}

/* Detail panel */
#detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 50%;
  max-width: 600px;
  height: 100vh;
  background: #fff;
  border-left: 1px solid #ddd;
  box-shadow: -4px 0 16px rgba(0,0,0,.08);
  overflow-y: auto;
  z-index: 100;
  transform: translateX(100%);
  transition: transform .2s ease;
}
#detail-panel.open { transform: translateX(0); }
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid #eee;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
#detail-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #666;
  line-height: 1;
}
#detail-title { font-size: 16px; font-weight: 600; flex: 1; }
#detail-content { padding: 16px; }
#detail-content dl { font-size: 13px; margin-bottom: 16px; }
#detail-content dt { font-weight: 600; color: #555; margin-top: 10px; }
#detail-content dd { margin-left: 0; color: #333; }
#detail-content pre {
  background: #f8f8f8;
  border: 1px solid #eee;
  border-radius: 4px;
  padding: 12px;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 500px;
  overflow-y: auto;
}
.att-list { list-style: none; }
.att-list li {
  padding: 6px 0;
  border-bottom: 1px solid #eee;
  font-size: 13px;
}
.att-list a { color: #2563eb; cursor: pointer; text-decoration: none; }
.att-list a:hover { text-decoration: underline; }
.download-link {
  display: inline-block;
  margin-left: 6px;
  font-size: 14px;
  color: #666;
  text-decoration: none;
  vertical-align: middle;
}
.download-link:hover { color: #2563eb; }
.btn-download {
  display: inline-block;
  padding: 8px 16px;
  background: #2563eb;
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}
.btn-download:hover { background: #1d4ed8; }
.att-text-toggle {
  background: none;
  border: none;
  color: #2563eb;
  cursor: pointer;
  font-size: 12px;
  margin-left: 8px;
}

/* Overlay */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.2);
  z-index: 99;
}

/* Utility */
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 700px) {
  #detail-panel { width: 100%; max-width: none; }
  .stat-cards { flex-direction: column; }
}
