/* Modern UI system for Detain System. Presentation only. */
:root {
  --app-bg: #eef3f8;
  --app-ink: #102033;
  --app-muted: #5d6b7c;
  --app-soft: #f7fafc;
  --app-line: #dce5ee;
  --app-panel: rgba(255, 255, 255, 0.92);
  --app-navy: #071f3d;
  --app-blue: #0f66ad;
  --app-teal: #0f8f8a;
  --app-red: #c9283e;
  --app-gold: #f3bd3d;
  --app-green: #198754;
  --app-shadow: 0 20px 45px rgba(16, 32, 51, 0.12);
  --app-shadow-sm: 0 8px 22px rgba(16, 32, 51, 0.10);
  --app-radius: 8px;
  --app-radius-sm: 6px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--app-bg);
  overflow-y: scroll;
  scrollbar-gutter: stable;
  text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--app-ink);
  background:
    linear-gradient(180deg, rgba(7, 31, 61, 0.05), transparent 260px),
    var(--app-bg) !important;
  letter-spacing: 0;
  overflow-x: hidden;
}

body,
input,
select,
textarea,
button {
  font-family: "Sarabun", "Prompt", "TH Sarabun New", Tahoma, Arial, sans-serif !important;
}

a {
  color: inherit;
}

img,
iframe,
embed {
  max-width: 100%;
}

.navbar,
.header {
  position: sticky;
  top: 0;
  z-index: 900;
  display: grid !important;
  grid-template-columns: minmax(260px, 1fr) auto minmax(300px, 1fr);
  align-items: center !important;
  gap: 18px;
  width: 100% !important;
  min-height: 78px;
  padding: 12px clamp(18px, 3vw, 40px) !important;
  background: rgba(7, 31, 61, 0.96) !important;
  color: #fff;
  box-shadow: 0 8px 30px rgba(7, 31, 61, 0.20) !important;
  backdrop-filter: blur(18px);
}

.navbar {
  grid-template-areas: "brand menu user";
}

.notification-navbar {
  grid-template-columns: minmax(240px, 1fr) auto;
  grid-template-areas: "brand user";
}

.header {
  grid-template-columns: minmax(260px, 1fr) auto;
}

.header > div,
.admin-header-actions {
  display: flex !important;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.navbar-left,
.navbar-right {
  width: auto !important;
  min-width: 0 !important;
}

.navbar-left {
  grid-area: brand;
  display: flex !important;
  align-items: center !important;
  gap: 12px;
}

.brand-logo {
  display: block;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  padding: 0;
  border: 0;
  border-radius: var(--app-radius);
  background: transparent;
  object-fit: contain;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

.navbar .nav-brand {
  grid-area: brand;
  display: inline-flex !important;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: #fff !important;
  text-decoration: none !important;
}

.navbar .nav-logo {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: var(--app-radius);
  background: url("../img/logo-detain-system.svg") center / contain no-repeat;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  font-size: 0;
}

.navbar .nav-logo::before {
  display: none;
}

.navbar .nav-title {
  overflow: hidden;
  color: #fff;
  font-size: clamp(18px, 1.5vw, 24px);
  font-weight: 900;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.navbar-left::before {
  display: none;
}

.navbar-left h2,
.navbar h2,
.header h1 {
  margin: 0;
  color: #fff !important;
  font-size: clamp(19px, 1.55vw, 26px) !important;
  font-weight: 800 !important;
  line-height: 1.15;
  letter-spacing: 0 !important;
  text-shadow: none !important;
  overflow-wrap: anywhere;
}

.navbar-links {
  grid-area: menu;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-wrap: nowrap !important;
  gap: 4px;
  min-width: 0;
  margin: 0 !important;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
}

.navbar-links > a,
.header a,
.navbar-right a,
.navbar .nav-back {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  margin: 0 !important;
  padding: 8px 14px !important;
  border-radius: 999px !important;
  color: rgba(255, 255, 255, 0.86) !important;
  font-size: 16px !important;
  font-weight: 700;
  line-height: 1.1;
  text-decoration: none !important;
  white-space: nowrap;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.navbar .nav-back {
  grid-area: user;
  justify-self: end;
}

.navbar-links > a:hover,
.navbar-right a:hover,
.header a:hover {
  color: #fff !important;
  background: rgba(255, 255, 255, 0.12);
}

.navbar-links > a.active {
  color: #101820 !important;
  background: var(--app-gold);
}

.navbar-links > a.active::after {
  display: none !important;
}

.navbar-right {
  grid-area: user;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  justify-self: end;
  gap: 10px;
  max-width: 100%;
  flex-wrap: nowrap;
  text-align: right !important;
  white-space: nowrap !important;
}

.navbar-right .user-chip,
.admin-header-actions .user-chip {
  margin: 0 !important;
}

.navbar-right .user-chip span,
.admin-header-actions .user-chip span {
  display: block;
  margin: 0 !important;
}

.navbar-right > span {
  min-width: 0;
  color: rgba(255, 255, 255, 0.82) !important;
  font-size: 14px !important;
  font-weight: 600;
  line-height: 1.35;
}

.user-chip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 8px;
  row-gap: 1px;
  align-items: center;
  width: min(34vw, 340px);
  min-width: 0;
  max-width: 340px;
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  color: #fff;
  text-align: left;
}

.user-chip-label {
  grid-row: 1 / span 2;
  display: inline-grid;
  place-items: center;
  position: relative;
  width: 28px;
  height: 28px;
  overflow: hidden;
  border-radius: 50%;
  background: rgba(243, 189, 61, 0.16);
  color: var(--app-gold);
  font-size: 0 !important;
}

.user-chip-label::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 50%;
  width: 8px;
  height: 8px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: currentColor;
}

.user-chip-label::after {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 50%;
  width: 16px;
  height: 9px;
  transform: translateX(-50%);
  border: 2px solid currentColor;
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
}

.navbar-right .user-chip-label,
.admin-header-actions .user-chip-label {
  color: var(--app-gold) !important;
  font-size: 0 !important;
}

.user-chip-main,
.user-chip-role {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip-main {
  color: #fff !important;
  font-size: 14px !important;
  font-weight: 800;
  line-height: 1.15;
}

.user-chip-role {
  color: rgba(255, 255, 255, 0.68) !important;
  font-size: 12px !important;
  font-weight: 700;
  line-height: 1.1;
}

.navbar-right a[href*="logout"],
a.logout-link[href*="logout"] {
  flex: 0 0 auto;
  color: #101820 !important;
  background: var(--app-gold);
}

.navbar-right .user-chip-main,
.admin-header-actions .user-chip-main {
  color: #fff !important;
  font-size: 14px !important;
  font-weight: 800 !important;
}

.navbar-right .user-chip-role,
.admin-header-actions .user-chip-role {
  color: rgba(255, 255, 255, 0.68) !important;
  font-size: 12px !important;
  font-weight: 700 !important;
}

.admin-header-actions .user-chip {
  width: min(28vw, 320px);
}

.container,
.login-box,
.register-box,
.result-box,
.table-box,
.notif-box,
.modal-content {
  border-radius: var(--app-radius) !important;
  box-shadow: var(--app-shadow) !important;
}

.container {
  width: min(100% - 36px, 1320px) !important;
  margin: 28px auto 42px !important;
  padding: clamp(18px, 3vw, 34px) !important;
  border: 1px solid rgba(220, 229, 238, 0.85);
  background: var(--app-panel) !important;
  overflow-x: auto;
}

.app-dashboard {
  width: min(100% - 36px, 1440px) !important;
  margin: 0 auto 42px !important;
  padding: clamp(22px, 4vw, 44px) 0 !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  overflow: visible !important;
}

.dashboard-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}

.hero-panel,
.profile-panel,
.action-card,
.quick-panel {
  border: 1px solid rgba(220, 229, 238, 0.88);
  border-radius: var(--app-radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--app-shadow-sm);
}

.hero-panel {
  position: relative;
  padding: clamp(24px, 4vw, 42px);
  background: #071f3d;
  color: #fff;
  overflow: hidden;
  isolation: isolate;
}

.hero-panel::before {
  content: "";
  position: absolute;
  inset: -8%;
  z-index: -2;
  background-image: url("../img/dashboard-hero-port.png");
  background-repeat: repeat-x;
  background-size: auto 100%;
  background-position: 0 50%;
  opacity: 0.72;
  transform: scale(1.08);
  animation: hero-bg-pan 34s linear infinite;
}

.hero-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 22% 20%, rgba(15, 102, 173, 0.28), transparent 42%),
    linear-gradient(135deg, rgba(3, 17, 36, 0.88), rgba(7, 31, 61, 0.78) 48%, rgba(4, 39, 72, 0.82));
}

.hero-panel > * {
  position: relative;
  z-index: 1;
}

@keyframes hero-bg-pan {
  from {
    background-position: 0 50%;
  }

  to {
    background-position: -900px 50%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hero-panel::before {
    animation: none;
  }
}

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.hero-eyebrow::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--app-gold);
}

.hero-title {
  max-width: 760px;
  margin: 0 0 12px;
  color: #fff;
  font-size: clamp(32px, 5vw, 58px);
  font-weight: 900;
  letter-spacing: 0 !important;
  line-height: 1.02;
  overflow-wrap: anywhere;
}

.hero-copy {
  max-width: 720px;
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: clamp(16px, 1.6vw, 20px);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}

.hero-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.88);
  background: rgba(255, 255, 255, 0.09);
  font-size: 14px;
  font-weight: 700;
}

.profile-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 22px;
}

.profile-kicker {
  color: var(--app-muted);
  font-size: 13px;
  font-weight: 800;
}

.profile-name {
  margin: 8px 0 4px;
  color: var(--app-ink);
  font-size: 24px;
  font-weight: 900;
  line-height: 1.15;
}

.profile-role {
  color: var(--app-muted);
  font-size: 15px;
  font-weight: 700;
}

.profile-divider {
  height: 1px;
  margin: 18px 0;
  background: var(--app-line);
}

.phone-row,
.signature-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.phone-row svg,
.signature-row svg {
  width: 22px;
  height: 22px;
  color: var(--app-blue);
}

.profile-label {
  color: var(--app-muted);
  font-size: 13px;
  font-weight: 800;
}

.profile-value {
  color: var(--app-ink);
  font-size: 17px;
  font-weight: 900;
}

.link-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius-sm);
  color: var(--app-blue);
  background: #fff;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.actions-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(280px, 0.88fr);
  gap: 18px;
  margin: 18px 0;
}

.action-card {
  position: relative;
  display: grid !important;
  min-height: 215px;
  padding: 22px;
  color: var(--app-ink) !important;
  text-decoration: none;
  overflow: hidden;
  isolation: isolate;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.action-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--app-blue);
  z-index: -1;
}

.action-card.detain {
  grid-row: span 2;
  min-height: 448px;
  padding: clamp(24px, 3vw, 34px);
  background:
    linear-gradient(135deg, rgba(201, 40, 62, 0.08), transparent 46%),
    rgba(255, 255, 255, 0.95);
}

.action-card.detain::before {
  background: var(--app-red);
}

.action-card.release::before {
  background: var(--app-blue);
}

.action-card.records::before {
  background: var(--app-teal);
}

.action-card:hover {
  transform: translateY(-4px);
  border-color: rgba(15, 102, 173, 0.35);
  box-shadow: 0 24px 54px rgba(16, 32, 51, 0.16) !important;
}

.action-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.action-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: var(--app-radius);
  color: #fff;
}

.action-icon svg {
  width: 28px;
  height: 28px;
  stroke-width: 2;
}

.action-card.detain .action-icon {
  background: var(--app-red);
}

.action-card.release .action-icon {
  background: var(--app-blue);
}

.action-card.records .action-icon {
  background: var(--app-teal);
}

.action-arrow {
  color: var(--app-muted);
  font-size: 24px;
  line-height: 1;
}

.action-title {
  display: block;
  margin: 26px 0 8px;
  color: var(--app-ink);
  font-size: clamp(22px, 2vw, 30px);
  font-weight: 900;
  letter-spacing: 0 !important;
  line-height: 1.15;
}

.action-card.detain .action-title {
  font-size: clamp(28px, 2.6vw, 38px);
}

.action-desc {
  display: block;
  margin: 0;
  color: var(--app-muted);
  font-size: 17px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.action-foot {
  display: block;
  align-self: end;
  margin-top: 20px;
  color: var(--app-blue);
  font-size: 14px;
  font-weight: 900;
}

.quick-panel {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(0, 1.2fr);
  gap: 22px;
  padding: 22px;
}

.signature-preview {
  display: grid;
  place-items: center;
  min-height: 190px;
  border: 1px dashed #bdc8d4;
  border-radius: var(--app-radius);
  background: var(--app-soft);
}

.signature-preview img {
  max-height: 150px;
  border: 0 !important;
  margin: 0 !important;
  object-fit: contain;
}

.signature-empty {
  color: var(--app-muted);
  font-size: 16px;
  font-weight: 700;
}

.settings-panel h3 {
  margin: 0 0 14px;
  font-size: 24px;
  font-weight: 900;
}

.settings-panel form {
  margin-top: 14px;
}

.settings-panel input[type="file"],
.settings-panel input[type="text"] {
  width: 100% !important;
}

.settings-panel button,
button,
.submit-btn,
.back-btn,
.hold-btn,
.btn-search,
.btn-reset,
.btn-details,
.btn-add,
.email-btn,
.cancel-btn {
  min-height: 42px;
  border: 0 !important;
  border-radius: var(--app-radius-sm) !important;
  box-shadow: none !important;
  line-height: 1.2;
  font-weight: 800;
  white-space: normal;
}

.settings-panel button,
.submit-btn,
.btn-search,
.btn-add,
.email-btn {
  background: var(--app-blue) !important;
  color: #fff !important;
}

.back-btn,
.btn-reset,
.cancel-btn {
  background: #e8edf3 !important;
  color: var(--app-ink) !important;
}

.hold-btn {
  background: var(--app-gold) !important;
  color: #101820 !important;
}

.message {
  color: var(--app-green) !important;
}

.login-box,
.register-box {
  width: min(100% - 32px, 450px) !important;
  margin: clamp(32px, 8vh, 84px) auto !important;
  padding: clamp(22px, 5vw, 34px) !important;
  border: 1px solid var(--app-line);
  background: var(--app-panel) !important;
}

h1,
h2,
h3,
h4,
.main-title,
.title {
  letter-spacing: 0 !important;
  line-height: 1.22;
}

.main-title,
.title {
  color: var(--app-ink) !important;
  font-size: clamp(25px, 3vw, 36px) !important;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="file"],
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-height: 44px;
  border: 1px solid var(--app-line) !important;
  border-radius: var(--app-radius-sm) !important;
  background: #fff !important;
  color: var(--app-ink) !important;
  font-size: 16px !important;
  line-height: 1.35;
  box-shadow: none !important;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(15, 102, 173, 0.18) !important;
  border-color: var(--app-blue) !important;
}

.input-row {
  align-items: flex-start !important;
}

.input-field {
  min-width: 0;
  flex-wrap: wrap;
}

.input-field > * {
  min-width: min(100%, 180px);
}

.container-row {
  align-items: stretch;
}

.container-row input {
  min-width: 0;
}

.add-btn,
.remove-btn {
  flex: 0 0 44px;
}

table {
  min-width: 820px;
  border-collapse: separate !important;
  border-spacing: 0;
  overflow: hidden;
}

th {
  background: var(--app-navy) !important;
  color: #fff !important;
}

th,
td {
  vertical-align: middle;
}

.table-box,
.container {
  overflow-x: auto;
}

.search-box,
.filter-box,
.details-group {
  border: 1px solid var(--app-line) !important;
  border-radius: var(--app-radius) !important;
  background: rgba(255, 255, 255, 0.72) !important;
  box-shadow: none !important;
}

.search-row,
.filter-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px !important;
}

.search-row input,
.search-row select,
.filter-box input,
.filter-box select {
  flex: 1 1 160px;
  width: auto !important;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.pagination a {
  min-width: 40px;
  text-align: center;
}

.pdf-preview,
.modal-iframe {
  min-height: 420px;
  border-radius: var(--app-radius) !important;
}

@media (max-width: 1360px) {
  .navbar {
    grid-template-columns: minmax(260px, 1fr) auto;
    grid-template-areas:
      "brand user"
      "menu menu";
  }

  .notification-navbar {
    grid-template-columns: minmax(240px, 1fr) auto;
    grid-template-areas: "brand user";
  }

  .navbar-links {
    justify-self: center;
  }

  .user-chip {
    width: min(38vw, 330px);
  }
}

@media (max-width: 1160px) {
  .navbar,
  .header {
    grid-template-columns: 1fr;
    align-items: start !important;
  }

  .navbar {
    grid-template-areas:
      "brand"
      "menu"
      "user";
  }

  .notification-navbar {
    grid-template-areas:
      "brand"
      "user";
  }

  .navbar-links {
    justify-self: start;
    flex-wrap: wrap !important;
    border-radius: var(--app-radius);
  }

  .navbar-right {
    justify-content: flex-start !important;
    justify-self: stretch;
    text-align: left !important;
  }

  .user-chip {
    width: min(100%, 380px);
    max-width: 100%;
  }

  .dashboard-hero,
  .quick-panel {
    grid-template-columns: 1fr;
  }

  .actions-grid {
    grid-template-columns: 1fr;
  }

  .action-card.detain {
    grid-row: auto;
    min-height: 245px;
  }
}

@media (max-width: 720px) {
  body {
    width: 100%;
    max-width: 100vw;
  }

  .navbar,
  .header {
    width: 100vw !important;
    max-width: 100vw;
    padding: 12px 14px !important;
  }

  .navbar-links {
    width: 100%;
    justify-content: flex-start !important;
  }

  .navbar-right {
    width: 100%;
    flex-wrap: wrap;
  }

  .user-chip {
    flex: 1 1 100%;
    width: 100%;
  }

  .navbar-links > a,
  .navbar-right a {
    font-size: 15px !important;
    padding: 8px 10px !important;
  }

  .container,
  .app-dashboard {
    width: calc(100vw - 20px) !important;
    max-width: 1320px;
  }

  .container {
    padding: 16px !important;
  }

  .container.app-dashboard {
    padding: 0 !important;
    overflow: visible !important;
  }

  .dashboard-hero,
  .actions-grid,
  .quick-panel,
  .hero-panel,
  .profile-panel,
  .action-card {
    max-width: 100%;
    min-width: 0;
  }

  .hero-meta {
    gap: 8px;
  }

  .hero-chip {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .hero-panel,
  .profile-panel,
  .action-card,
  .quick-panel {
    padding: 18px;
  }

  .input-row {
    display: block !important;
  }

  .input-label {
    width: auto !important;
    min-width: 0 !important;
    padding: 0 0 6px !important;
    text-align: left !important;
    display: block;
  }

  .input-field {
    display: grid !important;
    grid-template-columns: 1fr;
  }

  .container-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr 44px;
  }

  .action-group,
  .button-group,
  .table-header,
  .table-actions {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .submit-btn,
  .back-btn,
  .hold-btn,
  .button-group button,
  .button-group input[type="submit"] {
    width: 100% !important;
    min-width: 0 !important;
  }

  .modal-content {
    width: min(100% - 20px, 520px) !important;
    margin: 5vh auto !important;
    max-height: 90vh !important;
  }

  .noti-dropdown-content {
    width: min(92vw, 360px) !important;
  }
}

/* 2026 visual refresh: cleaner official operations UI. */
:root {
  --app-bg: #f4f7fb;
  --app-ink: #111827;
  --app-muted: #667085;
  --app-soft: #f8fafc;
  --app-line: #d8e0ea;
  --app-panel: rgba(255, 255, 255, 0.96);
  --app-navy: #101828;
  --app-blue: #2563eb;
  --app-teal: #0d9488;
  --app-red: #e11d48;
  --app-gold: #f59e0b;
  --app-green: #16a34a;
  --app-shadow: 0 18px 44px rgba(17, 24, 39, 0.10);
  --app-shadow-sm: 0 8px 22px rgba(17, 24, 39, 0.08);
  --app-radius: 8px;
  --app-radius-sm: 6px;
}

body {
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.06), transparent 280px),
    radial-gradient(circle at 90% 0%, rgba(13, 148, 136, 0.08), transparent 360px),
    var(--app-bg) !important;
}

.navbar,
.header {
  min-height: 74px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(16, 24, 40, 0.97) !important;
  box-shadow: 0 14px 34px rgba(16, 24, 40, 0.18) !important;
}

.brand-logo,
.navbar .nav-logo {
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.16);
}

.navbar-left h2,
.navbar h2,
.header h1,
.navbar .nav-title {
  font-weight: 900 !important;
}

.navbar-links {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.navbar-links > a,
.header a,
.navbar-right a,
.navbar .nav-back {
  color: rgba(255, 255, 255, 0.78) !important;
  font-weight: 800;
}

.navbar-links > a:hover,
.navbar-right a:hover,
.header a:hover {
  background: rgba(255, 255, 255, 0.10);
}

.navbar-links > a.active {
  color: #111827 !important;
  background: #fbbf24;
  box-shadow: 0 8px 18px rgba(251, 191, 36, 0.24);
}

.user-chip {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
}

.user-chip-label {
  background: rgba(251, 191, 36, 0.16);
  color: #fbbf24;
}

.navbar-right a[href*="logout"],
a.logout-link[href*="logout"] {
  background: #fbbf24;
  color: #101828 !important;
}

.container,
.login-box,
.register-box,
.result-box,
.table-box,
.notif-box,
.modal-content,
.profile-panel,
.action-card,
.quick-panel,
.hero-panel,
.mirror-panel,
.mirror-hero {
  border: 1px solid rgba(216, 224, 234, 0.96) !important;
  box-shadow: var(--app-shadow-sm) !important;
}

.container,
.login-box,
.register-box,
.result-box,
.table-box,
.notif-box,
.modal-content,
.profile-panel,
.action-card,
.quick-panel {
  background: var(--app-panel) !important;
}

.hero-panel {
  background: #101828;
}

.hero-panel::after {
  background:
    linear-gradient(135deg, rgba(16, 24, 40, 0.92), rgba(30, 64, 175, 0.80) 54%, rgba(13, 148, 136, 0.72)),
    linear-gradient(90deg, rgba(16, 24, 40, 0.18), rgba(16, 24, 40, 0));
}

.hero-title,
.mirror-hero-title {
  color: #ffffff !important;
  font-weight: 900;
}

.hero-copy,
.alert-message {
  color: rgba(255, 255, 255, 0.82) !important;
}

.hero-chip,
.mirror-eyebrow,
.alert-kicker {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.88);
}

.action-card {
  background: #ffffff !important;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.action-card::before {
  height: 3px;
}

.action-icon {
  border: 1px solid rgba(216, 224, 234, 0.96);
  background: #f8fafc !important;
  color: var(--app-blue);
}

.action-card.detain .action-icon {
  color: var(--app-red);
}

.action-card.release .action-icon {
  color: var(--app-blue);
}

.action-card.records .action-icon {
  color: var(--app-teal);
}

.action-arrow {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--app-line);
  border-radius: 999px;
  color: var(--app-muted);
  background: #fff;
  font-size: 18px;
}

.action-title,
.profile-name,
.settings-panel h3,
.feed-header h2,
.panel-title h2,
.table-header h3,
.main-title,
.title,
.page-title {
  color: var(--app-ink) !important;
  font-weight: 900 !important;
}

.action-desc,
.profile-role,
.profile-label,
.status-label,
.page-sub,
.feed-header span,
.panel-title span {
  color: var(--app-muted) !important;
}

button,
.submit-btn,
.btn-search,
.btn-add,
.email-btn,
.mirror-button.primary {
  background: var(--app-blue) !important;
  color: #fff !important;
}

button:hover,
.submit-btn:hover,
.btn-search:hover,
.btn-add:hover,
.email-btn:hover {
  filter: brightness(0.96);
}

.back-btn,
.btn-reset,
.cancel-btn,
.ghost-button,
.mirror-button.secondary,
.reset-btn {
  background: #eef2f7 !important;
  color: var(--app-ink) !important;
}

.hold-btn {
  background: #f59e0b !important;
  color: #111827 !important;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="file"],
select,
textarea {
  border-color: #d8e0ea !important;
  background: #fff !important;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(37, 99, 235, 0.16) !important;
  border-color: var(--app-blue) !important;
}

th {
  background: #111827 !important;
  color: #ffffff !important;
}

td {
  color: var(--app-ink);
}

tr:hover {
  background: #f8fafc !important;
}

.status-red,
.status-yellow,
.status-green,
.status-purple,
.status-orange,
.badge,
.pending,
.officer,
.admin,
.mirror {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 5px 11px !important;
  border-radius: 999px !important;
  font-size: 13px !important;
  font-weight: 900 !important;
  line-height: 1.1;
}

.status-red {
  background: #ffe4e8 !important;
  color: #9f1239 !important;
}

.status-yellow,
.pending {
  background: #fef3c7 !important;
  color: #92400e !important;
}

.status-green,
.officer {
  background: #dcfce7 !important;
  color: #166534 !important;
}

.status-purple,
.mirror {
  background: #ede9fe !important;
  color: #5b21b6 !important;
}

.status-orange {
  background: #ffedd5 !important;
  color: #9a3412 !important;
}

.admin {
  background: #dbeafe !important;
  color: #1e40af !important;
}

#notification-link {
  border-color: rgba(255, 255, 255, 0.16) !important;
  background: rgba(255, 255, 255, 0.08) !important;
}

#notification-link:hover,
#notification-link.active {
  background: rgba(251, 191, 36, 0.18) !important;
}

#notification-badge {
  background: #e11d48 !important;
}

.noti-dropdown-content {
  border-color: rgba(216, 224, 234, 0.96) !important;
  box-shadow: 0 24px 64px rgba(17, 24, 39, 0.22) !important;
}

.noti-header,
.noti-footer {
  background: #f8fafc !important;
}

.mobile-card-table tr {
  border-color: rgba(216, 224, 234, 0.96) !important;
}

.mobile-card-table td::before {
  color: #667085 !important;
}

@media (max-width: 520px) {
  .hero-title {
    width: 100%;
    max-width: 330px;
    font-size: 28px;
    line-height: 1.08;
    overflow-wrap: anywhere;
    word-break: break-all;
  }

  .hero-copy,
  .action-title,
  .action-desc {
    width: 100%;
    max-width: 330px;
    overflow-wrap: anywhere;
    word-break: break-all;
  }

  .hero-meta {
    display: grid;
    grid-template-columns: 1fr;
  }

  .hero-chip {
    width: 100%;
    justify-content: center;
  }

  .phone-row,
  .signature-row {
    grid-template-columns: 24px 1fr;
  }

  .phone-row .link-button {
    grid-column: 2;
    justify-self: start;
  }

  .container-row {
    grid-template-columns: 1fr 44px !important;
  }

  .container-row input[name="container_no[]"] {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .add-btn,
  .remove-btn {
    grid-column: 2;
    grid-row: 1;
  }

  .pdf-preview,
  .modal-iframe {
    height: 58vh !important;
    min-height: 320px;
  }
}

/* Responsive hardening for phones and iPads across legacy pages. */
@media (max-width: 1024px) {
  html {
    scrollbar-gutter: auto;
  }

  body {
    overflow-x: hidden !important;
  }

  .navbar,
  .header {
    position: sticky;
    grid-template-columns: 1fr !important;
    grid-template-areas:
      "brand"
      "menu"
      "user" !important;
    gap: 10px !important;
    min-height: 0 !important;
    padding: 12px max(14px, env(safe-area-inset-left)) 12px max(14px, env(safe-area-inset-right)) !important;
  }

  .notification-navbar {
    grid-template-areas:
      "brand"
      "user" !important;
  }

  .navbar-left,
  .navbar .nav-brand {
    width: 100% !important;
    min-width: 0 !important;
  }

  .navbar-left h2,
  .navbar h2,
  .navbar .nav-title,
  .header h1 {
    font-size: clamp(18px, 3vw, 24px) !important;
    white-space: normal !important;
    word-break: normal !important;
    overflow-wrap: anywhere !important;
  }

  .navbar-links {
    width: 100% !important;
    max-width: 100%;
    justify-content: flex-start !important;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    border-radius: var(--app-radius) !important;
  }

  .navbar-links > a,
  .header a,
  .navbar-right a,
  .navbar .nav-back {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 9px 12px !important;
    font-size: 15px !important;
  }

  .navbar-right,
  .header > div,
  .admin-header-actions {
    width: 100% !important;
    justify-content: flex-start !important;
    justify-self: stretch !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    text-align: left !important;
  }

  .user-chip,
  .admin-header-actions .user-chip,
  .navbar-right .user-chip {
    width: min(100%, 420px) !important;
    max-width: 100% !important;
  }

  .container,
  .app-dashboard,
  .page,
  .mirror-shell {
    width: min(100% - 24px, 1000px) !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .container {
    padding: clamp(16px, 3vw, 24px) !important;
  }

  .stats,
  .dashboard-hero,
  .actions-grid,
  .quick-panel,
  .mirror-hero-inner,
  .mirror-content-grid {
    grid-template-columns: 1fr !important;
  }

  .stats {
    display: grid !important;
  }

  .table-header,
  .table-actions,
  .filter-box,
  .search-box,
  .search-row,
  .action-group,
  .button-group,
  #action-button-group {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .table-header,
  .table-actions,
  .action-group,
  .button-group,
  #action-button-group {
    flex-direction: column !important;
  }

  .search-input,
  .filter-box input,
  .filter-box select,
  .filter-box button,
  .filter-box a,
  .search-row input,
  .search-row select,
  .search-row button,
  .search-row a,
  .table-actions input,
  .table-actions button {
    width: 100% !important;
    min-width: 0 !important;
  }

  .input-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .input-label {
    width: auto !important;
    min-width: 0 !important;
    padding: 0 !important;
    text-align: left !important;
  }

  .input-field {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: 10px !important;
    width: 100% !important;
  }

  .input-field input,
  .input-field select,
  .input-field textarea,
  .input-field [style*="max-width"] {
    max-width: 100% !important;
    width: 100% !important;
  }

  .form-group[style*="display: flex"],
  .form-group[style*="display:flex"] {
    flex-wrap: wrap !important;
  }

  .form-group[style*="display: flex"] > *,
  .form-group[style*="display:flex"] > * {
    min-width: min(100%, 220px) !important;
  }

  .container-row {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px !important;
    gap: 10px !important;
  }

  .add-btn,
  .remove-btn {
    width: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
  }

  .modal {
    padding: 14px !important;
  }

  .modal-content {
    width: min(100%, 720px) !important;
    max-width: calc(100vw - 28px) !important;
    margin: 4vh auto !important;
    max-height: 90vh !important;
    overflow: auto !important;
  }

  .pdf-preview,
  .modal-iframe,
  iframe {
    max-width: 100% !important;
  }
}

@media (max-width: 820px) {
  .brand-logo,
  .navbar-left .brand-logo {
    width: 40px !important;
    height: 40px !important;
    flex-basis: 40px !important;
  }

  .container,
  .app-dashboard,
  .page,
  .mirror-shell {
    width: calc(100vw - 18px) !important;
  }

  .hero-title,
  .mirror-hero-title,
  .page-title,
  .main-title,
  .title {
    font-size: clamp(25px, 7vw, 38px) !important;
    line-height: 1.12 !important;
    word-break: normal !important;
  }

  .hero-copy,
  .alert-message,
  .action-desc,
  .page-sub {
    font-size: clamp(15px, 4vw, 18px) !important;
  }

  .hero-panel,
  .profile-panel,
  .action-card,
  .quick-panel,
  .mirror-hero-inner,
  .control-panel,
  .feed-card,
  .table-box,
  .notif-box {
    padding: 16px !important;
  }

  table {
    min-width: 760px;
  }

  th,
  td {
    padding: 10px !important;
    font-size: 14px !important;
  }

  .feed-item,
  .notif-item {
    grid-template-columns: auto minmax(0, 1fr) !important;
  }

  .feed-time,
  .notif-arrow {
    grid-column: 2 !important;
  }

  .notif-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .notification-permission-card {
    width: min(100%, 440px) !important;
  }
}

@media (max-width: 560px) {
  html,
  body {
    min-width: 0;
  }

  .navbar,
  .header {
    width: 100% !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  .navbar-left {
    align-items: flex-start !important;
  }

  .navbar-left h2,
  .navbar h2,
  .navbar .nav-title,
  .header h1 {
    font-size: 18px !important;
    line-height: 1.2 !important;
  }

  .navbar-links {
    padding: 5px !important;
  }

  .navbar-links > a,
  .navbar-right a,
  .header a,
  .navbar .nav-back {
    min-height: 38px;
    padding: 8px 10px !important;
    font-size: 14px !important;
  }

  .user-chip {
    grid-template-columns: 28px minmax(0, 1fr);
    padding: 7px 10px !important;
  }

  .login-box,
  .register-box,
  .forgot-box,
  .result-box {
    width: calc(100vw - 22px) !important;
    margin: 22px auto !important;
    padding: 18px !important;
  }

  .container {
    width: calc(100vw - 16px) !important;
    margin-top: 14px !important;
    padding: 14px !important;
  }

  .container-row {
    grid-template-columns: 1fr 44px !important;
  }

  .container-row input:first-child,
  .container-row input[name="license_no[]"] {
    grid-column: 1 / -1;
  }

  .container-row input[name="container_no[]"] {
    grid-column: 1;
    grid-row: auto;
  }

  .container-row .add-btn,
  .container-row .remove-btn {
    grid-column: 2;
  }

  .phone-row,
  .signature-row {
    grid-template-columns: 24px minmax(0, 1fr) !important;
  }

  .form-group[style*="display: flex"],
  .form-group[style*="display:flex"] {
    display: grid !important;
    grid-template-columns: 1fr !important;
  }

  .phone-row .link-button,
  .signature-row .link-button,
  .phone-row button,
  .signature-row button {
    grid-column: 2;
    justify-self: start;
  }

  .action-card {
    min-height: 0 !important;
  }

  .action-title,
  .action-card.detain .action-title {
    font-size: 24px !important;
  }

  .button-group form,
  .action-group a,
  .action-group button,
  #action-button-group button,
  .mirror-actions button {
    width: 100% !important;
  }

  .pdf-preview,
  .modal-iframe {
    height: 60vh !important;
    min-height: 300px !important;
  }

  .noti-dropdown-content {
    position: fixed !important;
    width: auto !important;
    max-width: none !important;
  }
}

@media (hover: none) and (pointer: coarse) {
  button,
  .navbar-links > a,
  .navbar-right a,
  .header a,
  .link-button,
  .ghost-button,
  .pagination a,
  .notif-item-wrap,
  input,
  select,
  textarea {
    min-height: 44px;
  }

  .action-card:hover {
    transform: none;
  }
}

/* Phone table mode: no sideways scrolling for main document lists. */
@media (max-width: 720px) {
  .container:has(.mobile-card-table),
  .table-box:has(.mobile-card-table) {
    overflow-x: hidden !important;
  }

  table.mobile-card-table {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    background: transparent !important;
  }

  table.mobile-card-table thead,
  table.mobile-card-table .mobile-table-head {
    display: none !important;
  }

  table.mobile-card-table tbody {
    display: grid !important;
    gap: 12px;
    width: 100% !important;
  }

  table.mobile-card-table tr {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 12px !important;
    border: 1px solid var(--app-line);
    border-radius: var(--app-radius);
    background: #fff;
    box-shadow: var(--app-shadow-sm);
  }

  table.mobile-card-table tr.expand-row {
    display: none !important;
    margin-top: -8px !important;
    border-top: 0;
    background: #f6f9fc;
    box-shadow: none;
  }

  table.mobile-card-table tr.expand-row.is-open {
    display: block !important;
  }

  table.mobile-card-table tr.empty-row {
    box-shadow: none;
  }

  table.mobile-card-table td {
    display: grid !important;
    grid-template-columns: minmax(96px, 35%) minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    width: 100% !important;
    min-height: 42px;
    padding: 9px 0 !important;
    border: 0 !important;
    border-bottom: 1px solid #eef2f6 !important;
    color: var(--app-ink);
    text-align: left !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  table.mobile-card-table td:last-child {
    border-bottom: 0 !important;
  }

  table.mobile-card-table td::before {
    content: attr(data-label);
    color: var(--app-muted);
    font-size: 13px;
    font-weight: 900;
    line-height: 1.25;
  }

  table.mobile-card-table td[colspan] {
    display: block !important;
    padding: 0 !important;
  }

  table.mobile-card-table td[colspan]::before,
  table.mobile-card-table td:not([data-label])::before {
    display: none !important;
  }

  table.mobile-card-table td[data-label="เลือก"] {
    grid-template-columns: 1fr auto;
  }

  table.mobile-card-table td[data-label="เพิ่มเติม"],
  table.mobile-card-table td[data-label="Notes"] {
    grid-template-columns: 1fr;
  }

  table.mobile-card-table td[data-label="เพิ่มเติม"]::before,
  table.mobile-card-table td[data-label="Notes"]::before {
    margin-bottom: 2px;
  }

  table.mobile-card-table input[type="text"],
  table.mobile-card-table input[type="datetime-local"],
  table.mobile-card-table input[type="date"],
  table.mobile-card-table select,
  table.mobile-card-table textarea {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    font-size: 15px !important;
  }

  table.mobile-card-table input[type="checkbox"] {
    width: 28px !important;
    height: 28px !important;
    justify-self: end;
  }

  table.mobile-card-table .btn-details,
  table.mobile-card-table button {
    width: 100% !important;
  }

  table.mobile-card-table .expand-box {
    padding: 12px !important;
    border: 1px solid #dce5ee;
    border-radius: var(--app-radius);
    background: #fff;
  }

  table.mobile-card-table .expand-box p {
    margin: 8px 0;
    overflow-wrap: anywhere;
  }

  .withdraw-mobile-table + #action-button-group,
  #release_form #action-button-group {
    position: sticky;
    bottom: 0;
    z-index: 20;
    margin: 14px -14px -14px !important;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom)) !important;
    border-top: 1px solid var(--app-line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }
}
