/* ==========================================================================
   CSMCUT Back-Office CMS Stylesheet
   Modern Minimalist Emerald Green — Responsive for Desktop, Tablet & Mobile
   ========================================================================== */

:root {
  --bg-canvas: #f3f7f4;
  --bg-surface: #ffffff;
  --bg-subtle: #f7faf8;
  --green-950: #071d14;
  --green-900: #0f3325;
  --green-800: #184d38;
  --green-700: #21684b;
  --green-600: #2e855a;
  --green-100: #e5f3ec;
  --green-50: #eff7f3;

  --gold-600: #a67e33;
  --gold-500: #cca352;
  --gold-100: #fcf5e6;

  --amber-700: #b45309;
  --amber-100: #fef3c7;
  --red-600: #dc2626;
  --red-100: #fee2e2;
  --blue-700: #1d4ed8;
  --blue-100: #dbeafe;

  --text-main: #10261d;
  --text-sub: #4a6156;
  --text-muted: #768b81;
  --border-light: #dfe9e3;
  --border-strong: #c7d9ce;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;
  --shadow-xs: 0 2px 6px rgba(15, 51, 37, 0.04);
  --shadow-sm: 0 8px 24px rgba(15, 51, 37, 0.07);
  --shadow-lg: 0 24px 56px rgba(7, 29, 20, 0.18);
  --sidebar-w: 272px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Anuphan', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--bg-canvas);
  color: var(--text-main);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

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

/* ==========================================================================
   Login Screen
   ========================================================================== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 80% 15%, rgba(46, 133, 90, 0.12), transparent 45%),
              linear-gradient(160deg, #0f3325 0%, #154231 50%, #0b261b 100%);
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border-radius: 22px;
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 28px;
}

.login-brand img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  padding: 3px;
  border: 1.5px solid var(--border-strong);
  margin-bottom: 12px;
}

.login-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--green-900);
}

.login-brand p {
  font-size: 0.86rem;
  color: var(--text-sub);
  margin-top: 2px;
}

/* ==========================================================================
   App Shell (Sidebar + Main Workspace)
   ========================================================================== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background-color: var(--green-950);
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 60;
  transition: transform 0.28s ease;
}

.sidebar__brand {
  padding: 22px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar__brand img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #fff;
  padding: 2px;
  flex-shrink: 0;
}

.sidebar__brand-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.25;
}

.sidebar__brand-sub {
  font-size: 0.74rem;
  color: rgba(255, 255, 255, 0.6);
}

.sidebar__user {
  margin: 14px 16px 8px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar__user-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
}

.sidebar__user-role {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(204, 163, 82, 0.22);
  color: #f3d592;
}

.sidebar__nav {
  flex: 1;
  padding: 10px 12px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar__link {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.75);
  text-align: left;
  transition: all 0.2s;
}

.sidebar__link-left {
  display: flex;
  align-items: center;
  gap: 11px;
}

.sidebar__link:hover {
  background-color: rgba(255, 255, 255, 0.07);
  color: #fff;
}

.sidebar__link.is-active {
  background-color: var(--green-700);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.nav-counter {
  background-color: #ef4444;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
}

.sidebar__footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 29, 20, 0.52);
  z-index: 55;
}

/* Main Content Area */
.workspace {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: 70px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  align-items: center;
  justify-content: center;
  color: var(--green-900);
}

.topbar__title {
  font-size: 1.18rem;
  font-weight: 700;
  color: var(--green-900);
}

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

.content-area {
  padding: 28px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.view-pane {
  display: none;
}

.view-pane.is-active {
  display: block;
}

/* ==========================================================================
   Reusable Cards, Buttons, Badges & Forms
   ========================================================================== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-xs);
  margin-bottom: 22px;
}

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

.card__title {
  font-size: 1.06rem;
  font-weight: 700;
  color: var(--green-900);
}

.card__sub {
  font-size: 0.86rem;
  color: var(--text-sub);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  box-shadow: var(--shadow-xs);
}

.kpi-card__label {
  font-size: 0.82rem;
  color: var(--text-sub);
  margin-bottom: 6px;
}

.kpi-card__value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--green-900);
  line-height: 1.2;
}

.kpi-card__hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn--primary {
  background: var(--green-800);
  color: #fff;
  border: 1px solid var(--green-800);
}

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

.btn--outline {
  background: #fff;
  color: var(--green-900);
  border: 1px solid var(--border-strong);
}

.btn--outline:hover {
  background: var(--green-50);
  border-color: var(--green-700);
}

.btn--danger {
  background: var(--red-100);
  color: var(--red-600);
  border: 1px solid #fecaca;
}

.btn--danger:hover {
  background: #fecaca;
}

.btn--xs {
  padding: 6px 12px;
  font-size: 0.78rem;
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge--active {
  background: var(--green-100);
  color: var(--green-800);
}

.badge--warning {
  background: var(--amber-100);
  color: var(--amber-700);
}

.badge--expired {
  background: #f1f5f9;
  color: #64748b;
}

.badge--scheduled {
  background: var(--blue-100);
  color: var(--blue-700);
}

.badge--popup {
  background: var(--gold-100);
  color: var(--gold-600);
  border: 1px solid #ebd7a7;
}

/* Filter Pills & Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.pill-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill-btn {
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  font-size: 0.83rem;
  font-weight: 500;
  background: var(--bg-subtle);
  color: var(--text-sub);
  border: 1px solid var(--border-light);
}

.pill-btn.is-active {
  background: var(--green-800);
  color: #fff;
  border-color: var(--green-800);
}

/* Tables / Responsive Item Cards */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  text-align: left;
  padding: 12px 14px;
  background: var(--bg-subtle);
  color: var(--text-sub);
  font-weight: 600;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

.data-table td {
  padding: 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background-color: #fafcfb;
}

.thumb-sm {
  width: 68px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--green-50);
  border: 1px solid var(--border-light);
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Forms */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--green-900);
}

.field-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #fff;
  font-size: 0.92rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus {
  outline: none;
  border-color: var(--green-700);
  box-shadow: 0 0 0 3px rgba(33, 104, 75, 0.1);
}

.input-pwd-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-pwd-wrap .input {
  padding-right: 44px;
}

.pwd-toggle-btn {
  position: absolute;
  right: 6px;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: color 0.2s, background-color 0.2s;
}

.pwd-toggle-btn:hover {
  color: var(--green-800);
  background-color: var(--green-50);
}

/* Custom Thai Calendar Date Input & Popover (วว/ดด/ปปปป พ.ศ.) */
.thai-date-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.thai-date-wrap .thai-date-display {
  padding-right: 42px;
  cursor: pointer;
}

.thai-date-btn {
  position: absolute;
  right: 6px;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--green-800);
  transition: color 0.2s, background-color 0.2s;
}

.thai-date-btn:hover {
  background-color: var(--green-50);
  color: var(--green-900);
}

.thai-cal {
  position: fixed;
  z-index: 280;
  width: 296px;
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 18px 42px rgba(7, 29, 20, 0.2);
  padding: 14px;
  display: none;
  user-select: none;
}

.thai-cal.is-open {
  display: block;
}

.thai-cal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 10px;
}

.thai-cal__selects {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.thai-cal__select {
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-subtle);
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--green-900);
  cursor: pointer;
}

.thai-cal__select:focus {
  outline: none;
  border-color: var(--green-700);
}

.thai-cal__nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.thai-cal__nav-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--green-900);
  background: #fff;
  transition: background-color 0.15s, border-color 0.15s;
}

.thai-cal__nav-btn:hover {
  background: var(--green-50);
  border-color: var(--green-700);
}

.thai-cal__weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-light);
}

.thai-cal__weekdays span {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-sub);
}

.thai-cal__weekdays span:first-child {
  color: #dc2626;
}

.thai-cal__days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.thai-cal__day {
  height: 34px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, color 0.15s;
}

.thai-cal__day:hover {
  background: var(--green-100);
  color: var(--green-900);
}

.thai-cal__day.is-outside {
  color: #b5c4bc;
}

.thai-cal__day.is-today {
  border: 1.5px solid var(--green-700);
  font-weight: 700;
  color: var(--green-800);
}

.thai-cal__day.is-selected {
  background: var(--green-800);
  color: #fff;
  font-weight: 700;
  border-color: var(--green-800);
}

.thai-cal__day.is-disabled,
.thai-cal__day:disabled {
  color: #c5d1cb;
  background: transparent;
  border-color: transparent;
  text-decoration: line-through;
  cursor: not-allowed;
  opacity: 0.55;
}

.thai-cal__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
}

.thai-cal__foot-btn {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  color: var(--green-800);
  transition: background-color 0.15s;
}

.thai-cal__foot-btn:hover {
  background: var(--green-50);
}

.thai-cal__foot-btn.is-disabled,
.thai-cal__foot-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: transparent;
}

.thai-cal__foot-btn--clear {
  color: var(--text-sub);
}

.thai-cal__foot-btn--clear:hover {
  color: var(--red-600);
  background: var(--red-100);
}

textarea.input {
  min-height: 100px;
  resize: vertical;
}

/* Highlight Box for Expiration Date Scheduling */
.schedule-box {
  background: var(--green-50);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.schedule-box__title {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--green-900);
  margin-bottom: 4px;
}

.preset-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.preset-chip {
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  background: #fff;
  color: var(--green-800);
  border: 1px solid var(--border-strong);
}

.preset-chip:hover {
  background: var(--green-800);
  color: #fff;
  border-color: var(--green-800);
}

.toggle-list {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--green-900);
  cursor: pointer;
}

.toggle-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--green-800);
}

/* Upload Box */
.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.size-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--green-100);
  color: var(--green-800);
  font-size: 0.76rem;
  font-weight: 700;
}

.upload-box {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 14px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  flex-wrap: wrap;
}

.upload-preview {
  width: 100px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
  background: #fff;
  border: 1px solid var(--border-light);
  flex-shrink: 0;
}

.upload-empty {
  width: 100px;
  height: 60px;
  border-radius: 8px;
  background: #fff;
  border: 1.5px dashed var(--border-strong);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6px;
  line-height: 1.3;
  flex-shrink: 0;
}

.upload-spec {
  margin-top: 8px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  background: #fff;
  border: 1px solid var(--border-light);
  font-size: 0.78rem;
  color: var(--text-sub);
  line-height: 1.55;
}

.upload-spec strong {
  color: var(--green-900);
  font-weight: 700;
}

.upload-spec code {
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--green-800);
  background: var(--green-50);
  padding: 1px 6px;
  border-radius: 5px;
}

/* Modals & Toast */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 29, 20, 0.58);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-overlay.is-open {
  display: flex;
}

.modal-card {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.modal-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-light);
}

.modal-card__foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 16px;
  margin-top: 8px;
  border-top: 1px solid var(--border-light);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--green-900);
  color: #fff;
  padding: 13px 20px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: all 0.28s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   Responsive Design (Tablet & Smartphone)
   ========================================================================== */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

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

  .workspace {
    margin-left: 0;
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

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

@media (max-width: 680px) {
  .topbar {
    padding: 0 16px;
  }

  .content-area {
    padding: 16px;
  }

  .card,
  .modal-card {
    padding: 18px;
  }

  .kpi-grid,
  .form-grid-2,
  .form-grid-3,
  .demo-btns {
    grid-template-columns: 1fr;
  }

  .topbar__actions .btn span.hide-sm {
    display: none;
  }
}
