/* ==========================================================================
   PDI TOP — mobile-first application UI
   ========================================================================== */
:root {
  --navy: #1a237e;
  --navy-800: #141b63;
  --navy-050: #eef0fb;
  --green: #2d7c31;
  --green-600: #256a29;
  --green-050: #e9f5e9;
  --bg: #f3f5fa;
  --surface: #ffffff;
  --text: #17203a;
  --muted: #687188;
  --line: #e5e9f2;
  --line-strong: #d5dbe8;
  --danger: #c0392b;
  --danger-050: #fdecea;
  --amber: #a86a12;
  --amber-050: #fdf3e2;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 12px 32px -16px rgba(16, 24, 40, 0.25);
  --radius: 18px;
  --radius-sm: 12px;
  --bottom-nav: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
a { color: var(--navy); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }

.icon { width: 20px; height: 20px; flex: none; stroke-width: 1.8; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }

/* --------------------------------------------------------------------------
   Shell
   -------------------------------------------------------------------------- */
.app { min-height: 100vh; }

.sidebar {
  display: none;
  position: fixed;
  inset: 0 auto 0 0;
  width: 264px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  z-index: 30;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 800;
  font-size: 24px;
  letter-spacing: -0.5px;
}
.brand .brand-a { color: var(--navy); }
.brand .brand-b { color: var(--green); }

.brand-tag {
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 700;
  margin-top: 2px;
}

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.nav-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #98a1b3;
  font-weight: 700;
  padding: 10px 12px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 12px;
  color: #454e63;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-link:hover { background: #f6f8fc; color: var(--navy); }
.nav-link.active { background: var(--navy-050); color: var(--navy); }
.nav-link.active .icon { color: var(--navy); }
.nav-link .icon { color: #7c8699; }

.sidebar-user {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fafbfe;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  min-height: 58px;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar .brand { font-size: 21px; }
.topbar-title { display: none; font-weight: 700; font-size: 16px; color: #2b3550; }
.topbar-tools { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.user-menu { position: relative; }
.user-menu > summary { list-style: none; cursor: pointer; }
.user-menu > summary::-webkit-details-marker { display: none; }
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--navy), #3448b5);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
}
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 8px;
  z-index: 50;
}
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-name { font-weight: 700; font-size: 14px; }
.menu-role { font-size: 12px; color: var(--muted); margin-top: 2px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  background: none;
  border-radius: 9px;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  color: #3c455c;
}
.menu-item:hover { background: #f5f7fc; }
.menu-item.danger { color: var(--danger); }

.page {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 16px calc(var(--bottom-nav) + 28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  padding: 6px 6px calc(6px + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.bnav-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
  border-radius: 12px;
  color: #7c8699;
  font-size: 10.5px;
  font-weight: 600;
}
.bnav-link .icon { width: 21px; height: 21px; }
.bnav-link.active { color: var(--navy); }
.bnav-link.active .icon { color: var(--navy); }

/* --------------------------------------------------------------------------
   Page header, cards, typography
   -------------------------------------------------------------------------- */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}
.page-title { font-size: 23px; font-weight: 800; letter-spacing: -0.02em; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-top: 3px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 0;
}
.card-title { font-size: 16px; font-weight: 700; }
.card-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.card-body { padding: 16px; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--line); background: #fbfcfe; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.strong { font-weight: 700; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }
.text-right { text-align: right; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }

/* --------------------------------------------------------------------------
   Buttons & inputs
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 16px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: var(--navy);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: filter 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
  text-align: center;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--line-strong); color: #3b455d; }
.btn-ghost:hover { background: #f7f9fd; }
.btn-soft { background: var(--navy-050); color: var(--navy); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-soft { background: var(--danger-050); color: var(--danger); }
.btn-sm { min-height: 34px; padding: 5px 11px; font-size: 12.5px; border-radius: 9px; }
.btn-lg { min-height: 50px; font-size: 15px; padding: 12px 20px; }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: 40px; min-height: 40px; border-radius: 10px; }

form { margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 13px; font-weight: 600; color: #3b455d; }
.label .req { color: var(--danger); margin-left: 2px; }
.hint { font-size: 11.5px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: #fff;
  font-size: 15px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(26, 35, 126, 0.12);
}
.textarea { min-height: 104px; resize: vertical; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23687188' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.form-grid.two { grid-template-columns: 1fr; }
.form-grid .span-2 { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-form { display: flex; gap: 8px; flex-wrap: wrap; }
.search-input { position: relative; flex: 1 1 180px; }
.search-input .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: #8b94a7; width: 17px; height: 17px; }
.search-input .input { padding-left: 36px; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: #3b455d; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--navy); }

/* --------------------------------------------------------------------------
   Stats, badges, lists
   -------------------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-sm);
}
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--navy-050); color: var(--navy);
}
.stat-icon.green { background: var(--green-050); color: var(--green); }
.stat-icon.amber { background: var(--amber-050); color: var(--amber); }
.stat-icon.red { background: var(--danger-050); color: var(--danger); }
.stat-value { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: #eef1f8;
  color: #4a546c;
  white-space: nowrap;
}
.badge-green { background: var(--green-050); color: var(--green-600); }
.badge-red { background: var(--danger-050); color: var(--danger); }
.badge-amber { background: var(--amber-050); color: var(--amber); }
.badge-navy { background: var(--navy-050); color: var(--navy); }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.list { display: flex; flex-direction: column; }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}
.list-item:first-child { border-top: 0; }
.list-icon {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--navy-050); color: var(--navy);
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}
.list-main { min-width: 0; flex: 1; }
.list-title { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.list-actions { display: flex; gap: 6px; flex: none; }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0 0 var(--radius) var(--radius);
}
.data-table { width: 100%; border-collapse: collapse; min-width: 520px; }
.data-table th, .data-table td { padding: 12px 14px; text-align: left; font-size: 13.5px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: #6c768c; font-weight: 700; background: #fafbfe; position: sticky; top: 0; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fbfcff; }
.data-table .num { font-variant-numeric: tabular-nums; }
.data-table .actions { text-align: right; white-space: nowrap; }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 12.5px; }

.record-list { display: flex; flex-direction: column; }
.record {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}
.record:first-child { border-top: 0; }
.record-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.record-title { font-weight: 700; font-size: 15px; }
.record-meta { display: flex; flex-wrap: wrap; gap: 10px 14px; font-size: 12.5px; color: var(--muted); }
.record-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* --------------------------------------------------------------------------
   Empty, alerts, pagination, toasts
   -------------------------------------------------------------------------- */
.empty { padding: 34px 18px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-icon { width: 52px; height: 52px; border-radius: 16px; background: #f2f5fb; display: inline-flex; align-items: center; justify-content: center; color: #8c96aa; }
.empty-title { font-weight: 700; color: #3b455d; }

.alert { border-radius: 14px; padding: 13px 14px; display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; border: 1px solid transparent; }
.alert .icon { margin-top: 1px; }
.alert-error { background: var(--danger-050); color: #8f2c21; border-color: #f5c9c4; }
.alert-success { background: var(--green-050); color: #236326; border-color: #c9e6cb; }
.alert-warning { background: var(--amber-050); color: #84530c; border-color: #f0dcb4; }
.alert-info { background: var(--navy-050); color: #26327a; border-color: #d6dcf7; }
.alert ul { margin: 0; padding-left: 18px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 12px 16px; }
.pager-pages { display: flex; align-items: center; gap: 4px; }
.pager-link {
  min-width: 34px; height: 34px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: #4b556b; font-size: 13px; font-weight: 600;
}
.pager-link:hover { background: #f7f9fd; }
.pager-link.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.pager-link.disabled { opacity: 0.4; pointer-events: none; }
.pager-info { font-size: 12px; color: var(--muted); }

.toast-stack {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top, 0px));
  left: 12px;
  right: 12px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 13px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  font-size: 13.5px;
  animation: toast-in 0.2s ease;
}
.toast.success { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--amber); }
.toast.info { border-left: 4px solid var(--navy); }
.toast .toast-close { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------------------------
   Auth screens
   -------------------------------------------------------------------------- */
.auth-body {
  min-height: 100vh;
  background: radial-gradient(1200px 500px at 100% -10%, #e9edfb 0%, transparent 60%),
              radial-gradient(900px 400px at 0% 110%, #e9f4ea 0%, transparent 55%),
              #f6f8fc;
  display: flex;
  align-items: stretch;
  justify-content: center;
}
.auth-shell { width: 100%; max-width: 1120px; display: grid; grid-template-columns: 1fr; padding: 18px 16px 30px; gap: 18px; }
.auth-hero {
  border-radius: 22px;
  padding: 22px;
  color: #fff;
  background: linear-gradient(140deg, #182064 0%, #1a237e 42%, #245c39 100%);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 180px;
}
.auth-hero::after {
  content: "";
  position: absolute;
  inset: -40% -20% auto auto;
  width: 420px; height: 420px;
  background: radial-gradient(circle, rgba(255,255,255,0.16), transparent 62%);
}
.auth-hero .brand { color: #fff; font-size: 30px; }
.auth-hero .brand .brand-a, .auth-hero .brand .brand-b { color: #fff; }
.auth-hero-copy { font-size: 14px; color: rgba(255,255,255,0.78); max-width: 420px; margin-top: auto; position: relative; z-index: 1; }
.auth-hero-tag { font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase; color: rgba(255,255,255,0.65); font-weight: 700; }
.auth-hero-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; position: relative; z-index: 1; }
.auth-hero-badges span { font-size: 11px; padding: 5px 9px; border-radius: 999px; background: rgba(255,255,255,0.13); border: 1px solid rgba(255,255,255,0.16); }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-md); padding: 22px; }
.auth-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.auth-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #f1f4fa; padding: 4px; border-radius: 12px; margin: 18px 0 16px; }
.segmented a { padding: 9px 8px; text-align: center; border-radius: 9px; font-size: 13.5px; font-weight: 700; color: #6b748a; }
.segmented a.active { background: #fff; color: var(--navy); box-shadow: var(--shadow-sm); }
.auth-foot { margin-top: 16px; text-align: center; font-size: 12px; color: var(--muted); }
.password-wrap { position: relative; }
.password-wrap .input { padding-right: 46px; }
.password-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; background: none; color: #7a8398; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; }
.password-toggle:hover { background: #f3f5fa; }

/* --------------------------------------------------------------------------
   Employee form
   -------------------------------------------------------------------------- */
.form-hero {
  background: linear-gradient(135deg, #182064, #24358f 60%, #2d7c31);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.form-hero::after { content: ""; position: absolute; width: 260px; height: 260px; right: -90px; top: -110px; border-radius: 50%; background: rgba(255,255,255,0.08); }
.form-hero h2 { font-size: 19px; line-height: 1.25; position: relative; z-index: 1; }
.form-hero p { color: rgba(255,255,255,0.78); font-size: 12.5px; margin-top: 6px; position: relative; z-index: 1; }
.form-hero .hero-meta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 14px; font-size: 12px; color: rgba(255,255,255,0.85); position: relative; z-index: 1; }
.form-hero .hero-meta span { display: inline-flex; align-items: center; gap: 6px; }

.section-card { padding: 0; }
.section-head { padding: 15px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; background: #fbfcff; }
.section-index { width: 26px; height: 26px; border-radius: 8px; background: var(--navy-050); color: var(--navy); font-size: 12px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.section-title { font-size: 14.5px; font-weight: 700; line-height: 1.3; }
.section-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.section-body > .input, .section-body > .field { min-width: 0; }
.section-inline { font-size: 13.5px; color: #3b455d; }
.section-heading { font-size: 15px; font-weight: 800; color: var(--navy); }
.section-label { font-weight: 700; font-size: 13px; color: #3b455d; }

.editor-table { width: 100%; border-collapse: collapse; min-width: 600px; }
.editor-table th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: #667085; background: #f7f9fd; padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--line); font-weight: 700; white-space: nowrap; }
.editor-table td { padding: 5px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.editor-table tbody tr:last-child td { border-bottom: 0; }
.editor-table .input { min-height: 38px; padding: 7px 9px; font-size: 13.5px; border-radius: 8px; }
.editor-table .cell-index { font-weight: 700; color: #97a0b2; font-size: 12px; width: 34px; }
.editor-table .cell-label { min-width: 190px; font-weight: 600; font-size: 13px; color: #3b455d; }
.editor-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.row-remove { width: 30px; height: 30px; border: 0; background: var(--danger-050); color: var(--danger); border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.hidden-input { display: none; }

/* Compact tables on phones: up to 3 columns fit the viewport without
   horizontal scrolling, keeping long inspection lists scannable. */
@media (max-width: 639px) {
  .compact-table { overflow: visible; margin: 0 -16px !important; }
  .compact-table table { min-width: 0; width: 100%; table-layout: fixed; }
  .compact-table th,
  .compact-table td { padding: 4px 6px; font-size: 12px; line-height: 1.3; }
  .compact-table th { font-size: 9.5px; letter-spacing: 0.02em; padding: 7px 6px; }
  .compact-table td { height: auto; }
  .compact-table .input { min-height: 30px; height: 30px; padding: 3px 6px; font-size: 12px; border-radius: 6px; }
  .compact-table .cell-label { min-width: 0; padding-right: 4px; font-size: 12px; }
  .compact-table .cell-action { width: 26px; padding-left: 0; }
  .compact-table .row-remove { width: 24px; height: 24px; }
  .compact-table tbody td:first-child { overflow-wrap: anywhere; }
}

/* Wide tables (4+ columns) become labelled cards on phones. */
@media (max-width: 639px) {
  .stack-table { overflow: visible; margin: 0 !important; }
  .stack-table .editor-table,
  .stack-table .data-table { min-width: 0; display: block; }
  .stack-table thead { display: none; }
  .stack-table tbody { display: flex; flex-direction: column; gap: 10px; }
  .stack-table tbody tr {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    background: #fbfcff;
  }
  .stack-table tbody td { border: 0; padding: 4px 0; display: flex; align-items: center; gap: 10px; font-size: 13px; }
  .stack-table tbody td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #77809a;
  }
  .stack-table tbody td.cell-label { font-weight: 700; color: #2b3550; }
  .stack-table tbody td[data-label=""]::before { content: none; }
  .stack-table tbody td .input { min-height: 36px; }
  .stack-table tbody td.cell-action { justify-content: flex-end; padding-top: 6px; }
  .stack-table tbody td.cell-action::before { content: none; }
}

.photo-input { border: 1.5px dashed var(--line-strong); border-radius: 14px; padding: 14px; background: #fbfcff; display: flex; flex-direction: column; gap: 10px; }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-actions label.btn { cursor: pointer; }
.photo-preview { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-chip { position: relative; width: 78px; height: 78px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #fff; }
.photo-chip img { width: 100%; height: 100%; object-fit: cover; }
.photo-chip .remove { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 6px; border: 0; background: rgba(0,0,0,0.58); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }

.sticky-submit {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 28;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: rgba(255,255,255,0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
  display: flex;
  gap: 10px;
}
.sticky-submit .btn { flex: 1; }
body.form-mode .page { padding-bottom: 110px; }
body.form-mode .bottom-nav { display: none; }

.gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.gallery figure { margin: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fafbfe; }
.gallery img { width: 100%; height: 130px; object-fit: cover; }
.gallery figcaption { font-size: 11px; color: var(--muted); padding: 6px 8px; }

/* --------------------------------------------------------------------------
   Builder
   -------------------------------------------------------------------------- */
.builder-toolbar { position: sticky; top: 58px; z-index: 15; background: rgba(243,245,250,0.94); backdrop-filter: blur(8px); padding: 2px 0; }
body.builder-mode .page { padding-bottom: 112px; }
body.builder-mode .bottom-nav { display: none; }
.builder-section { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; overflow: hidden; box-shadow: var(--shadow-sm); }
.builder-section-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px; background: #f8fafd; border-bottom: 1px solid var(--line); }
.builder-section-head .input { flex: 1 1 220px; min-height: 40px; background: #fff; font-weight: 600; }
.builder-section-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; background: #fdfefe; }
.builder-field { border: 1px solid var(--line); border-radius: 13px; background: #fff; padding: 11px; }
.builder-field-top { display: flex; gap: 8px; align-items: center; }
.builder-field-top .input { flex: 1 1 auto; min-width: 0; min-height: 38px; }
.builder-field-controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.builder-field-controls .select { flex: 1 1 112px; min-height: 38px; min-width: 0; }
.builder-field-controls .switch { flex: 0 0 auto; }
.field-drag { font-size: 11px; color: #97a0b2; font-weight: 700; padding: 0 2px; }
.builder-field-extra { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); display: grid; gap: 8px; }
.builder-field-extra.collapsed { display: none; }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: #5c667c; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.icon-btn:hover { background: #f6f8fc; }
.icon-btn.danger { color: var(--danger); border-color: #f3d3cf; background: #fef7f6; }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.add-field-bar { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 2px; }
.chip-btn { border: 1px dashed var(--line-strong); background: #fff; color: #4d5770; border-radius: 999px; padding: 5px 11px; font-size: 12px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.chip-btn:hover { border-color: var(--navy); color: var(--navy); background: var(--navy-050); }
.builder-note { font-size: 12px; color: var(--muted); }
.column-row { display: grid; grid-template-columns: 1fr 100px auto auto auto; gap: 6px; align-items: center; }
.column-card {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fbfcfe;
}
.column-card .input { min-height: 38px; }
.card > summary { list-style: none; }
.card > summary::-webkit-details-marker { display: none; }
.mono-textarea { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12.5px; line-height: 1.5; }

/* --------------------------------------------------------------------------
   Detail view
   -------------------------------------------------------------------------- */
.detail-hero { background: linear-gradient(135deg, #182064, #2a3a96); color: #fff; border-radius: var(--radius); padding: 20px; }
.detail-hero .record-no { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; color: rgba(255,255,255,0.7); letter-spacing: 0.03em; }
.detail-hero h2 { font-size: 21px; margin-top: 4px; }
.detail-hero .meta { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 12.5px; color: rgba(255,255,255,0.8); margin-top: 12px; }
.detail-hero .meta span { display: inline-flex; align-items: center; gap: 6px; }
.kv { display: grid; grid-template-columns: 1fr; gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.kv-row { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; border-top: 1px solid var(--line); }
.kv-row:first-child { border-top: 0; }
.kv-key { background: #f7f9fd; padding: 10px 12px; font-size: 12.5px; font-weight: 700; color: #4b556b; }
.kv-val { padding: 10px 12px; font-size: 13.5px; word-break: break-word; }
.data-table.plain th { background: transparent; }
.detail-table { min-width: 560px; }
.detail-table td.green { color: var(--green); font-weight: 700; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (min-width: 640px) {
  .page { padding: 22px 22px calc(var(--bottom-nav) + 30px + var(--safe-bottom)); gap: 18px; }
  .page-title { font-size: 26px; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .toast-stack { left: auto; right: 18px; width: 360px; }
  .auth-shell { padding: 26px 22px 40px; }
  .auth-card { padding: 28px; }
  .record { flex-direction: row; align-items: center; justify-content: space-between; }
  .record-main { min-width: 0; }
  .record-actions { justify-content: flex-end; }
}

@media (min-width: 900px) {
  .sidebar { display: flex; }
  .app-main { margin-left: 264px; }
  .bottom-nav { display: none; }
  .topbar { padding: 10px 28px; min-height: 54px; }
  .topbar-brand { display: none; }
  .topbar-title { display: none; }
  .page { padding: 26px 32px 48px; max-width: 1180px; }
  .sticky-submit { display: none; }
  body.form-mode .page { padding-bottom: 48px; }
  .auth-shell { grid-template-columns: 0.9fr 1.1fr; align-items: stretch; padding: 42px 32px; gap: 22px; min-height: 100vh; }
  .auth-hero { padding: 38px; justify-content: flex-start; gap: 14px; }
  .auth-hero .brand { font-size: 38px; }
  .auth-hero-copy { font-size: 16px; margin-top: 20px; }
  .auth-hero-badges { margin-top: auto; }
  .auth-card { padding: 38px; display: flex; flex-direction: column; justify-content: center; }
  .builder-toolbar { top: 70px; }
}

@media (min-width: 1100px) {
  .form-grid.two { gap: 16px 18px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Print: clean report detail */
@media print {
  .sidebar, .topbar, .bottom-nav, .page-actions, .toast-stack, .sticky-submit, .pager { display: none !important; }
  .app-main { margin-left: 0; }
  .page { max-width: none; padding: 0; }
  body { background: #fff; }
  .card, .detail-hero { box-shadow: none; border-color: #ccc; }
}
