:root {
  --navy: #11285e;
  --blue: #0c43c7;
  --blue-2: #135de3;
  --blue-soft: #eef4ff;
  --pink: #f53886;
  --pink-soft: #fff0f6;
  --green: #18a65b;
  --green-soft: #ecfbf3;
  --orange: #ef8c22;
  --red: #d92d20;
  --border: #dce4f0;
  --muted: #6f7d99;
  --text: #14264e;
  --background: #f4f7fb;
  --card: #ffffff;
  --shadow: 0 12px 35px rgba(24, 49, 93, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", "Noto Sans", "Noto Sans JP", sans-serif;
  color: var(--text);
  background: var(--background);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
}
button,
input,
select,
textarea {
  font: inherit;
}
button {
  cursor: pointer;
}
input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea {
  min-height: 86px;
  resize: vertical;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue-2);
  box-shadow: 0 0 0 3px rgba(19, 93, 227, 0.12);
}
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.08);
}
input.date-input,
input.flatpickr-input[readonly] {
  cursor: pointer;
}
/* Keep the calendar's month/year controls independent from the app's form-control sizing. */
.flatpickr-calendar input,
.flatpickr-calendar select {
  width: auto;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
/* iOS can collapse Flatpickr's built-in year input to its spinner. */
.flatpickr-current-month {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25ch;
  white-space: nowrap;
}
.flatpickr-current-month .flatpickr-monthDropdown-months {
  flex: 0 1 auto;
  width: auto;
  max-width: calc(100% - 5.5ch);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.flatpickr-current-month .numInputWrapper {
  display: inline-block;
  flex: 0 0 4.5ch;
  width: 4.5ch;
  min-width: 4.5ch;
}
.flatpickr-current-month input.cur-year {
  display: inline-block;
  width: 4.5ch;
  min-width: 4.5ch;
  padding: 0;
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  opacity: 1;
  text-align: center;
}
.flatpickr-calendar {
  z-index: 1000;
}
h1,
h2,
p {
  margin-top: 0;
}
.required {
  color: var(--red);
}
.button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 44px;
  padding: 10px 20px;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.button-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  box-shadow: 0 6px 16px rgba(12, 67, 199, 0.18);
}
.button-primary:hover {
  filter: brightness(0.96);
}
.button-primary:disabled {
  opacity: 0.55;
  cursor: wait;
}
.button-secondary {
  color: var(--text);
  background: #fff;
  border-color: var(--border);
}
#export-button {
  color: #fff;
  background: #1d6f42;
  border-color: #1d6f42;
  transition: opacity 0.15s ease;
}
#dashboard-export-button {
  color: #fff;
  background: #1d6f42;
  border-color: #1d6f42;
  transition: opacity 0.15s ease;
}
#reset-filters,
#dashboard-reset-filters {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: #bfd1f6;
  transition: opacity 0.15s ease, background-color 0.15s ease,
    border-color 0.15s ease, color 0.15s ease;
}
#reset-filters:hover,
#dashboard-reset-filters:hover {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
  opacity: 0.8;
}
#export-button:hover {
  opacity: 0.8;
}
#dashboard-export-button:hover {
  opacity: 0.8;
}
.button-danger {
  color: #fff;
  background: var(--red);
}
.button-full {
  width: 100%;
}
.icon-button {
  border: 0;
  background: transparent;
  font-size: 28px;
  color: var(--muted);
}
.global-error {
  color: #9d1c13;
  background: #fff1f0;
  border: 1px solid #f5b9b4;
  border-radius: 8px;
  padding: 12px;
}
.field-error {
  color: var(--red);
  font-size: 12px;
  min-height: 17px;
  margin-top: 4px;
}

/* Public */
.public-page {
  padding: 18px;
}
.public-container {
  max-width: 1120px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid rgba(220, 228, 240, 0.8);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.public-heading {
  text-align: center;
  margin-bottom: 22px;
}
.public-heading h1 {
  font-size: clamp(26px, 3vw, 36px);
  margin-bottom: 7px;
}
.public-heading p {
  color: var(--muted);
  margin-bottom: 0;
}
.application-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.application-tabs button {
  min-height: 52px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 700;
  color: var(--text);
}
.application-tabs button[data-color="blue"].active {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}
.application-tabs button[data-color="pink"].active {
  color: #fff;
  background: var(--pink);
  border-color: var(--pink);
}
.application-tabs button[data-color="green"].active {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}
.form-sections {
  display: grid;
  gap: 12px;
}
.form-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 18px;
}
.form-card h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 18px;
  color: var(--blue);
  margin-bottom: 16px;
}
.form-card h2::before {
  content: "";
  width: 8px;
  height: 8px;
  background: currentColor;
  border-radius: 50%;
  box-shadow: 0 0 0 5px var(--blue-soft);
}
.field-row {
  display: block;
  margin-bottom: 14px;
}
.field-row[hidden] {
  display: none !important;
}
.field-row > label,
.field-row > span:first-child {
  display: block;
  font-size: 13px;
  font-weight: 680;
  margin-bottom: 6px;
}
.field-helper {
  color: var(--muted);
  font-size: 12px;
  margin: 5px 0 0;
}
.notice-card {
  margin-top: 12px;
  background: linear-gradient(90deg, #eef5ff, #f7fbff);
  border: 1px solid #cae0ff;
  border-radius: 10px;
  padding: 14px 18px;
  color: #16448f;
}
.notice-card p {
  margin: 5px 0 0;
  font-size: 13px;
}
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 16px;
}
.sticky-actions {
  position: sticky;
  bottom: 0;
  padding: 12px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), #fff 22%);
  z-index: 3;
}
.success-dialog,
.record-dialog {
  border: 0;
  border-radius: 14px;
  box-shadow: 0 25px 80px rgba(10, 31, 73, 0.25);
}
.success-dialog {
  width: min(430px, calc(100vw - 30px));
  text-align: center;
  padding: 30px;
}
dialog::backdrop {
  background: rgba(11, 23, 48, 0.46);
  backdrop-filter: blur(3px);
}
.success-icon {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  background: var(--green-soft);
  color: var(--green);
  border-radius: 50%;
  font-size: 32px;
  font-weight: 800;
}
.success-code {
  display: block;
  color: var(--blue);
  font-size: 22px;
  margin: 8px 0 20px;
}
.warning-text {
  color: #8a5a00;
  background: #fff8e6;
  border-radius: 8px;
  padding: 10px;
}

/* Login */
.login-page {
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at top, #edf4ff, #f7f9fc 55%);
}
.login-card {
  width: min(430px, 100%);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card form {
  text-align: left;
  margin-top: 22px;
}
.brand-mark {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), #5c8df5);
  font-weight: 800;
  font-size: 25px;
}
.brand-mark.small {
  width: 38px;
  height: 38px;
  margin: 0;
  border-radius: 10px;
  font-size: 17px;
}
.back-link {
  display: inline-block;
  margin-top: 18px;
  color: var(--blue);
  text-decoration: none;
}

/* Admin */
.admin-page {
  overflow-x: hidden;
  overflow-y: auto;
}
.admin-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: 100vh;
}
.admin-sidebar {
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  min-height: 100vh;
}
.admin-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 0 8px 20px;
}
.admin-brand strong {
  display: block;
}
.admin-brand small,
.admin-identity small {
  color: var(--muted);
  display: block;
  margin-top: 2px;
}
.admin-nav {
  display: grid;
  gap: 7px;
}
.admin-nav button {
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 12px 14px;
  color: var(--text);
}
.admin-nav button.active {
  color: var(--blue);
  background: var(--blue-soft);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--blue);
}
.sidebar-bottom {
  margin-top: auto;
  display: grid;
  gap: 8px;
}
.admin-identity {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
}
.admin-identity strong {
  max-width: 135px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
  background: var(--blue-2);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 750;
}
.sidebar-logout {
  min-height: 42px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.admin-main {
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 22px;
}
.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.admin-header h1 {
  font-size: 27px;
  margin-bottom: 5px;
}
.admin-header p {
  color: var(--muted);
  margin-bottom: 0;
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.kpi-grid.compact {
  margin-bottom: 12px;
}
.kpi-card {
  min-height: 122px;
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(24, 49, 93, 0.04);
}
.kpi-icon {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.kpi-icon svg {
  width: 27px;
  height: 27px;
}
.kpi-content {
  min-width: 0;
}
.kpi-label {
  color: var(--text);
  font-size: 14px;
}
.kpi-value {
  display: block;
  font-size: 30px;
  margin-top: 8px;
}
.kpi-total .kpi-icon {
  color: #6941c6;
  background: #f1ebff;
}
.kpi-new .kpi-icon {
  color: #159568;
  background: #e5f8f0;
}
.kpi-processing .kpi-icon {
  color: #dc7b16;
  background: #fff1df;
}
.kpi-completed .kpi-icon {
  color: #2366d1;
  background: #e8f1ff;
}
.admin-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(24, 49, 93, 0.04);
  overflow: hidden;
}
.card-heading {
  padding: 16px 18px 5px;
}
.card-heading-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-heading h2 {
  font-size: 17px;
  margin-bottom: 0;
}
.toolbar-shell {
  border-bottom: 1px solid var(--border);
}
.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
  gap: 10px;
  padding: 14px;
}
.filter-grid > * {
  min-width: 0;
}
.filter-grid .toolbar-search {
  grid-column: span 2;
}
.dashboard-filter-grid {
  grid-template-columns: minmax(180px, 1.35fr) minmax(150px, 0.9fr) repeat(
    2,
    minmax(150px, 1fr)
  ) minmax(100px, 0.55fr);
}
.dashboard-filter-grid .toolbar-search {
  grid-column: auto;
}
.list-filter-grid.is-compact {
  grid-template-columns: minmax(180px, 1.35fr) minmax(150px, 0.9fr) repeat(
    2,
    minmax(150px, 1fr)
  ) minmax(100px, 0.55fr);
}
.list-filter-grid.is-compact .toolbar-search {
  grid-column: auto;
}
.list-filter-grid.is-compact.without-status {
  grid-template-columns: minmax(180px, 1.35fr) repeat(
    2,
    minmax(150px, 1fr)
  ) minmax(100px, 0.55fr);
}
.filter-date-control {
  min-width: 0;
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}
.filter-date-control input {
  min-width: 0;
  width: 100%;
}
.filter-grid > .button {
  width: 100%;
  align-self: end;
}
.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: #fbfcff;
}
.toolbar-primary-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}
.table-scroll {
  overflow: auto;
  width: 100%;
}
.wide-table {
  max-height: calc(100vh - 330px);
}
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}
.data-table th,
.data-table td {
  min-width: 135px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  background: #fff;
  white-space: normal;
  overflow-wrap: anywhere;
}
.data-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  color: #30415f;
  background: #f8faff;
  font-weight: 750;
}
.data-table th.sticky-left,
.data-table td.sticky-left {
  position: sticky;
  left: 0;
  z-index: 4;
  min-width: 155px;
  box-shadow: 2px 0 5px rgba(15, 37, 78, 0.05);
}
.data-table th.sticky-right,
.data-table td.sticky-right {
  position: sticky;
  right: 0;
  z-index: 4;
  min-width: 125px;
  box-shadow: -2px 0 5px rgba(15, 37, 78, 0.05);
}
.data-table th.sticky-left,
.data-table th.sticky-right {
  z-index: 5;
  background: #f8faff;
}
.data-table tr:hover td {
  background: #fbfdff;
}
.dashboard-row-actionable {
  cursor: pointer;
}
.dashboard-row-actionable:focus-visible td {
  outline: 2px solid var(--blue-2);
  outline-offset: -2px;
}
.status-badge {
  display: inline-block;
  padding: 4px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.status-KPH {
  color: #1259bf;
  background: #eaf2ff;
}
.status-CHUA_VE {
  color: #8a6500;
  background: #fff7d6;
}
.status-SAP_VE {
  color: #155ebd;
  background: #e8f2ff;
}
.status-DA_VE {
  color: #16834c;
  background: #e7f8ef;
}
.status-DA_LAM_HS {
  color: #6842c2;
  background: #f0eaff;
}
.status-CHUAN_BI_HS {
  color: #a34e00;
  background: #fff0df;
}
.status-HOP_DONG_OK {
  color: #16834c;
  background: #e7f8ef;
}
.status-NEW {
  color: #1259bf;
  background: #eaf2ff;
}
.status-PROCESSING {
  color: #a34e00;
  background: #fff0df;
}
.status-MISSING_INFO {
  color: #8a6500;
  background: #fff7d6;
}
.status-SENT_JP {
  color: #6842c2;
  background: #f0eaff;
}
.status-WAIT_TRANSFER {
  color: #155ebd;
  background: #e8f2ff;
}
.status-COMPLETED {
  color: #16834c;
  background: #e7f8ef;
}
.status-CANCELLED {
  color: #9f2e25;
  background: #ffeceb;
}
.inline-cell {
  min-width: 155px;
}
.inline-editor {
  min-width: 135px;
  min-height: 36px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
}
.inline-editor:focus {
  min-width: 180px;
}
.inline-cell textarea.inline-editor {
  min-height: 54px;
  resize: vertical;
}
.inline-save-state {
  display: block;
  min-height: 16px;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}
.inline-save-state.is-saving {
  color: var(--blue);
}
.inline-save-state.is-saved {
  color: var(--green);
}
.inline-save-state.is-error,
.inline-row-error {
  color: var(--red);
}
.inline-row-error {
  display: block;
  font-size: 10px;
  max-width: 180px;
}
.action-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.action-group button {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--blue);
}
.action-group button:hover {
  background: var(--blue-soft);
}
.action-group button:focus-visible {
  outline: 2px solid var(--blue-2);
  outline-offset: 2px;
}
.action-group button.action-danger {
  color: var(--red);
}
.action-group button.action-danger:hover {
  background: #fff0ef;
}
.action-group svg {
  width: 20px;
  height: 20px;
}
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
}
.pagination-bar select {
  width: auto;
  min-height: 38px;
}
.pagination {
  display: flex;
  gap: 5px;
}
.pagination button {
  min-width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
}
.pagination button.active {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}
.record-dialog {
  width: min(820px, calc(100vw - 24px));
  max-height: 92vh;
  padding: 0;
  overflow: hidden;
}
.record-dialog form {
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.dialog-header h2 {
  margin-bottom: 3px;
}
.dialog-header p {
  color: var(--muted);
  margin-bottom: 0;
}
.record-dialog > form > .field-row {
  padding: 15px 20px 0;
  margin-bottom: 0;
}
.dialog-fields {
  padding: 15px 20px;
  overflow-y: auto;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: #fff;
}
#dialog-error {
  margin: 0 20px;
}

@media (max-width: 1000px) {
  .admin-layout {
    grid-template-columns: 190px minmax(0, 1fr);
  }
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .admin-main {
    padding: 16px;
  }
  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .filter-grid .toolbar-search {
    grid-column: 1 / -1;
  }
}
@media (max-width: 760px) {
  .public-page {
    padding: 0;
  }
  .public-container {
    border-radius: 0;
    border: 0;
    padding: 18px 14px 90px;
    min-height: 100vh;
  }
  .application-tabs {
    gap: 5px;
    position: sticky;
    top: 0;
    z-index: 6;
    background: #fff;
    padding: 6px 0;
  }
  .application-tabs button {
    padding: 8px 5px;
    font-size: 12px;
  }
  .form-card {
    padding: 14px;
  }
  .form-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 14px;
    background: #fff;
    border-top: 1px solid var(--border);
  }
  .form-actions .button {
    flex: 1;
  }
  .admin-layout {
    display: block;
  }
  .admin-sidebar {
    min-height: auto;
    padding: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .admin-brand,
  .sidebar-bottom {
    display: none;
  }
  .admin-nav {
    display: flex;
    overflow-x: auto;
  }
  .admin-nav button {
    white-space: nowrap;
  }
  .admin-main {
    height: auto;
    min-height: calc(100vh - 60px);
    overflow: visible;
    padding: 12px;
  }
  .admin-header {
    display: block;
  }
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }
  .kpi-card {
    min-height: 100px;
    padding: 14px;
  }
  .kpi-icon {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }
  .kpi-icon svg {
    width: 24px;
    height: 24px;
  }
  .kpi-value {
    font-size: 24px;
  }
  .filter-grid {
    grid-template-columns: 1fr;
  }
  .filter-grid .toolbar-search {
    grid-column: auto;
  }
  .toolbar-actions {
    align-items: stretch;
  }
  .toolbar-primary-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    margin-left: 0;
  }
  .wide-table {
    max-height: none;
  }
  .pagination-bar {
    flex-wrap: wrap;
  }
}
@media (max-width: 430px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .public-heading h1 {
    font-size: 26px;
  }
  .toolbar-primary-actions {
    grid-template-columns: 1fr;
  }
}
