:root {
  --bg: #f6f4ef;
  --card: #fffef9;
  --text: #1f2a2e;
  --muted: #6d7475;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b91c1c;
  --border: #d8d4cc;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #fef3c7 0%, var(--bg) 30%, #ebe8df 100%);
  color: var(--text);
}
.container { width: calc(100vw - 32px); margin: 16px; max-width: none; }
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
h1 { margin: 0; font-family: "Bricolage Grotesque", "IBM Plex Sans", sans-serif; }
.brand-link { color: inherit; text-decoration: none; }
.brand-link:hover { text-decoration: underline; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 6px 16px rgba(31, 42, 46, 0.07);
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
input, textarea, select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: white;
}
textarea { min-height: 110px; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  display: inline-block;
  border: none;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  border-radius: 9px;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
}
.btn:hover { background: var(--accent-dark); }
.btn-secondary { background: #334155; }
.btn-danger { background: var(--danger); }
.flash { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.flash.success { background: #dcfce7; color: #166534; }
.flash.error { background: #fee2e2; color: #991b1b; }
.subtle { color: var(--muted); font-size: 0.92rem; }
.inline-form { display: inline; }
.list-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}
.list-head h2 { margin: 0; }
.mail-list {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.mail-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: #fffefb;
}
.mail-row:last-child { border-bottom: 0; }
.mail-row.batch-mode { grid-template-columns: auto 1fr auto; }
.mail-check {
  padding-left: 10px;
  display: flex;
  align-items: center;
}
.mail-check input {
  width: 16px;
  height: 16px;
}
.mail-main {
  padding: 10px 12px;
}
.mail-row:hover .mail-main { background: #f8fafc; }
.mail-line {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
}
.mail-name-link {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}
.mail-name-link:hover { text-decoration: underline; }
.mail-link { color: #1d4ed8; text-decoration: none; }
.mail-link:hover { text-decoration: underline; }
.mail-sep { color: #94a3b8; }
.more-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-size: 0.75rem;
  font-weight: 600;
}
.row-tag {
  display: inline-block;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.76rem;
}
.mail-actions {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  align-items: center;
}
.mail-actions .btn {
  padding: 8px 11px;
  font-size: 0.86rem;
}
.pager {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.pager-link {
  display: inline-block;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  background: #fff;
}
.pager-link.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.tab-btn {
  display: inline-block;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  background: #fff;
}
.tab-btn.active {
  background: #e0f2f1;
  border-color: #99f6e4;
}
.tag-bar {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-toggle { margin-top: 10px; }
.tag-toggle summary {
  cursor: pointer;
  color: #334155;
  font-weight: 600;
  user-select: none;
}
.tag-toggle[open] summary { margin-bottom: 8px; }
.batch-bar {
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}
.select-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 8px;
}
.select-all input {
  width: 16px;
  height: 16px;
}
.tag-btn {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  text-decoration: none;
  color: #334155;
  background: #f8fafc;
  font-size: 0.8rem;
}
.tag-btn.active {
  background: #0f766e;
  color: #fff;
  border-color: #0f766e;
}
.detail-contact {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #f8fafc;
}
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.detail-layout {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.2fr);
  gap: 14px;
}
.detail-left-col {
  display: grid;
  gap: 12px;
  align-content: start;
}
.detail-left-col > .detail-contact {
  margin-top: 8px;
}
.detail-left {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #fff;
}
.detail-kv {
  margin-bottom: 8px;
}
.detail-kv:last-child {
  margin-bottom: 0;
}
.detail-right {
  display: grid;
  gap: 10px;
}
.email-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.email-item {
  display: inline-block;
  text-decoration: none;
  color: #1d4ed8;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 0.9rem;
}
.email-item:hover { text-decoration: underline; }
@media (max-width: 720px) {
  .container { width: calc(100vw - 16px); margin: 8px; }
  th:nth-child(1), td:nth-child(1), th:nth-child(6), td:nth-child(6) { display: none; }
  .mail-row { grid-template-columns: auto 1fr; }
  .mail-row.batch-mode { grid-template-columns: auto 1fr; }
  .mail-check { padding-top: 10px; align-self: flex-start; }
  .mail-line { overflow-x: auto; }
  .mail-actions { padding-top: 0; padding-left: 12px; padding-bottom: 10px; }
  .detail-layout { grid-template-columns: 1fr; }
}
