/* Design follows the PMS platform (pms.ziagotechnologies.com) admin pages. */
:root {
  --blue: #1d4ed8;
  --blue-dark: #1e40af;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #b91c1c;
  --sidebar-width: 250px;
  --sidebar-collapsed: 68px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
}

h1 { font-size: 22px; margin: 0 0 20px; }
h2 { font-size: 15px; margin: 0 0 12px; }
a { color: var(--blue); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Shell ---------- */

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--blue);
  color: #fff;
  overflow: hidden;
  transition: width 0.2s ease, transform 0.2s ease;
  z-index: 20;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  height: 60px;
  padding: 0 16px;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #fff;
  color: var(--blue);
  font-weight: 700;
  font-size: 18px;
}

.sidebar nav {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  padding: 12px 10px calc(12px + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.sidebar nav::-webkit-scrollbar { display: none; }

.sidebar nav a {
  display: flex;
  flex: none;
  align-items: center;
  gap: 14px;
  padding: 11px 14px;
  border-radius: 8px;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}
.sidebar nav a svg { flex: none; }
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.12); }
.sidebar nav a.active { background: rgba(255, 255, 255, 0.22); font-weight: 600; }

/* Sub-pages of a module, listed indented under it while it is open. */
.sidebar nav a.sub { padding-left: 34px; font-size: 14px; }
.sidebar nav a .chevron { margin-left: auto; transition: transform 0.15s ease; }
.sidebar nav a.open .chevron { transform: rotate(90deg); }
.sidebar nav .subs { display: none; flex-direction: column; gap: 4px; }
.sidebar nav .subs.open { display: flex; }

.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  transition: margin-left 0.2s ease;
}

.collapsed .sidebar { width: var(--sidebar-collapsed); }
.collapsed .main { margin-left: var(--sidebar-collapsed); }
.collapsed .brand-name,
.collapsed .sidebar nav a span { display: none; }

@media (min-width: 961px) {
  .collapsed .sidebar nav a.sub { padding-left: 14px; }
  .collapsed .sidebar nav a .chevron { display: none; }
}

.backdrop { display: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 60px;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.topbar-left, .topbar-user { flex: 1 1 0; }
.topbar-left { display: flex; align-items: center; gap: 8px; }

.topbar-title {
  min-width: 0;
  overflow: hidden;
  font-size: 18px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-user {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  text-align: right;
}
.topbar-user form { margin: 0; }
.topbar-name { font-weight: 600; }

.content { padding: 24px; }

.page-footer {
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); }
  .mobile-open .sidebar { transform: none; }
  .mobile-open .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 15;
  }
  .shell .sidebar {
    width: calc(var(--sidebar-width) + env(safe-area-inset-left, 0px));
    max-width: 88vw;
    padding-left: env(safe-area-inset-left, 0px);
    padding-top: env(safe-area-inset-top, 0px);
  }
  .shell .main { margin-left: 0; }
  .shell .brand-name,
  .shell .sidebar nav a span { display: inline; }
  .shell .sidebar nav a .chevron { display: block; }
  .topbar { padding: 0 12px; }
  .topbar-title { display: none; }
  .topbar-user { gap: 8px; }
  .topbar-user .muted, .topbar-user .profile-link { display: none; }
  .content { padding: 16px; }
}

@media (max-width: 560px) {
  .topbar-name { display: none; }
}

/* ---------- Components ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.page-head h1 { margin: 0; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.tile-value { margin-top: 6px; font-size: 28px; font-weight: 700; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: 16px;
  align-items: start;
}

.table-wrap { padding: 0; overflow-x: auto; }
.table-wrap h2 { padding: 18px 18px 0; }
.table-wrap td { white-space: nowrap; }

table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: #e5e7eb;
  color: #374151;
}
.badge.up, .badge.active { background: #dcfce7; color: #166534; }
.badge.down { background: #fee2e2; color: #991b1b; }

.button {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.button:hover { background: var(--blue-dark); }
.button:disabled { opacity: 0.6; cursor: default; }
.button.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.button.secondary:hover { background: var(--bg); }

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text);
  cursor: pointer;
}
.icon-button:hover { background: var(--bg); }

.alert {
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #fee2e2;
  color: #991b1b;
}
.alert.success { background: #dcfce7; color: #166534; }

/* ---------- Forms ---------- */

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

input, select, textarea {
  padding: 9px 11px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 400;
}
textarea { resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(29, 78, 216, 0.35);
  border-color: var(--blue);
}

.form { margin-bottom: 20px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; }
.field-error { color: var(--danger); font-size: 12px; font-weight: 400; }
label.has-error input, label.has-error textarea { border-color: var(--danger); }
.form-card { max-width: 760px; }

/* ---------- Login ---------- */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px;
  background: #fff;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 380px;
  padding: 32px;
  border-radius: 14px;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.login-card .muted { color: #dbeafe; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card .alert { margin: 0; }
.login-card .button { border-color: #fff; background: #fff; color: var(--blue); width: 100%; }
.login-card .button:hover { background: #eff6ff; }
.login-card.plain { background: #fff; color: var(--text); align-items: center; text-align: center; }
.login-card.plain .button { background: var(--blue); color: #fff; width: auto; }

.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.login-brand .brand-mark { width: 46px; height: 46px; }
.login-brand h1 { margin: 0; font-size: 20px; }
.login-brand p { margin: 2px 0 0; }
.login-foot { margin: 0; text-align: center; }

.pw-wrap { position: relative; display: flex; }
.pw-wrap input { flex: 1; padding-right: 60px; }
.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: none;
  color: var(--blue);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.page-sub { margin-top: 4px; }
.profile-stack { display: flex; flex-direction: column; gap: 16px; max-width: 900px; }
.profile-stack .form { margin: 0; scroll-margin-top: 76px; }
