:root {
  --bg: #e8f0ea;
  --bg-deep: #0f3d2e;
  --surface: #f7fbf8;
  --ink: #14241c;
  --muted: #4d6358;
  --accent: #1f7a4c;
  --accent-2: #c45c26;
  --danger: #9b1c1c;
  --line: rgba(20, 36, 28, 0.12);
  --shadow: 0 10px 30px rgba(15, 61, 46, 0.12);
  --radius: 16px;
  --font: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(31, 122, 76, 0.18), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(196, 92, 38, 0.12), transparent 55%),
    linear-gradient(180deg, #dce8df 0%, var(--bg) 40%, #f3f7f4 100%);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 61, 46, 0.96);
  color: #f4faf6;
  backdrop-filter: blur(8px);
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  min-height: 3rem;
}
.brand {
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand span { font-weight: 500; opacity: 0.85; margin-left: 0.25rem; }

.nav-toggle {
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-toggle:hover,
.nav-toggle[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.18);
}
.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  display: block;
  width: 1.15rem;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.nav-toggle-bars {
  position: relative;
}
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}
.nav-toggle-bars::before { top: -6px; }
.nav-toggle-bars::after { top: 6px; }
.nav-toggle[aria-expanded="true"] .nav-toggle-bars {
  background: transparent;
}
.nav-toggle[aria-expanded="true"] .nav-toggle-bars::before {
  top: 0;
  transform: rotate(45deg);
}
.nav-toggle[aria-expanded="true"] .nav-toggle-bars::after {
  top: 0;
  transform: rotate(-45deg);
}

.nav-panel {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.5rem 0.75rem 0.85rem;
}
.nav-panel[hidden] {
  display: none !important;
}
.nav {
  display: grid;
  gap: 0.25rem;
}
.nav a {
  color: #d7e8de;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
}
.nav a.is-active,
.nav a:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  text-decoration: none;
}
.nav-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.5rem;
  padding: 0.65rem 0.85rem 0.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.88rem;
}
.nav-user-name {
  color: #c5ddd0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-logout {
  color: #b8d4c4;
  flex-shrink: 0;
  text-decoration: none;
  font-weight: 600;
}
.nav-logout:hover {
  color: #fff;
  text-decoration: underline;
}

@media (min-width: 760px) {
  .nav {
    grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
  }
}

.shell {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 1rem 1rem 5rem;
}

.flash {
  padding: 0.85rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.flash-success { background: #d9f2e3; color: #0f3d2e; }
.flash-error { background: #f8d7d7; color: #7a1212; }
.flash-info { background: #e4eef8; color: #1a3a55; }

h1 {
  font-size: 1.55rem;
  margin: 0.25rem 0 0.75rem;
  letter-spacing: -0.02em;
}
.lead { color: var(--muted); margin: 0 0 1.25rem; line-height: 1.45; }

.period-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.period-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.period-form select,
.period-form input[type="date"],
.period-form input[type="text"],
.period-form input[type="email"],
.period-form input[type="password"],
.period-form textarea,
.form-grid input,
.form-grid select,
.form-grid textarea {
  font: inherit;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
.is-hidden { display: none !important; }
[hidden] { display: none !important; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 0.8rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: #d7e5db; color: var(--bg-deep); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.sync-btn {
  min-width: 12rem;
  white-space: nowrap;
}
.sync-btn-busy {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.sync-btn-spinner {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.sync-btn.is-busy {
  pointer-events: none;
  opacity: 0.92;
}

.msg-list { display: flex; flex-direction: column; gap: 0.65rem; }
.msg-item {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
}
.msg-item:hover { border-color: rgba(31,122,76,0.35); text-decoration: none; }
.msg-item .meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 0.35rem;
}
.msg-item h2 {
  font-size: 1.05rem;
  margin: 0 0 0.35rem;
}
.msg-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: #d9efe3;
  color: #0f3d2e;
}
.badge-warn { background: #f8e4d4; color: #7a3b12; }
.badge-muted { background: #e6ebe8; color: #44554c; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.panel h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
.panel pre, .body-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  line-height: 1.5;
  margin: 0;
  font-size: 0.98rem;
}

.action-bar {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 0.5rem;
  padding: 0.85rem 0 0.25rem;
  background: linear-gradient(180deg, transparent, var(--bg) 30%);
}
.action-bar .row { display: grid; gap: 0.5rem; }
@media (min-width: 640px) {
  .action-bar .row.two { grid-template-columns: 1fr 1fr; }
}

.login-wrap {
  min-height: calc(100vh - 4rem);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: 20px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}
.login-card h1 { text-align: center; }
.form-grid { display: grid; gap: 0.85rem; }
.form-grid label { display: grid; gap: 0.3rem; font-size: 0.88rem; color: var(--muted); }
.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 1rem 0;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}
@media (min-width: 700px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
}
.stat .n { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.03em; }
.stat .l { color: var(--muted); font-size: 0.8rem; }

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.data th, table.data td {
  text-align: left;
  padding: 0.65rem 0.4rem;
  border-bottom: 1px solid var(--line);
}
table.data th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }

.status-dot { opacity: 0.75; }

.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

.msg-item.is-unread h2 { font-weight: 700; }
.msg-item.is-seen { opacity: 0.92; }

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: rgba(15, 61, 46, 0.45);
  backdrop-filter: blur(3px);
}
.loading-overlay[hidden] { display: none !important; }
.loading-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: min(280px, 90vw);
}
.loading-card p { margin: 0; font-weight: 600; }
.spinner {
  width: 1.35rem;
  height: 1.35rem;
  border: 3px solid rgba(31, 122, 76, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
body.is-loading { overflow: hidden; }
