:root {
  --color-black: #111111;
  --color-white: #ffffff;
  --color-yellow: #ffc107;
  --color-yellow-dark: #d39e00;
  --color-bg: #f7f7f5;
  --color-border: #dedcd6;
  --color-text-muted: #5a5a56;
  --color-danger: #b3261e;
  --color-danger-bg: #fbe9e7;
  --color-success: #1e7e34;
  --color-success-bg: #e8f5e9;
  --color-warning-bg: #fff8e1;
  --sidebar-width: 240px;
  --topbar-height: 56px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans Thai", "Segoe UI", Tahoma, sans-serif;
  background: var(--color-bg);
  color: var(--color-black);
  font-size: 16px;
  line-height: 1.5;
}

a {
  color: inherit;
}

h1, h2, h3 {
  margin: 0 0 0.6em;
}

.app-shell {
  min-height: 100vh;
}

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-height);
  background: var(--color-black);
  color: var(--color-white);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-title {
  font-weight: 700;
  letter-spacing: 0.02em;
  flex: 1;
}

.menu-toggle {
  background: none;
  border: none;
  color: var(--color-white);
  font-size: 24px;
  line-height: 1;
  padding: 8px;
  cursor: pointer;
  display: inline-flex;
}

.topbar-user {
  font-size: 14px;
  color: var(--color-yellow);
  margin-right: 8px;
}

.btn-logout {
  background: var(--color-yellow);
  color: var(--color-black);
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-white);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  z-index: 25;
}

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

.sidebar-overlay {
  position: fixed;
  inset: var(--topbar-height) 0 0 0;
  background: rgba(17, 17, 17, 0.4);
  z-index: 20;
  display: none;
}

.sidebar-overlay.is-open {
  display: block;
}

.sidebar-nav {
  padding: 12px 0;
}

.sidebar-group-label {
  padding: 14px 18px 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.sidebar-link {
  display: block;
  padding: 12px 18px;
  text-decoration: none;
  color: var(--color-black);
  font-weight: 500;
  border-left: 4px solid transparent;
}

.sidebar-link:hover {
  background: var(--color-warning-bg);
}

.sidebar-link.is-active {
  border-left-color: var(--color-yellow);
  background: var(--color-warning-bg);
  font-weight: 700;
}

/* ---------- Content ---------- */
.content {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

@media (min-width: 900px) {
  .menu-toggle {
    display: none;
  }

  .sidebar {
    transform: translateX(0);
    position: fixed;
  }

  .sidebar-overlay {
    display: none !important;
  }

  .content {
    margin-left: var(--sidebar-width);
    padding: 24px;
  }
}

/* ---------- Cards / layout helpers ---------- */
.card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: 1fr; }

@media (min-width: 700px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

.stat-tile {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 16px;
  border-top: 4px solid var(--color-yellow);
}

.stat-tile .stat-value {
  font-size: 28px;
  font-weight: 800;
}

.stat-tile .stat-label {
  color: var(--color-text-muted);
  font-size: 14px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--color-black);
  color: var(--color-white);
}

.btn-primary:hover { background: #000; }

.btn-accent {
  background: var(--color-yellow);
  color: var(--color-black);
}

.btn-accent:hover { background: var(--color-yellow-dark); }

.btn-outline {
  background: var(--color-white);
  color: var(--color-black);
  border-color: var(--color-border);
}

.btn-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 14px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

/* ---------- Forms ---------- */
label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 14px;
}

.form-group {
  margin-bottom: 14px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 16px;
  background: var(--color-white);
  color: var(--color-black);
}

textarea {
  min-height: 80px;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--color-yellow);
  outline-offset: 1px;
}

.field-error {
  color: var(--color-danger);
  font-size: 13px;
  margin-top: 4px;
}

.field-hint {
  color: var(--color-text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-row input {
  width: auto;
  min-height: auto;
}

/* ---------- Alerts ---------- */
.alert {
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-weight: 600;
}

.alert-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid var(--color-success);
}

.alert-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}

.alert-warning {
  background: var(--color-warning-bg);
  color: #8a6100;
  border: 1px solid var(--color-yellow);
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
  background: var(--color-white);
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
  white-space: nowrap;
}

th {
  background: var(--color-black);
  color: var(--color-white);
  position: sticky;
  top: 0;
}

tbody tr:hover {
  background: var(--color-warning-bg);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-warning { background: var(--color-warning-bg); color: #8a6100; }
.badge-muted { background: #eee; color: var(--color-text-muted); }

/* ---------- Job entry rows ---------- */
.job-row {
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  position: relative;
  background: var(--color-white);
}

.job-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.job-row-title {
  font-weight: 700;
  color: var(--color-text-muted);
}

.btn-remove-row {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 600;
}

/* ---------- Auth (login) ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-black);
  padding: 16px;
}

.auth-card {
  background: var(--color-white);
  border-radius: 14px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  border-top: 6px solid var(--color-yellow);
}

.auth-title {
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 4px;
}

.auth-subtitle {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

/* ---------- Filters ---------- */
.filter-bar {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
}

.filter-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

/* ---------- Responsive card table (contacts raw-data list) ---------- */
/* On narrow screens the table collapses into a stack of cards: the header
   row is hidden, each <tr> becomes a card, and each <td> shows its column
   label (from data-label) above the value. */
@media (max-width: 720px) {
  .table-cards thead {
    display: none;
  }

  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td {
    display: block;
    width: 100%;
  }

  .table-cards {
    min-width: 0;
  }

  .table-cards tr {
    border: 1px solid var(--color-border);
    border-radius: 10px;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: var(--color-white);
  }

  .table-cards td {
    border-bottom: none;
    padding: 6px 0;
    white-space: normal;
    word-break: break-word;
    display: flex;
    justify-content: space-between;
    gap: 12px;
  }

  .table-cards td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--color-text-muted);
    flex-shrink: 0;
  }

  .table-cards td[data-label=""]::before,
  .table-cards td:not([data-label])::before {
    content: none;
  }
}

/* ---------- Text ID display: never let the browser reformat these ---------- */
.id-text {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-family: "Consolas", "SFMono-Regular", Menlo, monospace;
  font-size: 13px;
}

/* ---------- Import preview ---------- */
.preview-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.preview-stat {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.preview-stat-value {
  font-size: 22px;
  font-weight: 800;
}

.preview-stat-label {
  font-size: 12px;
  color: var(--color-text-muted);
}
