/* ==========================================================================
   VIGO Coffee POS — 100% Logical Properties RTL/LTR Touch-First UI Styles
   ========================================================================== */

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

[dir="rtl"] .flip-rtl {
  transform: scaleX(-1);
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 99px;
}

/* Buttons & Touch Targets (>= 48x48) */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch-target);
  min-width: 48px;
  padding-inline: 16px;
  padding-block: 8px;
  border-radius: var(--radius-base);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

button:active,
.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-success {
  background: var(--success);
  color: #0b1913;
  border-color: var(--success);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger-solid {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--bg-elevated);
}

.btn-sm {
  min-height: 48px;
  padding-inline: 12px;
  font-size: 0.85rem;
}

/* Form Inputs */
input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding-inline: 14px;
  padding-block: 10px;
  border-radius: calc(var(--radius-base) * 0.8);
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  text-align: start;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

label.field-label {
  display: block;
  margin-block-end: 6px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-rows: 64px 1fr;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-inline: 16px;
  background: var(--bg-surface);
  border-block-end: 1px solid var(--border-color);
  z-index: 20;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
}
.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
}

.nav-tab {
  min-height: 48px;
  padding-inline: 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  white-space: nowrap;
}
.nav-tab.active {
  background: var(--bg-elevated);
  color: var(--accent);
  border-color: var(--border-color);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding-inline: 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
}
.pill-badge.online { color: var(--success); }
.pill-badge.offline { color: var(--warning); border-color: var(--warning); }
.pill-badge.danger { color: var(--danger); border-color: var(--danger); }

/* Main Viewport */
.main-content {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.module-page {
  height: 100%;
  overflow-y: auto;
  padding: 16px;
}

/* POS 2-Pane Layout */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  height: 100%;
  overflow: hidden;
}

.pos-catalog {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  padding: 14px;
  gap: 12px;
}

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

.search-box {
  position: relative;
  flex: 1;
  min-width: 220px;
}
.search-box .search-icon {
  position: absolute;
  inset-inline-start: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-box input {
  padding-inline-start: 42px;
}

.category-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-block-end: 4px;
  flex-shrink: 0;
}

.cat-chip {
  min-height: 48px;
  padding-inline: 16px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
}
.cat-chip.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.product-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
  align-content: start;
  padding-block-end: 16px;
}

.product-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  text-align: start;
  padding: var(--card-pad);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-base);
  min-height: 132px;
  gap: 8px;
  cursor: pointer;
}
.product-card:hover {
  border-color: var(--accent);
}
.product-card.out-of-stock {
  opacity: 0.55;
}

.product-title {
  font-weight: 700;
  font-size: 0.98rem;
  line-height: 1.3;
}
.product-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.product-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-block-start: auto;
}
.product-price {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  font-size: 0.96rem;
}

.stock-dot {
  font-size: 0.72rem;
  padding-inline: 8px;
  padding-block: 3px;
  border-radius: 999px;
  font-weight: 600;
}
.stock-dot.ok { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.stock-dot.low { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.stock-dot.out { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

/* POS Cart Panel */
.pos-cart {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-surface);
  border-inline-start: 1px solid var(--border-color);
  overflow: hidden;
}

.cart-header {
  padding: 12px 14px;
  border-block-end: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--bg-primary);
  padding: 4px;
  border-radius: var(--radius-base);
  border: 1px solid var(--border-color);
}
.segmented button {
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.segmented button.active {
  background: var(--accent);
  color: var(--accent-text);
}

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cart-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: calc(var(--radius-base) * 0.85);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cart-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.cart-item-mods {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.cart-item-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.qty-stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.qty-stepper button {
  min-width: 48px;
  min-height: 48px;
  padding: 0;
}

.cart-footer {
  border-block-start: 1px solid var(--border-color);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-surface);
}

.totals-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.totals-row.grand {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  padding-block-start: 6px;
  border-block-start: 1px dashed var(--border-color);
}

.cart-actions-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

/* Cards, Grids & Tables */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-base);
  padding: 16px;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-base);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-label { font-size: 0.84rem; color: var(--text-muted); }
.kpi-value { font-family: var(--font-mono); font-size: 1.45rem; font-weight: 700; color: var(--accent); }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-base);
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: start;
}
table.data-table th,
table.data-table td {
  padding: 12px 14px;
  border-block-end: 1px solid var(--border-color);
  text-align: start;
  vertical-align: middle;
}
table.data-table th {
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.84rem;
  font-weight: 600;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
}
.modal-panel {
  width: min(680px, 100%);
  max-height: 90vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-base);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-panel.modal-lg { width: min(920px, 100%); }
.modal-panel.modal-sm { width: min(440px, 100%); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-block-end: 1px solid var(--border-color);
}
.modal-title { font-size: 1.1rem; font-weight: 700; margin: 0; }
.modal-body {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-footer {
  padding: 14px 18px;
  border-block-end: 0;
  border-block-start: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Login & PIN Pad */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
  z-index: 90;
}
.login-card {
  width: min(880px, 100%);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: calc(var(--radius-base) * 1.2);
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.pin-keypad button {
  min-height: 58px;
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding-block: 10px;
}
.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--accent);
}
.pin-dot.filled { background: var(--accent); }

/* Toast Notifications */
.toast-stack {
  position: fixed;
  inset-block-end: 20px;
  inset-inline-end: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  max-width: 360px;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-inline-start: 4px solid var(--accent);
  border-radius: var(--radius-base);
  padding: 12px 16px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  font-weight: 600;
}
.toast.success { border-inline-start-color: var(--success); }
.toast.error { border-inline-start-color: var(--danger); }
.toast.warning { border-inline-start-color: var(--warning); }

/* Floor Plan Table Cards */
.table-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  min-height: 100px;
  border-radius: var(--radius-base);
  border: 2px solid var(--border-color);
  background: var(--bg-elevated);
}
.table-card.available { border-color: var(--success); }
.table-card.occupied { border-color: var(--warning); }
.table-card.selected { background: color-mix(in srgb, var(--accent) 22%, transparent); border-color: var(--accent); }

/* Tablet Portrait & Mobile Responsiveness */
@media (max-width: 960px) {
  .pos-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 44vh;
  }
  .pos-cart {
    border-inline-start: none;
    border-block-start: 1px solid var(--border-color);
  }
  .login-card,
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
}

/* Sub-tabs inside modules */
.subtabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-block-end: 16px;
}
.subtab-btn {
  min-height: 48px;
  background: var(--bg-surface);
}
.subtab-btn.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
