@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg: #f4f7f6;
  --panel: #ffffff;
  --soft: #eef5f1;
  --line: #dfe8e3;
  --text: #14211c;
  --muted: #6c7a73;
  --gold: #caa565;
  --ink: #1f2f2a;
  --green: #10a66f;
  --red: #e05252;
  --blue: #3867d6;
  --violet: #7456b7;
  --shadow: 0 18px 45px rgba(31, 47, 42, 0.09);
  --sidebar-width: 276px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Prompt, Arial, sans-serif;
  background: linear-gradient(135deg, #f8faf7 0, #edf4f1 52%, #f7f1e5 100%);
  color: var(--text);
}

a {
  text-decoration: none;
  color: inherit;
}

.layout {
  display: flex;
  min-height: 100dvh;
}

/* =========================
   SIDEBAR
========================= */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  height: 100dvh;
  max-height: 100dvh;
  z-index: 1000;
  padding: 14px;
  color: #ffffff;
  background:
    radial-gradient(circle at top left, rgba(202, 165, 101, 0.28), transparent 34%),
    linear-gradient(180deg, #10231e 0%, #1f2f2a 58%, #101b18 100%);
  box-shadow: 10px 0 35px rgba(0, 0, 0, 0.22);

  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.brand {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  margin-bottom: 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.13);
}

.logo {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-weight: 900;
  color: #ffffff;
  background: linear-gradient(135deg, #18332b, #d7b26d);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.brand > div:not(.logo) {
  min-width: 0;
  flex: 1;
}

.brand h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand p {
  margin: 3px 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-close {
  display: none;
  flex-shrink: 0;
  margin-left: auto;
  border: 0;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  color: #ffffff;
  font-size: 20px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.13);
  cursor: pointer;
}

.nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  padding-bottom: 18px;

  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav::-webkit-scrollbar {
  width: 5px;
}

.nav::-webkit-scrollbar-track {
  background: transparent;
}

.nav::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.24);
}

/* รองรับเมนูแบบลิงก์เดี่ยวเดิม */
.nav > a {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 13px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  transition: 0.2s ease;
}

.nav > a:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.11);
  transform: translateX(3px);
}

.nav > a.active {
  color: #10231e;
  background: linear-gradient(135deg, #ffffff, #f4e5bf);
  font-weight: 900;
}

.nav-sep {
  flex: 0 0 auto;
  height: 1px;
  background: rgba(255, 255, 255, 0.16);
  margin: 7px 0;
}

/* รองรับเมนูแบบ Group */
.nav-group {
  flex: 0 0 auto;
  border-radius: 16px;
}

.nav-group-title {
  width: 100%;
  border: 0;
  cursor: pointer;
  padding: 10px 12px;
  border-radius: 15px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-group-title:hover {
  background: rgba(255, 255, 255, 0.14);
}

.nav-group-title b {
  transition: 0.2s ease;
}

.nav-group.open .nav-group-title b {
  transform: rotate(180deg);
}

.nav-group-links {
  display: none;
  padding: 6px 0 2px 6px;
}

.nav-group.open .nav-group-links {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-group-links a {
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 13px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  transition: 0.2s ease;
}

.nav-group-links a:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.11);
  transform: translateX(3px);
}

.nav-group-links a.active {
  color: #10231e;
  background: linear-gradient(135deg, #ffffff, #f4e5bf);
  font-weight: 900;
}

/* =========================
   MAIN LAYOUT
========================= */

.main {
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  min-height: 100dvh;
  padding: 26px;
  max-width: 1500px;
}

.mobile-appbar {
  display: none;
}

.mobile-menu-btn {
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--ink);
  color: white;
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
}

.sidebar-backdrop {
  display: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 22px;
}

.page-title span {
  display: inline-flex;
  background: #efe2c4;
  color: #6f5322;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.page-title h2 {
  font-size: 30px;
  line-height: 1.15;
  margin: 8px 0 4px;
}

.page-title p {
  margin: 0;
  color: var(--muted);
}

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

.branch-switch select {
  min-width: 220px;
}

/* =========================
   COMPONENTS เดิม
========================= */

.card {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}

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

.section-head h3 {
  margin: 0;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.stat {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff, #f6faf8);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stat b {
  display: block;
  font-size: 30px;
  margin-top: 4px;
}

.stat small {
  color: var(--muted);
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--ink);
  color: white;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  white-space: nowrap;
}

.btn.gold {
  background: linear-gradient(135deg, #9b7027, #d8b56f);
  color: #1e1608;
}

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

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

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

.btn.light {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #d7e1dc;
  background: #fff;
  border-radius: 10px;
  padding: 11px 12px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #b99250;
  box-shadow: 0 0 0 3px rgba(202, 165, 101, 0.16);
}

textarea {
  min-height: 96px;
  resize: vertical;
}

label {
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 6px;
  display: block;
}

.field {
  margin-bottom: 10px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

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

th,
td {
  padding: 12px 13px;
  border-bottom: 1px solid #edf1ef;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f0f5f2;
  color: #40524b;
  font-size: 13px;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  border-radius: 999px;
  background: #e8f0ff;
  color: #294fba;
  font-size: 12px;
  font-weight: 800;
}

.badge.green {
  background: #e6f8f0;
  color: #08734b;
}

.badge.red {
  background: #fdecec;
  color: #b73333;
}

.badge.gold {
  background: #fbf0d6;
  color: #7a5613;
}

.muted {
  color: var(--muted);
}

.text-right {
  text-align: right;
}

.nowrap {
  white-space: nowrap;
}

.danger {
  color: var(--red);
}

.success {
  color: var(--green);
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.toolbar .field {
  min-width: 180px;
  margin-bottom: 0;
}

.rx-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.rx-title {
  text-align: center;
  background: #efe2c4;
  font-weight: 800;
  padding: 10px;
}

.rx-row {
  display: grid;
  grid-template-columns: 86px 1fr 120px;
}

.rx-row > * {
  padding: 9px;
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.rx-row > *:last-child {
  border-right: 0;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.login-card {
  width: min(470px, 100%);
  padding: 34px;
}

.files {
  display: grid;
  gap: 8px;
}

.file-pill {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 9px 10px;
}

.print-only {
  display: none;
}

/* =========================
   RESPONSIVE
========================= */

@media (max-width: 1100px) {
  body {
    padding-top: 58px;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .mobile-appbar {
    display: flex;
    position: fixed;
    inset: 0 0 auto 0;
    height: 58px;
    z-index: 900;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
  }

  .mobile-appbar b {
    display: block;
    font-size: 14px;
    line-height: 1.1;
  }

  .mobile-appbar span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.1;
    margin-top: 3px;
  }

  .sidebar {
    z-index: 1001;
    width: min(84vw, 320px);
    max-width: 320px;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }

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

  .sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    border: 0;
    background: rgba(10, 20, 16, 0.46);
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .layout {
    display: block;
    min-height: 0;
  }

  .main {
    margin-left: 0;
    width: auto;
    max-width: none;
    padding: 14px;
  }

  .topbar {
    display: block;
    margin-bottom: 14px;
  }

  .top-actions {
    margin-top: 12px;
    align-items: stretch;
    display: grid;
  }

  .branch-switch select {
    min-width: 0;
  }

  .page-title h2 {
    font-size: 24px;
  }

  .page-title span,
  .page-title p {
    display: none;
  }

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

  .card {
    padding: 14px;
    margin-bottom: 12px;
  }

  .stat {
    padding: 14px;
  }

  .stat b {
    font-size: 24px;
  }

  .rx-row {
    grid-template-columns: 64px 1fr 82px;
  }

  .toolbar .field {
    min-width: 100%;
  }

  .section-head {
    display: block;
  }

  .table-wrap {
    font-size: 13px;
  }

  .btn {
    padding: 10px 12px;
  }
}

@media (min-width: 1101px) {
  .sidebar {
    transform: none !important;
  }

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

@media (max-height: 720px) {
  .sidebar {
    padding: 10px;
  }

  .brand {
    padding: 10px;
    margin-bottom: 8px;
  }

  .logo {
    width: 38px;
    height: 38px;
  }

  .nav > a,
  .nav-group-title {
    padding: 8px 10px;
    font-size: 12.5px;
  }

  .nav-group-links a {
    padding: 7px 9px;
    font-size: 12.5px;
  }
}

@media print {
  .sidebar,
  .topbar,
  .no-print {
    display: none !important;
  }

  .main {
    margin: 0 !important;
    width: 100% !important;
    padding: 0 !important;
  }

  .card {
    box-shadow: none;
    border: 0;
  }

  .print-only {
    display: block;
  }

  body {
    background: white;
  }
}