:root {
  --green-deep: #16352A;
  --green: #1F4D3A;
  --gold: #C7A03C;
  --gold-soft: #E4CA82;
  --cream: #F7F3E9;
  --ink: #1B2420;
  --danger: #B3432B;
  --white: #FFFFFF;
  --radius: 10px;
  --shadow: 0 4px 18px rgba(22, 53, 42, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: 'Work Sans', sans-serif;
  font-size: 15px;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-family: 'Spectral', serif;
  color: var(--green-deep);
  margin: 0 0 .5em;
}

a { color: var(--green); }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--green-deep), var(--green) 60%);
  padding: 20px;
}

.login-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-card .brand {
  font-family: 'Spectral', serif;
  font-size: 1.6rem;
  color: var(--green-deep);
  font-weight: 600;
  margin-bottom: 2px;
}

.login-card .brand-sub {
  color: var(--gold);
  font-size: .8rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 24px;
}

.field {
  text-align: left;
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--green-deep);
  margin-bottom: 5px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d8d0bd;
  border-radius: 6px;
  font-family: inherit;
  font-size: .95rem;
  background: var(--white);
  color: var(--ink);
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(199, 160, 60, 0.2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: .9rem;
  transition: filter .15s ease, transform .05s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--green); color: var(--white); }
.btn-primary:hover { filter: brightness(1.1); }

.btn-gold { background: var(--gold); color: var(--green-deep); }
.btn-gold:hover { filter: brightness(1.06); }

.btn-outline { background: transparent; border: 1px solid var(--green); color: var(--green); }
.btn-outline:hover { background: rgba(31, 77, 58, .08); }

.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { filter: brightness(1.1); }

.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-block { width: 100%; }

.login-error {
  background: #fbe4de;
  color: var(--danger);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: .85rem;
  margin-bottom: 14px;
  display: none;
}

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--green-deep);
  color: var(--cream);
  display: flex;
  flex-direction: column;
  padding: 22px 0;
}

.sidebar .brand {
  font-family: 'Spectral', serif;
  font-size: 1.25rem;
  color: var(--white);
  padding: 0 22px 6px;
}
.sidebar .brand-sub {
  color: var(--gold-soft);
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 0 22px 20px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  margin-bottom: 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 22px;
  color: var(--cream);
  text-decoration: none;
  font-size: .9rem;
  border-left: 3px solid transparent;
  opacity: .85;
}
.nav-item:hover { background: rgba(255,255,255,.06); opacity: 1; }
.nav-item.active {
  background: rgba(199, 160, 60, .14);
  border-left-color: var(--gold);
  opacity: 1;
  font-weight: 600;
}

.nav-spacer { flex: 1; }

.main {
  flex: 1;
  padding: 30px 36px 60px;
  min-width: 0;
  overflow-x: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
  flex-wrap: wrap;
  gap: 10px;
}

.topbar .who {
  font-size: .85rem;
  color: var(--green);
}

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 560px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #eee3cd; vertical-align: middle; }
th { color: var(--green-deep); font-family: 'Spectral', serif; font-weight: 600; background: #faf6ea; }
tr:hover td { background: #fbf8ef; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-on { background: #dcecdf; color: var(--green); }
.badge-off { background: #f1e6e6; color: var(--danger); }

.thumb {
  width: 44px; height: 44px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #e5dcc4;
  background: #f1ece0;
  display: block;
}

.row-actions { display: flex; gap: 6px; white-space: nowrap; }

.empty-state {
  text-align: center;
  padding: 40px 10px;
  color: #8a8577;
  font-size: .9rem;
}

/* ---------- Stat cards ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  border-left: 4px solid var(--gold);
}
.stat-card .num { font-family: 'Spectral', serif; font-size: 1.9rem; color: var(--green-deep); font-weight: 700; }
.stat-card .label { font-size: .8rem; color: #6d6a5c; margin-top: 2px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(22, 53, 42, .45);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 200;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  padding: 26px 28px 28px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.modal h3 { margin-bottom: 18px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
  border-top: 1px solid #eee3cd;
  padding-top: 18px;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .field.full { grid-column: 1 / -1; }

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.checkbox-field input { width: auto; }
.checkbox-field label { margin: 0; }

.upload-widget {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.upload-preview {
  width: 64px; height: 64px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid #e5dcc4;
  background: #f1ece0;
}
.upload-preview.empty { display: flex; align-items: center; justify-content: center; font-size: .65rem; color: #a29c88; text-align: center; }

/* ---------- Messages ---------- */
.msg-list { display: flex; flex-direction: column; gap: 8px; }
.msg-item {
  border: 1px solid #eee3cd;
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  background: var(--white);
}
.msg-item.unread { background: #fbf6e6; border-color: var(--gold-soft); font-weight: 600; }
.msg-item .msg-top { display: flex; justify-content: space-between; gap: 10px; font-size: .85rem; }
.msg-item .msg-preview { font-weight: 400; color: #6d6a5c; font-size: .82rem; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item .msg-date { color: #8a8577; font-weight: 400; font-size: .78rem; white-space: nowrap; }

.msg-detail { font-size: .92rem; line-height: 1.6; }
.msg-detail .msg-field { margin-bottom: 10px; }
.msg-detail .msg-field .k { color: var(--green); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.msg-detail .body-text { white-space: pre-wrap; background: #faf6ea; border-radius: 8px; padding: 12px 14px; margin-top: 6px; }

/* ---------- Toasts ---------- */
.toast-wrap {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 400;
}
.toast {
  background: var(--green-deep);
  color: var(--white);
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: .87rem;
  min-width: 220px;
  max-width: 340px;
  border-left: 4px solid var(--gold);
  animation: toast-in .18s ease;
}
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

.hidden { display: none !important; }

.helper-text { font-size: .76rem; color: #8a8577; margin-top: -10px; margin-bottom: 14px; }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; padding: 10px 0; }
  .sidebar .brand, .sidebar .brand-sub { display: none; }
  .nav-item { border-left: none; border-bottom: 3px solid transparent; padding: 10px 14px; flex-shrink: 0; }
  .nav-item.active { border-left-color: transparent; border-bottom-color: var(--gold); }
  .nav-spacer { display: none; }
  .main { padding: 20px 16px 50px; }
  .form-grid { grid-template-columns: 1fr; }
}
