* {
  box-sizing: border-box;
}

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e6e8ee;
  --line-strong: #d7dbe7;
  --text: #1f2329;
  --muted: #646a73;
  --blue: #3370ff;
  --blue-soft: #eef4ff;
  --danger: #d84b4b;
  --shadow: 0 10px 30px rgba(31, 35, 41, 0.06);
}

body {
  margin: 0;
  font-family: "Noto Sans Thai", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.sidebar-logo {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #4f8cff, #34c4ff);
  color: #fff;
  font-weight: 700;
}

.sidebar-caption,
.section-kicker,
.sidebar-group-title,
.crumbs {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.sidebar-brand h1,
.topbar h2,
.toolbar h3,
.detail-header h3,
.login-copy h3,
.modal-head h3 {
  margin: 0;
}

.sidebar-nav {
  display: grid;
  gap: 8px;
}

.sidebar-group {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.sidebar-link {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}

.sidebar-link.active {
  color: var(--blue);
  background: var(--blue-soft);
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafbfe;
}

.sidebar-footer p,
.sidebar-footer small {
  margin: 0;
}

.workspace {
  padding: 0 0 18px;
}

.topbar {
  height: 72px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-left {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
}

.session-chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: #f2f3f5;
  color: var(--muted);
}

.login-gate,
.status-banner,
.tabs,
.panel-grid,
.table-panel,
.detail-panel {
  margin: 18px 24px 0;
}

.login-gate {
  display: grid;
  grid-template-columns: 1.2fr 420px;
  gap: 24px;
  padding: 24px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.login-form,
.detail-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
  font-size: 14px;
}

input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
}

.status-banner {
  padding: 14px 16px;
  border: 1px solid #dfe7ff;
  border-radius: 12px;
  background: linear-gradient(90deg, #f8fbff, #f4f7ff);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tabs {
  display: flex;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  padding: 0 4px 12px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
}

.tab-button.active {
  color: var(--blue);
  border-bottom: 2px solid var(--blue);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-grid {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 420px;
  gap: 16px;
}

.left-panel,
.table-panel,
.detail-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.left-panel,
.detail-panel {
  padding: 16px;
}

.table-panel {
  padding: 0;
  overflow: hidden;
}

.search-box,
.toolbar {
  padding: 16px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.toolbar-button,
.primary-button {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 9px 14px;
  cursor: pointer;
}

.primary-button,
.toolbar-button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.toolbar-button.subtle {
  background: #fff;
}

.toolbar-button.danger {
  color: var(--danger);
}

.toolbar-search {
  width: 220px;
}

.department-list {
  display: grid;
  gap: 6px;
  max-height: 760px;
  overflow: auto;
}

.department-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 10px 12px;
  cursor: pointer;
}

.department-item.selected {
  background: var(--blue-soft);
}

.department-item-name,
.department-item-meta {
  display: block;
}

.department-item-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table thead {
  background: #f7f8fa;
}

.data-table th {
  color: var(--muted);
  font-weight: 500;
}

.row-actions {
  white-space: nowrap;
}

.detail-header {
  margin-bottom: 14px;
}

.secondary-form {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.secondary-form h4 {
  margin: 0 0 12px;
}

.diagnostics-box {
  margin: 18px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #0f172a;
  color: #dbeafe;
  font-size: 12px;
  overflow: auto;
  max-height: 260px;
}

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

.full-width {
  margin-right: 24px;
}

.modal-dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  width: min(520px, calc(100vw - 24px));
}

.modal-dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

.modal-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

@media (max-width: 1320px) {
  .panel-grid {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .detail-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 960px) {
  .app-shell,
  .login-gate,
  .panel-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    height: auto;
    padding: 16px;
  }

  .topbar,
  .topbar-right {
    align-items: flex-start;
    flex-direction: column;
  }

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