/* =====================================================
   CM POS — Shared Stylesheet
   Cloudmate Brand Theme
   ===================================================== */

:root {
  /* ---- Cloudmate Brand Colors ---- */
  --primary:       #0099e5;
  --primary-dark:  #0075b0;
  --primary-light: #E0F4FF;
  --accent:        #221f3c;
  --accent-light:  #EEEDF5;
  --warning:       #BA7517;
  --warning-light: #FAEEDA;
  --danger:        #A32D2D;
  --danger-light:  #FCEBEB;
  --text-primary:  #222222;
  --text-secondary:#5a5a5a;
  --text-muted:    #888888;
  --bg:            #f9f9f9;
  --surface:       #FFFFFF;
  --border:        #E4E4E4;
  --border-strong: #C8C8C8;
  --radius-sm:     8px;
  --radius-md:     12px;
  --radius-lg:     16px;
  --shadow-sm:     0 1px 4px rgba(0,0,0,.08);
  --shadow-md:     0 4px 16px rgba(0,0,0,.12);
  --topbar-h:      58px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

html { overflow-x: clip; }
body {
  font-family: 'Inter', 'Sarabun', 'Noto Sans Thai', Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: clip;
  max-width: 100vw;
}

/* ---- Typography ---- */
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p  { font-size: 0.9rem; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border: none; border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500; cursor: pointer;
  transition: filter .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--primary);   color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--surface);   color: var(--text-primary); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger    { background: var(--danger-light); color: var(--danger); }
.btn-warning   { background: var(--warning-light); color: var(--warning); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-full { width: 100%; }

/* Language switcher buttons in topbar */
.lang-btn-topbar {
  background: transparent; border: none; cursor: pointer;
  font-size: 1.15rem; padding: 3px 6px; border-radius: 16px;
  opacity: 0.55; transition: opacity .15s, background .15s;
}
.lang-btn-topbar:hover { opacity: 0.85; background: rgba(255,255,255,.15); }
.lang-btn-topbar.active { opacity: 1; background: rgba(255,255,255,.25); }

/* ---- Cards ---- */
.card {
  background: var(--surface); border-radius: var(--radius-md);
  border: 1px solid var(--border); padding: 1rem 1.25rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

/* ---- Badges ---- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 0.75rem; font-weight: 500; white-space: nowrap;
}
.badge-green   { background: var(--primary-light); color: var(--primary-dark); }
.badge-blue    { background: var(--accent-light);  color: var(--accent); }
.badge-amber   { background: var(--warning-light); color: var(--warning); }
.badge-orange  { background: #fff7ed; color: #c2410c; }
.badge-red     { background: var(--danger-light);  color: var(--danger); }
.badge-gray    { background: #E8E6DF; color: var(--text-secondary); }

/* ---- Form Elements ---- */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 4px; color: var(--text-secondary); }
.form-control {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); font-size: 0.9rem; background: var(--surface);
  color: var(--text-primary); transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,153,229,.15); }
select.form-control { cursor: pointer; }

/* Collapsible field groups inside forms (native <details>) */
details.form-accordion { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
details.form-accordion > summary {
  font-size: 0.875rem; font-weight: 500; color: var(--text-secondary);
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px;
}
details.form-accordion > summary::-webkit-details-marker { display: none; }
details.form-accordion > summary::before { content: '▸'; font-size: .75rem; color: var(--text-muted); transition: transform .15s; }
details.form-accordion[open] > summary::before { transform: rotate(90deg); }
details.form-accordion > .accordion-body { margin-top: 10px; }

/* branch dropdown options — white text on dark topbar but must be readable in native dropdown */
#staff-branch-filter option,
#superadmin-branch-filter option,
#kds-branch-filter option {
  color: #1a1a1a;
  background: #fff;
}

/* ---- Top Navigation ---- */
.topbar {
  background: linear-gradient(135deg, #0d1b2a 0%, #1a3454 60%, #0a2a4a 100%);
  color: #fff;
  padding: 0 1.5rem; height: 58px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 16px rgba(0,0,0,.3);
  border-bottom: 1px solid rgba(0,153,229,.35);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-brand h1 {
  font-size: 1.1rem; font-weight: 700; color: #fff;
  letter-spacing: .02em;
}
.topbar-brand h1 span { color: #0099e5; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.topbar-nav { display: flex; gap: 6px; }
.topbar-nav a {
  padding: 6px 14px; border-radius: var(--radius-sm); color: rgba(255,255,255,.75);
  text-decoration: none; font-size: 0.85rem; font-weight: 500;
  transition: background .15s, color .15s;
  border: 1px solid transparent;
}
.topbar-nav a:hover { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.12); }
.topbar-nav a.active { background: rgba(0,153,229,.2); color: #fff; border-color: rgba(0,153,229,.4); }

/* ---- Sidebar ---- */
.sidebar {
  width: 220px; background: var(--surface); border-right: 1px solid var(--border);
  height: calc(100vh - var(--topbar-h)); position: fixed; left: 0; top: var(--topbar-h);
  padding: 0.5rem 0; overflow-y: auto;
}
.sidebar-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 1.25rem; color: var(--text-secondary); text-decoration: none;
  font-size: 0.85rem; transition: all .15s;
}
.sidebar-item:hover, .sidebar-item.active {
  background: var(--primary-light); color: var(--primary-dark); border-left: 3px solid var(--primary);
}
.sidebar-item .icon { font-size: 1rem; width: 20px; text-align: center; }
.sidebar-group-label {
  font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .7px;
  color: var(--text-muted); padding: 8px 1.25rem 3px; margin-top: 2px;
}
.sidebar-divider { height: 1px; background: var(--border); margin: 4px 12px; }

/* ---- Layout ---- */
.main-layout { display: flex; }
.main-content { flex: 1; min-width: 0; padding: 1.25rem; padding-top: 0.5rem; padding-bottom: 0.5rem; margin-left: 220px; margin-top: 0; min-height: calc(100vh - var(--topbar-h)); }
.page-title { font-size: 1.25rem; font-weight: 600; margin-bottom: 1.25rem; color: var(--text-primary); }

/* ---- Tables ---- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: #EFF7FF; color: var(--text-secondary);
  padding: 10px 12px; text-align: left; font-size: 0.8rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.875rem;
}
.data-table tr:hover td { background: #F8F9FA; }

/* ---- Toast ---- */
.toast-container { position: fixed; top: 70px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text-primary); color: #fff; padding: 12px 16px;
  border-radius: var(--radius-sm); font-size: 0.875rem; min-width: 250px;
  box-shadow: var(--shadow-md); animation: slideIn .2s ease;
}
.toast.success { background: var(--primary-dark); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ---- Stat Cards ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border-radius: var(--radius-md); border: 1px solid var(--border); padding: 1.25rem; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--text-primary); }
.stat-change { font-size: 0.8rem; color: var(--primary); margin-top: 4px; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,25,40,.55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  animation: overlayIn .18s ease;
}
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn   { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: none; } }

.modal, .modal-box {
  background: var(--surface);
  border-radius: 20px;
  padding: 0; width: 90%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.08);
  animation: modalIn .22s cubic-bezier(.34,1.2,.64,1);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.1rem 1.4rem;
  background: linear-gradient(135deg, #0099e5 0%, #0075b0 100%);
  border-radius: 20px 20px 0 0;
  margin-bottom: 0;
}
.modal-header h3, .modal-header h2 {
  color: #fff; font-size: 1rem; font-weight: 700; margin: 0;
}
.modal-body { padding: 1.25rem 1.4rem; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  border-radius: 0 0 20px 20px;
  flex-wrap: wrap;
}
.modal-close {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,.2); border: none;
  font-size: .9rem; cursor: pointer; color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s; flex-shrink: 0;
}
.modal-close:hover { background: rgba(255,255,255,.35); }

/* ---- Modal internal sections ---- */
.modal-info-strip {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: .85rem; color: var(--text-secondary);
}
.modal-info-strip strong { color: var(--text-primary); }
.modal-info-strip .sep   { color: var(--border-strong); user-select: none; }

.modal-items-wrap {
  padding: 0 20px 4px;
  max-height: 230px; overflow-y: auto;
}

.modal-summary-wrap {
  padding: 12px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.modal-summary-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; font-size: .9rem; color: var(--text-secondary);
}
.modal-summary-row span:last-child { color: var(--text-primary); font-weight: 500; }
.modal-summary-row.discount { color: var(--danger); }
.modal-summary-row.discount span:last-child { color: var(--danger); }
.modal-summary-row.total {
  font-size: 1.05rem; font-weight: 700;
  border-top: 1.5px solid var(--border-strong);
  padding-top: 8px; margin-top: 4px;
}
.modal-summary-row.total span { color: var(--text-primary) !important; }

.modal-actions-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  border-radius: 0 0 20px 20px;
}

/* ---- Table responsive wrapper ---- */
.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---- Bottom Navigation (mobile — Staff/Kitchen) ---- */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,.1);
  height: 60px;
  padding: 0;
}
.bottom-nav-items {
  display: flex; height: 100%;
}
.bottom-nav-item {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  border: none; background: none; cursor: pointer;
  color: var(--text-muted); font-size: .6rem; font-weight: 500;
  padding: 6px 2px; transition: color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
.bottom-nav-item .bn-icon { width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.bottom-nav-item .bn-icon svg { width: 100%; height: 100%; }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item.active .bn-icon { transform: scale(1.1); }
.bottom-nav-item:active { background: var(--primary-light); }

/* ---- FAB: เปิดออเดอร์ใหม่ (desktop/tablet — บนมือถือมี bottom-nav ให้แล้ว) ---- */
.fab-new-order {
  display: flex; align-items: center; justify-content: center;
  position: fixed; right: 20px; bottom: 20px; z-index: 150;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  cursor: pointer; transition: transform .15s;
  -webkit-tap-highlight-color: transparent;
}
.fab-new-order:active { transform: scale(.93); }
.fab-new-order svg { width: 26px; height: 26px; }
@media (max-width: 768px) {
  .fab-new-order { display: none; }
}

/* ---- Card table row (mobile admin) ---- */
.card-table-row {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 12px 14px;
  margin-bottom: 8px; display: flex; flex-direction: column; gap: 6px;
}
.card-table-row .ctr-title { font-weight: 600; font-size: .9rem; color: var(--text-primary); }
.card-table-row .ctr-meta  { font-size: .8rem; color: var(--text-muted); }
.card-table-row .ctr-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

/* ---- Responsive ---- */
.hamburger {
  display: none; background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,.9); font-size: 1.3rem; padding: 4px 8px;
  line-height: 1;
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 99;
}

@media (max-width: 768px) {
  /* ── global overflow lock ── */
  html, body { overflow-x: clip; max-width: 100vw; }
  * { box-sizing: border-box; }

  /* ---- Typography ---- */
  html { font-size: 14px; }
  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.15rem; }

  /* ---- Topbar ---- */
  .topbar {
    padding: 0 0.75rem; height: 52px; min-height: 52px;
    overflow: hidden; /* ห้ามล้น viewport */
  }
  .topbar-brand { min-width: 0; overflow: hidden; flex-shrink: 1; }
  .topbar-brand h1 {
    font-size: .85rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: min(120px, 28vw);
  }
  .topbar-actions {
    gap: 4px; flex-shrink: 0;
    max-width: 60vw; overflow: hidden;
  }
  /* branch selector — clamp width on mobile */
  #staff-branch-filter {
    max-width: 110px !important;
    font-size: .7rem !important;
    padding: 2px 4px !important;
  }
  #staff-branch-filter option {
    color: #1a1a1a;
    background: #fff;
  }
  .topbar-nav { display: none; }

  /* ---- Sidebar → hamburger ---- */
  .hamburger { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .25s; z-index: 100; }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open ~ .sidebar-overlay,
  .sidebar-overlay.open { display: block; }

  /* ---- Layout ---- */
  .main-layout { overflow-x: clip; max-width: 100vw; }
  .main-content {
    margin-left: 0; max-width: 100vw; min-width: 0;
    overflow-x: clip;
    padding: 0.75rem; padding-bottom: calc(0.75rem + 60px);
  }

  /* ---- Stats ---- */
  .stat-grid { grid-template-columns: 1fr 1fr; gap: .75rem; }
  .stat-value { font-size: 1.4rem; }

  /* ---- Modal ---- */
  .modal, .modal-box {
    width: 95vw; max-height: 92vh;
    border-radius: var(--radius-md);
  }
  .modal-header { border-radius: var(--radius-md) var(--radius-md) 0 0; }
  .modal-footer { border-radius: 0 0 var(--radius-md) var(--radius-md); flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; }
  .modal-body { padding: 1rem; }
  .modal-items-wrap { max-height: 35vh; }

  /* ---- Buttons ---- */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; padding: 6px 10px; }

  /* ---- Toast → bottom on mobile ---- */
  .toast-container { top: auto; bottom: 70px; right: 8px; left: 8px; }
  .toast { min-width: unset; width: 100%; }

  /* ---- Forms ---- */
  .form-control { font-size: 16px; } /* ป้องกัน iOS zoom */

  /* ---- Bottom nav show ---- */
  .bottom-nav { display: flex; flex-direction: column; }
}

/* ---- Print ---- */
@media print {
  .topbar, .sidebar, .bottom-nav, .btn, .no-print { display: none !important; }
  .main-content { margin: 0; padding: 0; }
  body { background: #fff; }
}
