:root {
  color-scheme: light;
  font-family:
    Inter, "Noto Sans Thai", "Segoe UI", Tahoma, Arial, sans-serif;
  background: #f4f6f8;
  color: #172033;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e2e8f0;
  --text: #172033;
  --muted: #64748b;
  --primary: #111827;
  --primary-hover: #263246;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(59, 130, 246, 0.08), transparent 28rem),
    #f4f6f8;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.3rem, 2vw, 1.75rem);
}

h2 {
  margin-bottom: 0.35rem;
  font-size: clamp(1.2rem, 2vw, 1.65rem);
}

h3 {
  margin-bottom: 0.25rem;
}

.eyebrow {
  margin-bottom: 0.35rem;
  color: #64748b;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.muted {
  margin-bottom: 0;
  color: var(--muted);
}

.topbar {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 78px;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
  backdrop-filter: blur(18px);
}

.brand-area,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 1.2rem;
  background: #111827;
  color: #ffffff;
  border-radius: 16px;
  font-size: 1.4rem;
  font-weight: 850;
}

.brand-mark.small {
  width: 42px;
  height: 42px;
  margin: 0;
  border-radius: 13px;
  font-size: 1rem;
}

.section-nav {
  position: sticky;
  z-index: 25;
  top: 78px;
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  padding: 0.65rem clamp(1rem, 4vw, 3rem);
  background: rgba(244, 246, 248, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.nav-button {
  padding: 0.62rem 0.9rem;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 10px;
  font-weight: 750;
  white-space: nowrap;
}

.nav-button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.07);
}

.page-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 4rem;
}

.app-section {
  display: none;
}

.app-section.active {
  display: block;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.summary-card,
.panel {
  background: var(--surface);
  border: 1px solid rgba(226, 232, 240, 0.85);
  box-shadow: var(--shadow);
}

.summary-card {
  min-height: 145px;
  padding: 1.2rem;
  border-radius: 18px;
}

.summary-card p {
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.summary-card strong {
  display: block;
  margin-bottom: 0.4rem;
  font-size: clamp(1.35rem, 2.8vw, 1.9rem);
}

.summary-card span {
  color: var(--muted);
  font-size: 0.82rem;
}

.skeleton {
  background:
    linear-gradient(
      100deg,
      #ffffff 20%,
      #f1f5f9 40%,
      #ffffff 60%
    );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  to {
    background-position-x: -200%;
  }
}

.panel {
  overflow: hidden;
  border-radius: 20px;
}

.panel-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.page-message {
  min-height: 0;
  margin-bottom: 0;
  padding: 0 1rem;
  color: #075985;
  font-size: 0.9rem;
}

.page-message:not(:empty) {
  margin-bottom: 1rem;
  padding: 0.8rem 1rem;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 12px;
}

.page-message[data-kind="error"]:not(:empty) {
  background: #fef3f2;
  color: var(--danger);
  border-color: #fecdca;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
}

td {
  font-size: 0.92rem;
}

td strong,
td small {
  display: block;
}

td small {
  margin-top: 0.15rem;
  color: var(--muted);
}

.note-cell {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  display: inline-flex;
  align-items: center;
  min-width: 92px;
  justify-content: center;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.status-vacant,
.status-active {
  background: #ecfdf3;
  color: #027a48;
}

.status-occupied {
  background: #eff8ff;
  color: #175cd3;
}

.status-personal {
  background: #f4f3ff;
  color: #5925dc;
}

.status-maintenance {
  background: #fff7ed;
  color: #c2410c;
}

.status-inactive,
.status-ended,
.status-cancelled {
  background: #f2f4f7;
  color: #475467;
}

.primary-button,
.secondary-button,
.table-button,
.icon-button {
  border: 0;
  border-radius: 11px;
  transition:
    transform 120ms ease,
    background 120ms ease;
}

.primary-button {
  padding: 0.78rem 1rem;
  background: var(--primary);
  color: #ffffff;
  font-weight: 750;
}

.primary-button:hover {
  background: var(--primary-hover);
}

.secondary-button {
  padding: 0.7rem 0.9rem;
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 700;
}

.secondary-button:hover,
.table-button:hover {
  background: #f8fafc;
}

.table-button {
  padding: 0.48rem 0.7rem;
  background: #ffffff;
  color: #334155;
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 700;
}

.danger-button {
  color: var(--danger);
  border-color: #fecdca;
}

.icon-button {
  width: 40px;
  height: 40px;
  background: transparent;
  color: #475569;
  font-size: 1.8rem;
  line-height: 1;
}

.empty-state {
  height: 160px;
  color: var(--muted);
  text-align: center;
}

.empty-state.compact {
  display: grid;
  place-items: center;
  height: 110px;
}

.card-list {
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
}

.contract-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.contract-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.contract-card > strong {
  white-space: nowrap;
}

.room-badge {
  display: inline-flex;
  margin-bottom: 0.45rem;
  padding: 0.25rem 0.55rem;
  background: #eff8ff;
  color: #175cd3;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 750;
}

dialog {
  width: min(700px, calc(100% - 2rem));
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 0;
  border: 0;
  border-radius: 20px;
  box-shadow: 0 30px 100px rgba(15, 23, 42, 0.25);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}

dialog form {
  padding: 1.4rem;
}

.dialog-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  padding: 1.25rem 0;
}

.form-grid label,
.login-form label {
  display: grid;
  gap: 0.45rem;
  color: #334155;
  font-size: 0.88rem;
  font-weight: 700;
}

.full-width {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.78rem 0.82rem;
  background: #ffffff;
  color: var(--text);
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #64748b;
  box-shadow: 0 0 0 3px rgba(100, 116, 139, 0.15);
}

textarea {
  resize: vertical;
}

.dialog-actions {
  display: flex;
  justify-content: end;
  gap: 0.7rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.form-error {
  min-height: 1.3rem;
  margin: 0;
  color: var(--danger);
  font-size: 0.86rem;
}

.form-help {
  margin: -0.25rem 0 1rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-card {
  width: min(430px, 100%);
  padding: clamp(1.5rem, 5vw, 2.4rem);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 24px;
  box-shadow: 0 30px 90px rgba(15, 23, 42, 0.13);
}

.login-card h1 {
  margin-bottom: 0.4rem;
  font-size: 2rem;
}

.login-form {
  display: grid;
  gap: 1rem;
  margin-top: 1.6rem;
}

.login-form .primary-button {
  margin-top: 0.25rem;
}

@media (max-width: 900px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .page-shell {
    width: min(100% - 1rem, 1180px);
    padding-top: 1rem;
  }

  .topbar {
    position: static;
    align-items: stretch;
    min-height: 68px;
    padding: 0.8rem;
  }

  .topbar,
  .hero,
  .panel-header {
    flex-direction: column;
  }

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

  .section-nav {
    top: 0;
  }

  .summary-grid {
    grid-template-columns: 1fr;
    gap: 0.7rem;
  }

  .summary-card {
    min-height: 120px;
  }

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

  .full-width {
    grid-column: auto;
  }

  dialog form {
    padding: 1rem;
  }

  .contract-card {
    align-items: flex-start;
    flex-direction: column;
  }
}
