:root {
  --bg: #f4f7f5;
  --bg-2: #eef4f1;
  --surface: #ffffff;
  --surface-alt: #f8fbfa;
  --ink: #172321;
  --muted: #6a7b77;
  --line: #dbe7e3;
  --brand: #1f7a5c;
  --brand-dark: #165a44;
  --brand-soft: #e7f3ee;
  --danger: #c94a4a;
  --danger-soft: #fdecec;
  --warn: #c58a1a;
  --shadow: 0 8px 28px rgba(23, 35, 33, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --transition: 180ms cubic-bezier(.2,.8,.2,1);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #dcefeb 0%, transparent 70%),
    linear-gradient(180deg, var(--bg) 0%, #f7faf9 100%);
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #fbfefd;
  border-right: 1px solid var(--line);
  padding: 28px 18px 20px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand) 0%, #3aa07f 100%);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 14px; letter-spacing: 0.5px;
  box-shadow: 0 6px 16px rgba(31, 122, 92, 0.25);
}
.brand-title { font-size: 15px; font-weight: 800; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 3px; }

.nav { display: flex; flex-direction: column; gap: 4px; padding: 18px 0; overflow-y: auto; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border: 0; background: transparent; border-radius: 10px;
  color: #41524f; font-size: 14px; font-weight: 600; text-align: left;
  transition: all var(--transition);
}
.nav-item:hover { background: #f0f6f4; color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-dark); }
.nav-ic { width: 20px; text-align: center; font-size: 15px; line-height: 1; }

.sidebar-foot { padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.env-pill {
  display: inline-flex; align-self: flex-start; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px; background: #f0f6f4; color: var(--muted);
  font-size: 11px; font-weight: 700;
}
.env-pill.ok { background: #e8f5ef; color: #1a6d52; }
.env-pill.err { background: var(--danger-soft); color: #a33a3a; }
.small { font-size: 11px; }
.muted { color: var(--muted); }

/* Main */
.main { flex: 1; min-width: 0; padding: 28px 28px 40px; }
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 20px;
  margin-bottom: 24px; flex-wrap: wrap;
}
.eyebrow { margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--brand); }
.page-title { margin: 0; font-size: 30px; line-height: 1.15; font-weight: 800; letter-spacing: -0.02em; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.search-wrap { position: relative; }
.input {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 14px; outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: 44px;
}
.input:focus { border-color: #9fcdbb; box-shadow: 0 0 0 4px rgba(31,122,92,0.08); }
.input::placeholder { color: #96a5a1; }
.search { width: 280px; background: #fbfefd; }
textarea.input { min-height: 96px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px;
  border-radius: 10px; border: 1px solid transparent; font-size: 14px; font-weight: 700;
  transition: all var(--transition); white-space: nowrap; min-height: 44px;
}
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(31,122,92,0.2); }
.btn-primary:hover { background: var(--brand-dark); transform: translateY(-1px); }
.btn-ghost { background: transparent; border-color: var(--line); color: #425350; }
.btn-ghost:hover { background: #f6faf9; }
.btn-sm { padding: 7px 10px; font-size: 12px; min-height: 34px; border-radius: 8px; }
.btn-danger { background: var(--danger-soft); color: #b33e3e; border-color: #f3d6d6; }
.btn-danger:hover { background: #f9dede; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; font-size: 20px; line-height: 1; color: var(--muted);
  display: grid; place-items: center;
}
.icon-btn:hover { background: #f7fafa; color: var(--ink); }

/* Content / pages */
.page { display: none; }
.page.active { display: block; animation: fade .22s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* Stats */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 20px 18px; box-shadow: var(--shadow);
}
.stat-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.stat-value { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; color: var(--ink); line-height: 1.1; margin-bottom: 10px; }
.stat-note { font-size: 12px; color: #7a8a86; }

/* Panels */
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.panel-head {
  padding: 20px 22px; border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.panel-head-row { align-items: center; }
.panel-title { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.panel-sub { margin: 5px 0 0; font-size: 13px; color: var(--muted); }
.panel-actions { display: flex; align-items: center; gap: 10px; }
.count-pill {
  padding: 7px 12px; background: #f3f8f6; border: 1px solid #e3ece9; color: #55706a;
  border-radius: 999px; font-size: 12px; font-weight: 700;
}

/* List */
.list { padding: 8px 0; }
.list-item { padding: 14px 22px; border-bottom: 1px solid #edf2f0; }
.list-item:last-child { border-bottom: 0; }
.list-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.list-title { font-size: 14px; font-weight: 700; color: var(--ink); }
.list-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.list-desc { font-size: 13px; color: #5f706c; line-height: 1.6; }
.empty { padding: 28px 22px; color: var(--muted); font-size: 14px; text-align: center; }

/* Table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 720px; }
.table th, .table td {
  padding: 13px 16px; text-align: left; font-size: 13px; vertical-align: middle;
  border-bottom: 1px solid #edf2f0;
}
.table th {
  font-size: 12px; font-weight: 700; color: #5f716d; text-transform: uppercase;
  letter-spacing: 0.05em; background: #f8fbfa; border-bottom: 1px solid var(--line);
  position: sticky; top: 0;
}
.table tbody tr:hover { background: #fafdfc; }
.table .empty-cell { text-align: center; color: var(--muted); padding: 34px 16px; }
.td-actions { white-space: nowrap; text-align: right; }
.td-actions .btn { margin-left: 6px; }
.td-main { font-weight: 600; color: var(--ink); }
.td-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }
.badge {
  display: inline-flex; align-items: center; padding: 5px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: #eef4f2; color: #56706a;
}
.badge.ok { background: #e8f5ef; color: #1f7a5c; }
.badge.warn { background: #fff6df; color: #a06800; }
.badge.info { background: #edf3fb; color: #3f6799; }
.badge.muted { background: #f2f5f4; color: #6b7c78; }

/* Settings form */
.form-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px; padding: 22px;
}
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: 13px; font-weight: 700; color: #3f514e; }
.field.full { grid-column: 1 / -1; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: -2px; }

/* Modal */
.modal { position: fixed; inset: 0; display: none; z-index: 50; }
.modal.show { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(23, 35, 33, 0.35); backdrop-filter: blur(2px); }
.modal-card {
  position: relative; width: min(760px, calc(100vw - 32px)); margin: 6vh auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 20px 60px rgba(20,30,28,0.18); overflow: hidden;
  max-height: 88vh; display: flex; flex-direction: column;
  animation: modalIn .18s ease-out;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-head { padding: 20px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.modal-title { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.modal-card .form-grid { overflow-y: auto; }
.modal-foot {
  padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px;
  background: #fbfdfc;
}

/* Toast */
.toast-wrap { position: fixed; top: 18px; right: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 80; pointer-events: none; }
.toast {
  pointer-events: auto; min-width: 260px; max-width: 360px; padding: 12px 14px;
  border-radius: 12px; background: #1f2d2a; color: #fff; font-size: 13px; font-weight: 600;
  box-shadow: 0 10px 24px rgba(0,0,0,0.16); animation: toastIn .18s ease-out;
}
.toast.success { background: #1f7a5c; }
.toast.error { background: #c94a4a; }
@keyframes toastIn { from { opacity:0; transform: translateY(-8px);} to { opacity:1; transform: translateY(0);} }

/* Responsive */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: relative; padding: 16px;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding-bottom: 14px; }
  .nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; padding: 12px 0 4px; gap: 6px; }
  .nav-item { white-space: nowrap; padding: 10px 12px; }
  .sidebar-foot { display: none; }
  .main { padding: 20px 16px 32px; }
  .search { width: 100%; min-width: 0; }
  .topbar-right { width: 100%; }
  .search-wrap { flex: 1; }
}
@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-card { padding: 16px; }
  .stat-value { font-size: 24px; }
  .form-grid { grid-template-columns: 1fr; padding: 16px; }
  .page-title { font-size: 26px; }
  .modal-card { margin: 3vh auto; width: calc(100vw - 20px); max-height: 94vh; }
  .panel-head { padding: 16px; }
  .list-item { padding: 14px 16px; }
}

/* ===== Landing / Auth ===== */
.landing { min-height: 100vh; display: flex; flex-direction: column; padding: 24px 28px 20px; max-width: 1280px; margin: 0 auto; width: 100%; }
.landing-nav { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0 24px; }
.landing-brand { display: flex; align-items: center; gap: 12px; }
.landing-nav-tag {
  display: inline-flex; align-items: center; padding: 8px 14px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line); color: #4c615d; font-size: 12px; font-weight: 700;
}
.landing-main {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 40px; align-items: center; padding: 24px 0 32px;
}
.landing-hero { padding: 10px 10px 10px 4px; }
.landing-title {
  margin: 0 0 18px; font-size: 46px; line-height: 1.12; font-weight: 800;
  letter-spacing: -0.03em; color: var(--ink); max-width: 720px;
}
.text-brand { color: var(--brand); }
.landing-lead {
  margin: 0 0 28px; font-size: 16px; line-height: 1.85; color: #556866;
  max-width: 640px;
}
.landing-features {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px;
  margin-bottom: 28px; max-width: 680px;
}
.feature-item { display: flex; gap: 14px; align-items: flex-start; }
.feature-ic {
  width: 42px; height: 42px; border-radius: 12px; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-size: 18px; flex-shrink: 0;
  border: 1px solid #d8eae4;
}
.feature-title { font-size: 14px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.feature-desc { font-size: 13px; color: var(--muted); line-height: 1.6; }
.landing-note {
  display: inline-flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: #f3f8f6; border: 1px solid #dfeae7; border-radius: 10px;
  font-size: 13px; color: #4f6561; font-weight: 500;
}
.note-dot { width: 8px; height: 8px; border-radius: 50%; background: #45a37f; box-shadow: 0 0 0 4px rgba(69,163,127,0.12); flex-shrink: 0; }

.landing-auth { display: flex; justify-content: flex-end; }
.auth-card {
  width: 100%; max-width: 460px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: 0 16px 48px rgba(23, 35, 33, 0.08); overflow: hidden;
}
.auth-card-head { padding: 28px 28px 0; }
.auth-title { margin: 0 0 8px; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; color: var(--ink); }
.auth-sub { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.7; }
.auth-form { padding: 22px 28px 10px; display: flex; flex-direction: column; gap: 16px; }
.input-pass-wrap { position: relative; display: flex; align-items: center; }
.input-pass-wrap .input { padding-right: 76px; }
.pass-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--brand); font-size: 12px; font-weight: 700;
  padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.pass-toggle:hover { background: var(--brand-soft); }
.btn-block { width: 100%; justify-content: center; }
.form-error {
  display: none; padding: 10px 12px; border-radius: 10px; background: #fdecec; color: #b33e3e;
  font-size: 13px; font-weight: 600; line-height: 1.5; border: 1px solid #f5d6d6;
}
.form-error.show { display: block; }
.auth-card-foot { padding: 18px 28px 24px; border-top: 1px solid #edf2f0; margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.auth-foot-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.auth-hint { margin: 0; line-height: 1.6; }
.landing-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 0 4px; border-top: 1px solid var(--line); font-size: 13px; color: #5a6d69;
}

/* User card in sidebar */
.user-card {
  display: flex; align-items: center; gap: 10px; padding: 10px 10px;
  background: #f4f8f7; border: 1px solid #e6eeec; border-radius: 12px; margin-bottom: 4px;
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 10px; background: #dcefeb; color: var(--brand-dark);
  display: grid; place-items: center; font-weight: 800; font-size: 14px; flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name { font-size: 13px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-logout { margin-bottom: 6px; color: #7a5a5a; }
.btn-logout:hover { background: #fbf3f3; color: #a14545; border-color: #f0dddd; }

/* Read-only state */
body.role-readonly .read-write-only { display: none !important; }
body.role-readonly #btn-save-settings { display: none !important; }

/* Loading button */
.btn.loading { opacity: 0.8; pointer-events: none; }

/* Responsive landing */
@media (max-width: 1100px) {
  .landing-main { grid-template-columns: 1fr; gap: 20px; padding-top: 10px; }
  .landing-auth { justify-content: flex-start; }
  .auth-card { max-width: 560px; }
  .landing-title { font-size: 40px; }
}
@media (max-width: 720px) {
  .landing { padding: 18px 16px 16px; }
  .landing-title { font-size: 32px; }
  .landing-lead { font-size: 15px; line-height: 1.75; }
  .landing-features { grid-template-columns: 1fr; gap: 14px; }
  .auth-card-head { padding: 22px 20px 0; }
  .auth-form { padding: 20px 20px 10px; }
  .auth-card-foot { padding: 16px 20px 20px; }
  .landing-nav-tag { display: none; }
  .landing-footer { flex-direction: column; align-items: flex-start; }
}
