/* ==========================================================================
   Popular Meadows Systems — single stylesheet
   Palette kept from the original system: navy #001b2e, slate #537692
   ========================================================================== */

:root {
  --navy: #001b2e;
  --navy-2: #0b2a42;
  --slate: #537692;
  --slate-hover: #466680;
  --slate-light: #7fa2bb;
  --slate-dark: #2f4f66;
  --mist: #e8effb;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f6f9fc;
  --border: #dde5ee;
  --text: #1c2733;
  --muted: #64748b;

  --green: #1e8e5a;
  --green-bg: #e3f4ec;
  --red: #e63946;
  --red-bg: #fde8ea;
  --amber: #a86a12;
  --amber-bg: #fdf1dc;
  --blue-bg: #e5eef7;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(0, 27, 46, .06), 0 4px 16px rgba(0, 27, 46, .06);
  --shadow-lg: 0 12px 40px rgba(0, 27, 46, .18);
  --sidebar: 256px;
  --font: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--slate); text-decoration: none; }
a:hover { color: var(--slate-dark); }
h1, h2, h3 { margin: 0; line-height: 1.25; color: var(--navy); }
p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid rgba(83, 118, 146, .45); outline-offset: 2px; }
.icon { width: 18px; height: 18px; flex: none; }
.sr-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

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

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #c9d6e3; z-index: 40;
  transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 22px 22px 18px; color: #fff; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--slate-light), var(--slate));
  font-weight: 600; font-size: 15px; color: #fff; letter-spacing: .5px;
}
.brand-name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11.5px; color: var(--slate-light); }

.nav { flex: 1; overflow-y: auto; padding: 6px 12px 12px; }
.nav-label {
  padding: 16px 12px 6px; font-size: 10.5px; font-weight: 600;
  letter-spacing: .09em; text-transform: uppercase; color: #6f8aa2;
}
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; margin: 2px 0; border-radius: 10px;
  color: #c9d6e3; font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: rgba(127, 162, 187, .18); color: #fff; box-shadow: inset 3px 0 0 var(--slate-light); }
.nav a .icon { opacity: .85; }

.user-box {
  display: flex; align-items: center; gap: 10px;
  margin: 12px; padding: 12px; border-radius: 12px;
  background: rgba(255, 255, 255, .05);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--slate); color: #fff; font-weight: 600; font-size: 13px;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { color: #fff; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11.5px; color: var(--slate-light); }
.logout { color: #9fb4c7; padding: 6px; border-radius: 8px; display: grid; place-items: center; }
.logout:hover { color: #fff; background: rgba(255, 255, 255, .08); }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 18px 32px;
  background: rgba(238, 242, 247, .88);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid transparent;
}
.topbar h1 { font-size: 21px; font-weight: 600; }
.topbar .subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.topbar .menu-btn { display: none; }
.content { padding: 8px 32px 40px; max-width: 1400px; width: 100%; }
.scrim { display: none; }

@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 27, 46, .45); z-index: 30; }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding: 14px 16px; }
  .content { padding: 8px 16px 32px; }
}

/* ---------- Cards & layout helpers ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card, .mt { margin-top: 18px; }
.grid > .card + .card { margin-top: 0; }
.card-body { padding: 22px; }
.card-header {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 15.5px; font-weight: 600; }
.card-header .hint { color: var(--muted); font-size: 12.5px; }
.spacer { flex: 1; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid > .grid-span { grid-column: span 2; }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } .grid > .grid-span { grid-column: auto; } }
@media (min-width: 600px) and (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }

.align-end { align-items: end; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-end { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer;
  font: 500 13.5px var(--font); white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, opacity .15s;
}
.btn .icon { width: 17px; height: 17px; }
.btn-primary { background: var(--slate); color: #fff; }
.btn-primary:hover { background: var(--slate-hover); color: #fff; }
.btn-dark { background: var(--navy); color: #fff; }
.btn-dark:hover { background: var(--navy-2); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--slate-light); color: var(--slate-dark); }
.btn-danger { background: var(--surface); border-color: #f3c5ca; color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; border-radius: 8px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 9px; }
.btn:disabled, .btn.is-busy { opacity: .55; cursor: not-allowed; }
.btn.is-busy::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 500; color: var(--slate-dark); }
.input, .select {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: 400 13.5px var(--font);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus { outline: none; border-color: var(--slate); box-shadow: 0 0 0 3px rgba(83, 118, 146, .18); }
.input-sm { height: 34px; font-size: 13px; border-radius: 8px; }
.select {
  appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23537692' stroke-width='2'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search .input { padding-left: 34px; height: 36px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.check input { width: 16px; height: 16px; accent-color: var(--slate); }

/* Drop zone around a file input */
.dropzone {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 132px; padding: 20px;
  border: 2px dashed #c6d3e0; border-radius: var(--radius);
  background: var(--surface-2); text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--slate); background: var(--mist); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone .dz-icon {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface); color: var(--slate); box-shadow: var(--shadow);
}
.dropzone .dz-title { font-weight: 500; color: var(--navy); }
.dropzone .dz-hint { font-size: 12px; color: var(--muted); }
.dropzone .dz-files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 4px; max-width: 100%; }
.dropzone.has-files { border-style: solid; border-color: var(--slate-light); background: #f2f7fb; }
.file-chip {
  display: inline-block; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 12px; color: var(--slate-dark);
}

/* ---------- Alerts ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; font-size: 13.5px; }
.alert .icon { margin-top: 1px; }
.alert-error { background: var(--red-bg); color: #9b1c27; }
.alert-success { background: var(--green-bg); color: #13603c; }
.alert-info { background: var(--blue-bg); color: var(--slate-dark); }

/* ---------- Stat tiles ---------- */
.stat { padding: 16px 18px; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 600; color: var(--navy); margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value.ok { color: var(--green); }
.stat-value.bad { color: var(--red); }
.stat-value.warn { color: var(--amber); }

/* ---------- Tables ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 22px; border-bottom: 1px solid var(--border); }
.toolbar .select, .card-header .select { width: auto; min-width: 150px; }
.toolbar .count { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.table-wrap { overflow: auto; max-height: 68vh; }
/* Tables use Inter (a text face built for dense data) at a calmer contrast; headings keep Poppins */
.table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-family: "Inter", var(--font); font-size: 13.5px; color: #334155;
  font-feature-settings: "tnum", "cv11";
}
.table th {
  position: sticky; top: 0; z-index: 1;
  background: #f3f6f9; color: #5b7185;
  font-weight: 600; font-size: 12px; letter-spacing: .01em;
  text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px 16px; border-bottom: 1px solid #eef2f6; vertical-align: middle; line-height: 1.45; }
.table tbody tr:nth-child(even) td { background: #f9fbfc; }
.table tbody tr:hover td { background: #eef4f9; }
.table .mono { font-family: inherit; font-size: 13px; color: #56687a; letter-spacing: .01em; }
.table td.num { color: var(--navy); font-weight: 500; }
.table .muted-cell { color: #56687a; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; color: var(--slate-dark); background: var(--mist); }
.tag-plain { font-size: 12px; color: #8a9aab; }
.table tbody tr:last-child td { border-bottom: none; }
.table .desc { min-width: 220px; max-width: 420px; }
.table .actions { text-align: right; white-space: nowrap; }
.table .center { text-align: center; }
.table .center .check { justify-content: center; }
.btn-placeholder { display: inline-block; width: 34px; margin-left: 6px; vertical-align: middle; }
.table .input.is-saving { border-color: var(--slate-light); background: var(--surface-2); }
.table .actions .btn + .btn { margin-left: 6px; }
.table .input, .table .select { height: 34px; font-size: 13px; border-radius: 8px; min-width: 110px; }
.table tbody tr.row-bad td { background: #fff7f8; }
.table tbody tr.row-warn td { background: #fffbf3; }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty .icon { width: 30px; height: 30px; color: var(--slate-light); margin-bottom: 8px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--green-bg); color: var(--green); }
.badge-bad { background: var(--red-bg); color: var(--red); }
.badge-warn { background: var(--amber-bg); color: var(--amber); }
.badge-info { background: var(--blue-bg); color: var(--slate-dark); }
.badge-muted { background: #eef1f5; color: var(--muted); }
.text-bad { color: var(--red); font-weight: 600; }
.text-warn { color: var(--amber); font-weight: 600; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; padding: 5px; background: #e2e9f1; border-radius: 12px; width: fit-content; max-width: 100%; overflow-x: auto; margin-bottom: 18px; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border: 0; border-radius: 9px; background: transparent;
  font: 500 13px var(--font); color: var(--slate-dark); cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--navy); }
.tab.active { background: var(--surface); color: var(--navy); box-shadow: var(--shadow); }
.tab .pill { font-size: 11px; padding: 0 7px; border-radius: 999px; background: var(--mist); color: var(--slate-dark); }

/* ---------- Dashboard ---------- */
.hero {
  position: relative; overflow: hidden;
  padding: 28px 30px; border-radius: 18px; color: #fff;
  background: linear-gradient(120deg, var(--slate) 0%, var(--navy) 100%);
  box-shadow: var(--shadow);
}
.hero::after {
  content: ""; position: absolute; right: -60px; top: -60px; width: 240px; height: 240px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .16), transparent 70%);
}
.hero h2 { color: #fff; font-size: 24px; font-weight: 600; }
.hero p { color: #d6e2ec; margin-top: 6px; }
.section-title { margin: 28px 0 12px; font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tools { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.tool {
  display: flex; flex-direction: column; gap: 12px; padding: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--text);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s;
}
.tool:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(0, 27, 46, .12); border-color: var(--slate-light); color: var(--text); }
.tool-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--mist); color: var(--slate); }
.tool-icon .icon { width: 22px; height: 22px; }
.tool h3 { font-size: 15px; font-weight: 600; }
.tool p { color: var(--muted); font-size: 12.5px; }
.tool .go { margin-top: auto; font-size: 12.5px; font-weight: 500; color: var(--slate); display: inline-flex; align-items: center; gap: 4px; }

/* ---------- Downloads list ---------- */
.po-list { list-style: none; margin: 0; padding: 8px; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.po-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.po-item .file-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--red-bg); color: var(--red); flex: none; }
.po-item .po-meta { flex: 1; min-width: 0; }
.po-item .po-no { font-weight: 600; color: var(--navy); font-variant-numeric: tabular-nums; }
.po-item .po-sub { font-size: 12px; color: var(--muted); }
.po-item.is-done { background: #f5fbf8; border-color: #bfe3cf; }
.po-item.is-done .file-icon { background: var(--green-bg); color: var(--green); }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-brand {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 48px; color: #fff;
  background: linear-gradient(135deg, var(--slate) 0%, var(--navy) 70%);
}
.auth-brand::before, .auth-brand::after {
  content: ""; position: absolute; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .14), transparent 70%);
}
.auth-brand::before { width: 520px; height: 520px; right: -180px; top: -160px; }
.auth-brand::after { width: 380px; height: 380px; left: -140px; bottom: -160px; }
.auth-logo { position: relative; z-index: 1; display: flex; align-items: center; gap: 14px; }
.auth-logo img { height: 48px; border-radius: 10px; background: #fff; padding: 6px 10px; }
.auth-brand h1 { position: relative; z-index: 1; color: #fff; font-size: 36px; font-weight: 600; max-width: 460px; }
.auth-brand p { position: relative; z-index: 1; color: #d0dde8; margin-top: 12px; max-width: 420px; }
.auth-brand .foot { position: relative; z-index: 1; font-size: 12px; color: #9fb4c7; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; background: var(--surface); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 24px; font-weight: 600; }
.auth-card .muted { margin: 6px 0 26px; }
.auth-card .field + .field { margin-top: 16px; }
.auth-card .btn { width: 100%; height: 44px; margin-top: 24px; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 44px; }
.pw-toggle { position: absolute; right: 4px; top: 4px; width: 32px; height: 32px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 8px; display: grid; place-items: center; }
.pw-toggle:hover { color: var(--slate); }
.input.lg { height: 44px; }
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { padding: 28px 24px; min-height: 200px; }
  .auth-brand h1 { font-size: 24px; }
  .auth-brand .foot { display: none; }
}

/* ---------- Error page ---------- */
.error-page { min-height: 70vh; display: grid; place-items: center; text-align: center; }
.error-code { font-size: 64px; font-weight: 600; color: var(--slate-light); line-height: 1; }

/* ---------- Toasts & dialog ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 40px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 12px; background: var(--navy); color: #fff;
  box-shadow: var(--shadow-lg); font-size: 13.5px;
  animation: toast-in .2s ease;
}
.toast.error { background: #8f1d27; }
.toast.success { background: #15603f; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

dialog.modal {
  width: min(440px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 16px;
  box-shadow: var(--shadow-lg); color: var(--text);
}
dialog.modal::backdrop { background: rgba(0, 27, 46, .5); backdrop-filter: blur(2px); }
.modal-body { padding: 24px; }
.modal-body h3 { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.modal-body .field { margin-top: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 24px; background: var(--surface-2); border-top: 1px solid var(--border); }
