/* ═══════════════════════════════════════════════════════════════
   Teddpharm Chemist POS — main.css
   v2.0 · Dark/Light · Responsive · Mobile-first
═══════════════════════════════════════════════════════════════ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --secondary: #10b981;
  --secondary-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --warning-border: #fde68a;
  --info: #3b82f6;
  --info-light: #dbeafe;

  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #1e1b4b;
  --text: #0f172a;
  --text-secondary: #334155;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.12);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --transition: .18s cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --border: #334155;
  --primary-light: #312e81;
  --secondary-light: #064e3b;
  --danger-light: #7f1d1d;
  --warning-light: #78350f;
  --info-light: #1e3a5f;
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 13px; }

/* ── Layout ─────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  color: #c7d2fe;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header { padding: 20px 16px 12px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-logo { display: flex; align-items: center; gap: 10px; }
.sidebar-logo-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; flex-shrink: 0; }
.sidebar-logo-text { font-weight: 700; font-size: 15px; color: #e0e7ff; line-height: 1.2; }
.sidebar-logo-sub { font-size: 11px; color: rgba(255,255,255,.35); }

.sidebar-nav { flex: 1; padding: 12px 10px; }
.nav-section-label { font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.3); padding: 14px 8px 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; color: rgba(255,255,255,.6);
  transition: all var(--transition); cursor: pointer;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #e0e7ff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer { padding: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 10px 8px 8px; }
.sidebar-user-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #e0e7ff; line-height: 1.2; }
.sidebar-user-role { font-size: 11px; color: rgba(255,255,255,.4); text-transform: capitalize; }

.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 199; }

/* ── Main Content ───────────────────────────────────────────── */
.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }
.top-bar { height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 20px; background: var(--bg-card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.hamburger { display: none; background: none; border: none; padding: 6px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-muted); }
.page-content { padding: 20px 24px 40px; flex: 1; }

/* ── Typography ─────────────────────────────────────────────── */
.page-title { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.2; }
.page-subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ── Cards ──────────────────────────────────────────────────── */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-title { font-size: 15px; font-weight: 600; color: var(--text); }

/* ── Stat Grid ──────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 14px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; display: flex; align-items: flex-start; gap: 14px; box-shadow: var(--shadow); }
.stat-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon.blue { background: var(--info-light); color: var(--info); }
.stat-icon.green { background: var(--secondary-light); color: var(--secondary); }
.stat-icon.yellow { background: var(--warning-light); color: var(--warning); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1.2; margin: 2px 0; }
.stat-sub { font-size: 11px; color: var(--text-muted); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; line-height: 1;
  border: none; cursor: pointer; transition: all var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-card); border-color: #cbd5e1; }
.btn-success { background: var(--secondary); color: #fff; }
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-ghost { background: none; color: var(--text-secondary); border: none; padding: 6px 8px; }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 14px; }
.btn-block { width: 100%; justify-content: center; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.form-control {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-card); color: var(--text); font-size: 13px;
  transition: border var(--transition), box-shadow var(--transition);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.form-control::placeholder { color: var(--text-muted); }
select.form-control { cursor: pointer; }

/* ── Filter bar ─────────────────────────────────────────────── */
.filter-bar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.search-bar { display: flex; align-items: center; gap: 8px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 10px; }
.search-bar input { border: none; background: none; padding: 9px 0; flex: 1; color: var(--text); }
.search-bar input:focus { outline: none; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrapper { border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--bg); }
th { padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text-secondary); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.badge-blue { background: var(--info-light); color: var(--info); }
.badge-green { background: var(--secondary-light); color: var(--secondary); }
.badge-yellow { background: var(--warning-light); color: var(--warning); }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-gray { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }

/* ── Modals ─────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(2px); animation: fadeIn .15s ease; }
.modal { background: var(--bg-card); border-radius: var(--radius-lg); width: 100%; box-shadow: var(--shadow-lg); max-height: 92vh; overflow-y: auto; animation: slideUp .2s cubic-bezier(.34,1.56,.64,1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.modal-title { font-size: 17px; font-weight: 700; color: var(--text); }
.modal-body { padding: 16px 20px; }
.modal-footer { padding: 12px 20px 18px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--border); margin-top: 4px; }

/* ── Toasts ─────────────────────────────────────────────────── */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--shadow-md); font-size: 13px; font-weight: 500; max-width: 360px; min-width: 240px; animation: slideInRight .25s cubic-bezier(.34,1.56,.64,1); }
.toast.success { background: var(--secondary-light); color: #065f46; border-left: 4px solid var(--secondary); }
.toast.error { background: var(--danger-light); color: #991b1b; border-left: 4px solid var(--danger); }
.toast.warning { background: var(--warning-light); color: #92400e; border-left: 4px solid var(--warning); }
.toast.info { background: var(--info-light); color: #1e40af; border-left: 4px solid var(--info); }
.toast-close { margin-left: auto; background: none; border: none; cursor: pointer; opacity: .6; font-size: 14px; }
.toast-close:hover { opacity: 1; }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px; line-height: 1.5; }
.alert-danger { background: var(--danger-light); color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid var(--warning-border); }
.alert-success { background: var(--secondary-light); color: #065f46; border: 1px solid #6ee7b7; }
.alert-info { background: var(--info-light); color: #1e40af; border: 1px solid #93c5fd; }

/* ── Dash grid ──────────────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-top: 16px; }

/* ── Category tabs ──────────────────────────────────────────── */
.category-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.category-tab { padding: 6px 14px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px; font-size: 12px; font-weight: 600; color: var(--text-muted); cursor: pointer; transition: all var(--transition); white-space: nowrap; }
.category-tab:hover { border-color: var(--primary); color: var(--primary); }
.category-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── POS Layout ─────────────────────────────────────────────── */
.pos-layout { display: grid; grid-template-columns: 1fr 360px; gap: 16px; height: calc(100vh - var(--topbar-h) - 48px); }
.pos-products-panel { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px,1fr)); gap: 10px; overflow-y: auto; flex: 1; padding-right: 4px; }
.product-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 12px; cursor: pointer; transition: all var(--transition); }
.product-card:hover { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); transform: translateY(-1px); }
.product-card:active { transform: scale(.97); }
.product-card.out-of-stock { opacity: .72; cursor: pointer; border-color: #fca5a5; }
.product-name { font-weight: 600; font-size: 13px; line-height: 1.3; margin-bottom: 6px; }
.product-price { font-size: 15px; font-weight: 700; color: var(--primary); }
.product-stock { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.product-category-badge { font-size: 10px; color: var(--text-muted); margin-bottom: 6px; }

/* ── Cart ───────────────────────────────────────────────────── */
.cart-panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.cart-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.cart-items { flex: 1; overflow-y: auto; padding: 10px; }
.cart-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--text-muted); font-size: 13px; }
.cart-item { display: flex; align-items: center; gap: 8px; padding: 10px; background: var(--bg); border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 13px; }
.cart-item-name { flex: 1; font-weight: 500; line-height: 1.3; }
.cart-item-price { font-size: 12px; color: var(--text-muted); }
.qty-btn { width: 26px; height: 26px; border: 1px solid var(--border); background: var(--bg-card); border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; cursor: pointer; font-weight: 700; font-size: 14px; transition: all var(--transition); }
.qty-btn:hover { border-color: var(--primary); color: var(--primary); }
.qty-display { min-width: 24px; text-align: center; font-weight: 600; font-size: 13px; }
.cart-footer { padding: 12px 14px; border-top: 1px solid var(--border); }
.cart-totals { margin-bottom: 12px; }
.cart-total-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.cart-total-row.grand-total { font-size: 16px; font-weight: 700; color: var(--text); padding-top: 8px; border-top: 1px solid var(--border); margin-top: 4px; }
.payment-methods { display: flex; gap: 6px; margin-bottom: 10px; }
.payment-btn { flex: 1; padding: 8px; border: 2px solid var(--border); background: var(--bg-card); border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; cursor: pointer; transition: all var(--transition); color: var(--text-muted); }
.payment-btn.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.payment-btn:hover:not(.active) { border-color: #cbd5e1; color: var(--text); }

/* ── Offline banner ─────────────────────────────────────────── */
.offline-banner { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--warning-light); color: #92400e; font-size: 13px; font-weight: 500; border-radius: var(--radius-sm); margin-bottom: 12px; }
.offline-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); }
.online-badge { display: flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--secondary-light); color: #065f46; transition: all var(--transition); }
.online-badge.offline { background: var(--warning-light); color: #92400e; }
.online-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--secondary); animation: pulse 2s infinite; }
.online-badge.offline .online-dot { background: var(--warning); animation: none; }

/* ── Login ──────────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e1b4b 100%); }
.login-card { background: var(--bg-card); border-radius: var(--radius-lg); padding: 36px 32px; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo-icon { width: 56px; height: 56px; border-radius: 14px; background: var(--primary); color: #fff; font-weight: 800; font-size: 20px; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px; }
.login-logo-name { font-size: 20px; font-weight: 700; color: var(--text); }
.login-logo-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Spinner ────────────────────────────────────────────────── */
.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }

/* ── Animations ─────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity:0 } to { opacity:1 } }
@keyframes slideUp { from { opacity:0; transform:translateY(20px) } to { opacity:1; transform:translateY(0) } }
@keyframes slideInRight { from { opacity:0; transform:translateX(24px) } to { opacity:1; transform:translateX(0) } }
@keyframes spin { to { transform:rotate(360deg) } }
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:.4 } }

/* ── Utilities ──────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--secondary); }
code { font-family: 'SFMono-Regular', Consolas, monospace; background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; border: 1px solid var(--border); }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .dash-grid { grid-template-columns: 1fr; }
  .pos-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; height: auto; }
  .product-grid { height: 340px; }
  .cart-panel { height: auto; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-240px); width: 240px; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.hidden { display: none; }
  .main-content { margin-left: 0; }
  .hamburger { display: flex; }
  .page-content { padding: 14px 14px 32px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 20px; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(130px,1fr)); height: 300px; }
  .pos-layout { gap: 10px; }
  table { min-width: 520px; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .search-bar { max-width: 100% !important; }
  .modal { margin: 8px; }
  .login-card { padding: 24px 18px; }
}
