:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --text: #1f2a24;
  --muted: #66756b;
  --border: #d8d1c4;
  --accent: #4e6f45;
  --accent-dark: #35512f;
  --danger: #9c2f2f;
  --warning-bg: #fff7df;
  --success-bg: #eaf7ea;
  --error-bg: #fdecec;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

.site-header {
  background: linear-gradient(135deg, #334b2d, #5c7d4d);
  color: #fff;
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow);
}

.site-header h1 {
  margin: 0 0 .75rem 0;
  font-size: 1.45rem;
  font-weight: 650;
}

.site-header nav {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

.site-header nav a {
  color: #fff;
  text-decoration: none;
  padding: .45rem .7rem;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: .45rem;
}

.site-header nav a:hover { background: rgba(255,255,255,.15); }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem;
}

a { color: var(--accent-dark); }

h2 { margin: .25rem 0 1rem; }

.card,
.panel,
.message-card,
section.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: .75rem;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.stats,
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.title-row,
.actions-row,
.toolbar,
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
  margin: .75rem 0 1rem;
}

.title-row { justify-content: space-between; }

form label {
  display: block;
  margin: .65rem 0;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  max-width: 720px;
  padding: .55rem .65rem;
  border: 1px solid var(--border);
  border-radius: .45rem;
  font: inherit;
  background: #fff;
}

.filters input,
.filters select,
.toolbar input,
.toolbar select { width: auto; min-width: 12rem; }

textarea { min-height: 8rem; }

button,
.button {
  display: inline-block;
  border: 0;
  border-radius: .45rem;
  background: var(--accent);
  color: #fff;
  padding: .55rem .85rem;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button:hover { background: var(--accent-dark); }

button.danger,
.button.danger { background: var(--danger); }

.button.secondary { background: #6e756f; }

button:disabled { opacity: .55; cursor: not-allowed; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: .75rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}

th,
td {
  padding: .7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  text-align: left;
}

th { background: #ece7dd; font-weight: 650; }
tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: .15rem .55rem;
  background: #e8eee4;
  color: var(--accent-dark);
  font-size: .85rem;
  font-weight: 700;
}

.message-card {
  margin: 1rem 0;
}

.message-card.incoming { border-left: .35rem solid var(--accent); }
.message-card.outgoing { border-left: .35rem solid #5c6d8c; }
.message-card.system { border-left: .35rem solid #8c7b4a; }

.message-card h3 { margin-top: 0; }

pre.message-body,
.message-card pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  background: #faf8f4;
  border: 1px solid var(--border);
  border-radius: .45rem;
  padding: .8rem;
  overflow-x: auto;
}

.messages { margin-bottom: 1rem; }
.message {
  padding: .7rem .9rem;
  border-radius: .5rem;
  margin: .5rem 0;
  border: 1px solid var(--border);
}
.message.success { background: var(--success-bg); }
.message.error { background: var(--error-bg); }
.message.warning { background: var(--warning-bg); }

.hidden-field {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.detail-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: .35rem 1rem;
}
.detail-list dt { font-weight: 700; }
.detail-list dd { margin: 0; }

.hint,
.warning-note,
small { color: var(--muted); }

.checkbox-row { display: flex; align-items: center; gap: .5rem; }
.checkbox-row input { width: auto; }
.checkbox-grid { columns: 2; }
.small { max-width: 5rem; }

@media (max-width: 720px) {
  main { padding: .75rem; }
  .site-header { padding: .85rem; }
  .site-header h1 { font-size: 1.15rem; }
  table { display: block; overflow-x: auto; }
  .filters input,
  .filters select,
  .toolbar input,
  .toolbar select,
  input,
  select,
  textarea { width: 100%; min-width: 0; }
  .detail-list { grid-template-columns: 1fr; }
  .checkbox-grid { columns: 1; }
}

.mail-alert {
  background: #fff7df;
  border: 1px solid #dfc476;
  border-radius: .75rem;
  padding: 1rem;
  margin: 1rem 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
}

.stat-link {
  color: var(--text);
  text-decoration: none;
}

.stat-link:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.card span {
  font-size: 1.6rem;
  font-weight: 700;
}

.compact-stats {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.unread-row td {
  background: #fffdf6;
  font-weight: 650;
}

.status-new { background: #fff0d2; color: #805500; }
.status-open { background: #e8eee4; color: var(--accent-dark); }
.status-waiting { background: #e7edf7; color: #314e7a; }
.status-closed { background: #eeeeee; color: #555; }

.narrow-card {
  max-width: 760px;
}

.contact-status {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid #d0d7de;
  background: #f6f8fa;
}
.contact-status:empty {
  display: none;
}
.contact-status.success {
  border-color: #9ec5a5;
  background: #eef8f0;
}
.contact-status.error {
  border-color: #d7a0a0;
  background: #fff1f1;
}
