* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f6f7f9;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: #1f2937;
  color: #f3f4f6;
}
.topbar .brand a { color: #f3f4f6; font-weight: 600; text-decoration: none; }
.topbar nav { flex: 1; display: flex; gap: 16px; }
.topbar nav a { color: #cbd5e1; text-decoration: none; }
.topbar nav a:hover { color: #fff; }
.topbar .logout { display: flex; align-items: center; gap: 12px; margin: 0; }
.topbar .user { color: #cbd5e1; font-size: 13px; }
.topbar .link-btn {
  background: transparent; border: 1px solid #475569; color: #f3f4f6;
  padding: 4px 10px; border-radius: 4px; cursor: pointer;
}

main { max-width: 1100px; margin: 24px auto; padding: 0 24px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 8px; }

.back { display: inline-block; margin-bottom: 12px; color: #475569; text-decoration: none; }
.back:hover { text-decoration: underline; }

.alert { padding: 10px 14px; border-radius: 6px; margin: 12px 0; }
.alert.error { background: #fee2e2; color: #991b1b; }
.alert.warning { background: #fef3c7; color: #92400e; }

.filters { display: flex; gap: 16px; margin: 12px 0 16px; align-items: end; flex-wrap: wrap; }
.filters label { display: flex; flex-direction: column; font-size: 12px; color: #475569; }
.filters select, .filters button { padding: 6px 10px; }

table.queue { width: 100%; border-collapse: collapse; background: #fff; }
table.queue th, table.queue td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #e5e7eb; }
table.queue th { font-size: 12px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.04em; }
table.queue td.preview { color: #475569; }
table.queue tr:hover { background: #f9fafb; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-approved { background: #dbeafe; color: #1e3a8a; }
.badge-edited   { background: #ede9fe; color: #5b21b6; }
.badge-rejected { background: #f3f4f6; color: #374151; }
.badge-sent     { background: #d1fae5; color: #065f46; }
.badge-failed   { background: #fee2e2; color: #991b1b; }

.empty { color: #6b7280; padding: 24px; text-align: center; }

dl.meta { display: grid; grid-template-columns: 200px 1fr; gap: 4px 16px; margin: 12px 0; }
dl.meta dt { color: #6b7280; }

.text-block, .meta-block {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 6px;
  padding: 12px; white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
}
.text-block.edited { border-left: 4px solid #7c3aed; }

details { margin: 8px 0; }
summary { cursor: pointer; color: #475569; }

.actions { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; margin: 16px 0; }
.actions form { margin: 0 0 16px; }
.actions form:last-child { margin-bottom: 0; }
.actions label { display: block; margin: 8px 0; }
.actions textarea, .actions input[type=text] {
  display: block; width: 100%; padding: 8px 10px; margin-top: 4px;
  border: 1px solid #cbd5e1; border-radius: 4px; font-family: inherit; font-size: 14px;
}
.actions textarea { font-family: ui-monospace, monospace; font-size: 13px; resize: vertical; }
.actions button {
  padding: 8px 16px; border-radius: 4px; cursor: pointer; font-weight: 600;
  border: 1px solid transparent;
}
.actions button.primary { background: #1d4ed8; color: #fff; }
.actions button.primary:hover { background: #1e40af; }
.actions button.danger { background: #fff; color: #b91c1c; border-color: #fca5a5; }
.actions button.danger:hover { background: #fee2e2; }

table th, table td { padding: 6px 10px; border-bottom: 1px solid #e5e7eb; font-size: 13px; }
.audit table { width: 100%; border-collapse: collapse; background: #fff; }
.audit code { font-size: 12px; color: #374151; }

.manual-form { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; }
.manual-form textarea {
  display: block; width: 100%; padding: 10px; border: 1px solid #cbd5e1; border-radius: 4px;
  font-family: ui-monospace, monospace; font-size: 13px; margin-top: 6px;
}
.manual-form button {
  margin-top: 12px; padding: 8px 16px; border: none; border-radius: 4px;
  background: #1d4ed8; color: #fff; font-weight: 600; cursor: pointer;
}
.hint { color: #6b7280; }
.hint code { background: #f3f4f6; padding: 1px 4px; border-radius: 3px; font-size: 12px; }

.alert.success { background: #d1fae5; color: #065f46; }

.settings-form { display: flex; flex-direction: column; gap: 16px; }
.settings-group {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 16px 20px; margin: 0;
}
.settings-group legend { font-weight: 600; padding: 0 8px; color: #1f2937; }
.settings-field { margin: 12px 0; }
.settings-field > label {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 13px; color: #1f2937; margin-bottom: 4px;
}
.settings-field .field-label { font-weight: 600; }
.settings-field .field-key { font-size: 11px; color: #6b7280; background: #f3f4f6; padding: 1px 6px; border-radius: 3px; }
.settings-field input[type=text],
.settings-field input[type=password],
.settings-field textarea,
.settings-field select {
  display: block; width: 100%; padding: 8px 10px;
  border: 1px solid #cbd5e1; border-radius: 4px;
  font-family: ui-monospace, monospace; font-size: 13px;
}
.settings-field textarea { resize: vertical; }
.settings-field .clear-checkbox {
  display: inline-flex !important; gap: 6px; margin-top: 6px;
  font-size: 12px; color: #b91c1c; font-weight: 400;
}
.settings-field small.hint { display: block; margin-top: 4px; font-size: 12px; color: #6b7280; }
.settings-actions { display: flex; gap: 12px; margin-top: 8px; }
.settings-actions button.primary {
  padding: 10px 18px; border: none; border-radius: 4px;
  background: #1d4ed8; color: #fff; font-weight: 600; cursor: pointer;
}
.settings-actions button.primary:hover { background: #1e40af; }

/* analytics */
.period-switcher { margin: 0 0 20px; display: flex; align-items: center; gap: 8px; font-size: 13px; color: #6b7280; }
.period-btn { padding: 4px 12px; border: 1px solid #cbd5e1; border-radius: 4px; text-decoration: none; color: #374151; font-size: 13px; }
.period-btn:hover { background: #f1f5f9; }
.period-btn.active { background: #1d4ed8; color: #fff; border-color: #1d4ed8; }

.stat-cards { display: flex; gap: 16px; margin: 0 0 28px; flex-wrap: wrap; }
.stat-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px 20px; min-width: 160px; flex: 1; }
.stat-value { font-size: 28px; font-weight: 700; color: #1f2937; line-height: 1.2; }
.stat-label { font-size: 12px; color: #6b7280; margin-top: 4px; }

.analytics-tables { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 28px; }
.analytics-table-block { flex: 1; min-width: 260px; }
.analytics-table-block table { width: 100%; border-collapse: collapse; background: #fff; }
.analytics-table-block th, .analytics-table-block td { text-align: left; padding: 7px 10px; border-bottom: 1px solid #e5e7eb; font-size: 13px; }
.analytics-table-block th { font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.04em; }

.daily-chart { display: flex; align-items: flex-end; gap: 6px; padding: 12px 0 0; background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; flex-wrap: wrap; }
.daily-bar-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 36px; }
.daily-bar { width: 28px; background: #3b82f6; border-radius: 3px 3px 0 0; min-height: 4px; transition: opacity 0.1s; }
.daily-bar:hover { opacity: 0.75; }
.daily-count { font-size: 11px; color: #374151; font-weight: 600; }
.daily-label { font-size: 11px; color: #9ca3af; }

/* login page */
body.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #1f2937; }
.login-form { background: #fff; padding: 32px; border-radius: 8px; min-width: 320px; box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
.login-form h1 { margin: 0 0 16px; }
.login-form label { display: block; margin: 12px 0; font-size: 13px; color: #475569; }
.login-form input { display: block; width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 14px; }
.login-form button { width: 100%; padding: 10px; margin-top: 16px; border: none; border-radius: 4px; background: #1d4ed8; color: #fff; font-weight: 600; cursor: pointer; }
