@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@300;400;500;600;700&display=swap");

:root {
  --ta-brand: #465fff;
  --ta-brand-hover: #3641f5;
  --ta-bg: #f9fafb;
  --ta-surface: #ffffff;
  --ta-border: #e4e7ec;
  --ta-text: #101828;
  --ta-muted: #667085;
  --ta-muted-soft: #98a2b3;
  --ta-sidebar: #ffffff;
  --ta-sidebar-active: #eef4ff;
  --ta-shadow: 0 1px 2px rgba(16, 24, 40, .06);
}

* {
  letter-spacing: 0;
}

body {
  min-height: 100vh;
  font-family: "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--ta-bg);
  color: var(--ta-text);
  font-size: 14px;
}

body.sidebar-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

.app-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: rgba(249, 250, 251, .94);
  transition: opacity .22s ease, visibility .22s ease;
  backdrop-filter: blur(6px);
}

.app-loader img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  animation: loader-pulse 1s ease-in-out infinite;
}

.app-loader.is-hidden {
  visibility: hidden;
  opacity: 0;
}

@keyframes loader-pulse {
  0%, 100% { transform: scale(1); opacity: .72; }
  50% { transform: scale(1.08); opacity: 1; }
}

a {
  color: var(--ta-brand);
  text-decoration: none;
}

a:hover {
  color: var(--ta-brand-hover);
}

.sidebar {
  width: 290px;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1020;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--ta-border);
  background: var(--ta-sidebar);
  padding: 28px 20px;
  transition: transform .25s ease, box-shadow .25s ease;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1015;
  visibility: hidden;
  background: rgba(16, 24, 40, .42);
  opacity: 0;
  transition: opacity .22s ease, visibility .22s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px 28px;
}

.sidebar-brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.sidebar-title {
  margin: 0;
  color: #1d2939;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.35;
}

.sidebar-subtitle,
.sidebar-group {
  color: var(--ta-muted-soft);
  font-size: 12px;
}

.sidebar-group {
  margin: 18px 0 10px;
  padding: 0 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin: 2px 0;
  padding: 11px 12px;
  border-radius: 8px;
  color: #344054;
  font-weight: 500;
  transition: color .15s ease, background-color .15s ease;
}

.sidebar a:hover,
.sidebar a.active {
  background: var(--ta-sidebar-active);
  color: var(--ta-brand);
}

.sidebar-icon {
  width: 34px;
  height: 34px;
  display: inline-grid;
  flex: 0 0 34px;
  place-items: center;
  border-radius: 8px;
  background: #f2f4f7;
  color: #667085;
  font-size: 16px;
  transition: color .15s ease, background-color .15s ease;
}

.sidebar a:hover .sidebar-icon,
.sidebar a.active .sidebar-icon {
  background: #dbeafe;
  color: var(--ta-brand);
}

.btn .bi,
.btn-icon {
  margin-right: 7px;
}

.btn-sm .bi,
.btn-sm .btn-icon {
  margin-right: 5px;
}

.main {
  min-height: 100vh;
  margin-left: 290px;
}

.page-content {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .28s ease, transform .28s ease;
}

.page-ready .page-content,
.page-ready .login-panel {
  opacity: 1;
  transform: translateY(0);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1010;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--ta-border);
  background: rgba(255, 255, 255, .92);
  padding: 18px 32px;
  backdrop-filter: blur(10px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sidebar-toggle {
  width: 42px;
  height: 42px;
  display: none;
  place-items: center;
  border: 1px solid var(--ta-border);
  border-radius: 8px;
  background: #fff;
  color: #344054;
  font-size: 20px;
}

.page-title {
  margin: 0;
  color: var(--ta-text);
  font-size: 20px;
  font-weight: 700;
}

.page-subtitle {
  margin: 3px 0 0;
  color: var(--ta-muted);
  font-size: 13px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-pill > div:first-child {
  min-width: 0;
}

.user-avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #f2f4f7;
  color: #344054;
  font-weight: 700;
}

.content {
  padding: 30px;
}

.card,
.modal-content {
  border: 1px solid var(--ta-border);
  border-radius: 8px;
  box-shadow: var(--ta-shadow);
}

.card {
  background: var(--ta-surface);
}

.card-header {
  border-bottom-color: var(--ta-border);
  background: var(--ta-surface) !important;
}

.metric {
  margin-top: 8px;
  color: var(--ta-text);
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
}

.table {
  color: #344054;
  vertical-align: middle;
}

.table thead th {
  border-bottom: 1px solid var(--ta-border);
  background: #f9fafb;
  color: #667085;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.table > :not(caption) > * > * {
  padding: 14px 18px;
  border-bottom-color: var(--ta-border);
}

.form-label {
  color: #344054;
  font-weight: 500;
}

.form-control,
.form-select {
  min-height: 44px;
  border-color: #d0d5dd;
  border-radius: 8px;
  color: #344054;
  font-size: 14px;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--ta-brand);
  box-shadow: 0 0 0 4px rgba(70, 95, 255, .12);
}

.btn {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 600;
}

.btn-primary {
  border-color: var(--ta-brand);
  background: var(--ta-brand);
}

.btn-primary:hover,
.btn-primary:focus {
  border-color: var(--ta-brand-hover);
  background: var(--ta-brand-hover);
}

.badge {
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 600;
}

.alert {
  border-radius: 8px;
}

.contact-section {
  border: 1px solid var(--ta-border);
  border-radius: 8px;
  background: #f9fafb;
  padding: 18px;
}

.contact-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.contact-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  border: 1px solid var(--ta-border);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.contact-icon {
  width: 40px;
  height: 40px;
  display: grid;
  flex: 0 0 40px;
  place-items: center;
  border-radius: 8px;
  background: #eef4ff;
  color: var(--ta-brand);
  font-size: 18px;
}

.contact-card small {
  display: block;
  color: var(--ta-muted);
  font-size: 12px;
}

.contact-card strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--ta-text);
  font-weight: 600;
}

.status-panel .badge {
  vertical-align: middle;
}

.login-wrap,
.login-page {
  min-height: 100vh;
}

.login-wrap {
  display: grid;
  place-items: center;
  background: var(--ta-bg);
  padding: 24px;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 32px 18px;
  background:
    radial-gradient(circle at 18% 18%, rgba(70, 95, 255, .14), transparent 28%),
    radial-gradient(circle at 78% 10%, rgba(6, 182, 212, .12), transparent 24%),
    linear-gradient(135deg, #f8fafc 0%, #eef4ff 100%);
}

.login-panel {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(380px, .95fr);
  align-items: center;
  gap: 34px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .28s ease, transform .28s ease;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 30px;
}

.login-brand h1 {
  margin: 0;
  color: #101828;
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 700;
  line-height: 1.2;
}

.login-kicker {
  margin: 0 0 10px;
  color: var(--ta-brand);
  font-size: 15px;
  font-weight: 700;
}

.login-org {
  margin: 12px 0 0;
  color: #475467;
  font-size: 18px;
  font-weight: 500;
}

.login-logo-shell {
  width: 108px;
  height: 108px;
  display: grid;
  flex: 0 0 108px;
  place-items: center;
  border: 1px solid rgba(70, 95, 255, .16);
  border-radius: 24px;
  background: rgba(255, 255, 255, .86);
  box-shadow: 0 20px 40px rgba(16, 24, 40, .08);
}

.login-card {
  width: min(460px, 100%);
  padding: 32px;
  justify-self: end;
  border: 1px solid rgba(228, 231, 236, .9);
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 24px 60px rgba(16, 24, 40, .12);
  backdrop-filter: blur(12px);
}

.login-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
}

.input-icon {
  position: relative;
}

.input-icon .bi {
  position: absolute;
  left: 14px;
  top: 50%;
  z-index: 2;
  color: #98a2b3;
  transform: translateY(-50%);
}

.input-icon .form-control {
  padding-left: 42px;
}

.login-help {
  grid-column: 1 / -1;
  color: #475467;
  text-align: center;
  font-size: 14px;
}

@media (max-width: 991px) {
  .sidebar {
    width: min(290px, 86vw);
    transform: translateX(-100%);
    box-shadow: 0 24px 64px rgba(16, 24, 40, .18);
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-open .sidebar-backdrop {
    visibility: visible;
    opacity: 1;
  }

  .main {
    margin-left: 0;
  }

  .topbar {
    position: sticky;
    min-height: 72px;
    padding: 16px 20px;
  }

  .topbar-left,
  .topbar-left > div:last-child {
    min-width: 0;
  }

  .sidebar-toggle {
    display: grid;
    flex: 0 0 42px;
  }

  .content {
    padding: 18px;
  }

  .login-panel {
    grid-template-columns: 1fr;
  }

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

  .login-brand {
    justify-content: center;
    padding: 10px 0 0;
    text-align: left;
  }

  .login-card {
    justify-self: center;
  }
}

@media (max-width: 575px) {
  .topbar {
    align-items: stretch;
    gap: 12px;
    padding: 14px 16px;
  }

  .topbar-left {
    width: 100%;
  }

  .page-title {
    max-width: calc(100vw - 110px);
    overflow: hidden;
    font-size: 19px;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-subtitle {
    max-width: calc(100vw - 110px);
    overflow: hidden;
    font-size: 12px;
    line-height: 1.45;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .user-pill {
    width: 100%;
    justify-content: space-between;
    border: 1px solid var(--ta-border);
    border-radius: 8px;
    background: #f9fafb;
    padding: 10px 12px;
    text-align: left !important;
  }

  .user-pill .fw-semibold,
  .user-pill .text-muted {
    display: block;
    max-width: calc(100vw - 112px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .user-avatar {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
  }

  .sidebar-toggle {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .login-card {
    padding: 24px;
  }

  .login-brand {
    flex-direction: column;
    text-align: center;
  }

  .login-logo-shell {
    width: 92px;
    height: 92px;
    flex-basis: 92px;
  }

  .login-logo {
    width: 62px;
    height: 62px;
  }
}
