:root {
  --bg: #f2f5fb;
  --surface: #ffffff;
  --text: #12233a;
  --muted: #5f6e83;
  --primary: #0e4cad;
  --primary-strong: #0a3f90;
  --danger: #b3261e;
  --success: #1f7a35;
  --warning: #f59e0b;
  --border: #d8dfeb;
  --shadow: 0 10px 24px rgba(17, 32, 61, 0.08);
  --shadow-lg: 0 20px 40px rgba(17, 32, 61, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #eef3fc 0%, #f8fafd 100%);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.app-sidebar {
  background: linear-gradient(180deg, #0f1e36 0%, #1a2d4d 100%);
  color: #d6e2ff;
  padding: 24px 16px;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
}

.brand {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  background: linear-gradient(135deg, #fff 0%, #a5c7ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-role {
  font-size: 12px;
  color: #9fb6e5;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.menu {
  display: grid;
  gap: 6px;
}

.menu-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: #d6e2ff;
  text-decoration: none;
  font-weight: 600;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.08);
  text-decoration: none;
}

.menu-item.is-active {
  background: #1e3f75;
  color: #fff;
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.app-topbar h1 {
  margin: 0;
  font-size: 22px;
}

.top-meta {
  color: var(--muted);
  font-size: 13px;
}

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

a:hover {
  text-decoration: underline;
}

.link-light {
  color: #fff;
}

.mt-10 {
  margin-top: 10px;
}

.max-w-180 {
  max-width: 180px;
}

.max-w-220 {
  max-width: 220px;
}

.max-w-260 {
  max-width: 260px;
}

.max-w-280 {
  max-width: 280px;
}

.max-w-860 {
  max-width: 860px;
}

.center {
  margin: 0 auto;
}

.page-shell {
  max-width: 1220px;
  margin: 24px auto;
  padding: 0 16px;
}

.topbar {
  background: #132542;
  color: #fff;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar-agent {
  background: #174a2a;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.card + .card,
.stack > .card {
  margin-top: 14px;
}

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

h1,
h2,
h3 {
  margin: 0 0 10px;
}

p {
  margin: 6px 0;
}

.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.row-between {
  justify-content: space-between;
  align-items: flex-start;
}

.form-stack > * {
  margin-top: 8px;
}

.form-stack > *:first-child {
  margin-top: 0;
}

input,
select,
button {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font: inherit;
}

input,
select {
  background: #fff;
  width: 100%;
}

button {
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
}

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

.flash-success,
.flash-error {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 600;
}

.flash-success {
  background: #eaf7ee;
  color: var(--success);
  border: 1px solid #c5e8cf;
}

.flash-error {
  background: #fdebea;
  color: var(--danger);
  border: 1px solid #f6c8c5;
}

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

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

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid #e6ecf6;
  text-align: left;
  white-space: nowrap;
  font-size: 14px;
}

th {
  color: #2a3d5d;
  background: #f7f9fe;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.actions {
  margin-top: 12px;
}

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-card {
  width: min(420px, 100%);
}

.inline-note {
  font-size: 12px;
  color: var(--muted);
}

.stat-card {
  text-align: center;
  padding: 24px 16px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  margin: 8px 0;
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.lottery-box {
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.lottery-box.thai {
  background: #fef3c7;
  border: 1px solid #fbbf24;
}

.lottery-box.lao {
  background: #dbeafe;
  border: 1px solid #2563eb;
}

.lottery-box-title {
  font-weight: 700;
  font-size: 18px;
  color: #1f2937;
}

.lottery-box-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.lottery-stat-card {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.lottery-stat-card .stat-label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.lottery-stat-card .stat-value {
  font-size: 28px;
  margin-top: 0;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success {
  background: #eaf7ee;
  color: var(--success);
}

.badge-danger {
  background: #fdebea;
  color: var(--danger);
}

.badge-warning {
  background: #fef3e2;
  color: var(--warning);
}

.badge-info {
  background: #e3f2fd;
  color: #0277bd;
}

.btn-secondary {
  background: #6c757d;
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  display: inline-block;
}

.btn-secondary:hover {
  background: #5a6268;
  text-decoration: none;
}

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

.btn-danger:hover {
  background: #9a1f17;
}

.page-content {
  padding: 24px;
  max-width: 1400px;
}

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

.section-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

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

.credit-display {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  color: #fff;
  padding: 16px 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.credit-label {
  font-size: 13px;
  opacity: 0.9;
  margin-bottom: 4px;
}

.credit-value {
  font-size: 28px;
  font-weight: 700;
}

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.status-open {
  color: var(--success);
  font-weight: 600;
}

.status-closed {
  color: var(--danger);
  font-weight: 600;
}

@media (max-width: 700px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    padding: 12px;
  }

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

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  
  .page-content {
    padding: 16px;
  }
}
