:root {
  --primary: #2d6a4f;
  --primary-light: #52b788;
  --bg: #f0fdf4;
  --bg-card: #ffffff;
  --text: #1b4332;
  --text-muted: #4b5563;
  --border: #d1fae5;
  --danger: #b91c1c;
  --warning: #b45309;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(45, 106, 79, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

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

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.container-wide {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

header.app-header {
  background: var(--primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

header.app-header .brand {
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 0.5px;
}

header.app-header a, header.app-header .icon-btn {
  color: #fff;
}

.card {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card h1, .card h2, .card h3 {
  margin-top: 0;
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="month"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 1rem;
  color: var(--text);
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(82, 183, 136, 0.25);
}

textarea { resize: vertical; min-height: 80px; }

.field { margin-bottom: 14px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 18px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, transform .05s ease;
  font-family: inherit;
}
.btn:hover { background: #245a42; }
.btn:active { transform: translateY(1px); }
.btn:disabled { background: #9ca3af; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-secondary { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8c1010; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.stat-card {
  background: var(--bg-card);
  padding: 18px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--primary-light);
}
.stat-card .label { color: var(--text-muted); font-size: 0.9rem; }
.stat-card .value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }

.list { list-style: none; padding: 0; margin: 0; }
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px;
  background: var(--bg-card);
  border-radius: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  gap: 12px;
}
.list-item .meta { color: var(--text-muted); font-size: 0.85rem; }
.list-item .amount { font-weight: 700; color: var(--primary); white-space: nowrap; }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--primary);
  border: 1px solid var(--border);
  font-weight: 600;
}
.badge-ok { background: var(--primary-light); color: #fff; border-color: var(--primary-light); }
.badge-warn { background: #fef3c7; color: var(--warning); border-color: #fde68a; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--bg); font-weight: 700; color: var(--primary); }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-weight: 500;
}
.alert-error { background: #fee2e2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: var(--primary); border: 1px solid var(--border); }
.alert-info { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center { text-align: center; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.preview-img {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 12px;
  display: block;
  margin: 0 auto;
}

/* Admin layout */
.admin-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 56px);
}
.admin-nav {
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 18px 12px;
}
.admin-nav a {
  display: block;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--text);
  margin-bottom: 4px;
  font-weight: 600;
}
.admin-nav a:hover { background: var(--bg); text-decoration: none; }
.admin-nav a.active { background: var(--primary); color: #fff; }

.admin-content { padding: 20px; }

@media (max-width: 720px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-nav {
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px;
    overflow-x: auto;
  }
  .admin-nav a { margin-bottom: 0; padding: 8px 12px; font-size: 0.9rem; }
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}
.toolbar .field { margin-bottom: 0; }

.text-muted { color: var(--text-muted); }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.hidden { display: none !important; }

.icon-btn {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
  padding: 6px 10px;
  border-radius: 8px;
}
.icon-btn:hover { background: rgba(255,255,255,0.15); }

.tree-kg { margin-bottom: 14px; }
.tree-kg > .kg-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  background: var(--primary);
  color: #fff; border-radius: 10px 10px 0 0;
  font-weight: 700;
}
.tree-kg .groups-list {
  background: #fff; border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 10px 10px;
  padding: 10px;
}
.tree-kg .group-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 8px;
}
.tree-kg .group-row:hover { background: var(--bg); }
