/* ============================================================
   Inventory Management System — app.css
   Mobile-first, blue/white theme
   ============================================================ */

/* CSS Variables */
:root {
  --primary:        #1565C0;
  --primary-dark:   #0d47a1;
  --primary-light:  #e3f2fd;
  --secondary:      #546e7a;
  --success:        #2e7d32;
  --success-bg:     #e8f5e9;
  --danger:         #c62828;
  --danger-bg:      #ffebee;
  --warning:        #f57f17;
  --warning-bg:     #fff8e1;
  --text:           #212121;
  --text-muted:     #757575;
  --border:         #e0e0e0;
  --bg:             #f5f7fa;
  --white:          #ffffff;
  --sidebar-w:      240px;
  --radius:         6px;
  --shadow:         0 2px 8px rgba(0,0,0,.1);
  --font:           system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ============================================================
   Layout
   ============================================================ */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform .25s ease;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background: var(--primary-dark);
  min-height: 64px;
}

.company-logo-area {
  display: flex;
  align-items: center;
  gap: .5rem;
  overflow: hidden;
}

.company-logo-img {
  height: 36px;
  width: 36px;
  object-fit: contain;
  border-radius: 4px;
  background: var(--white);
}

.company-name {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-links {
  list-style: none;
  padding: .5rem 0;
  flex: 1;
}

.nav-link {
  display: block;
  padding: .75rem 1.25rem;
  color: rgba(255,255,255,.85);
  font-size: .9rem;
  transition: background .15s, color .15s;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255,255,255,.15);
  color: var(--white);
  text-decoration: none;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,.2);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.user-name {
  font-size: .85rem;
  font-weight: 600;
  color: var(--white);
}

.logout-btn {
  font-size: .8rem;
  padding: .4rem .75rem;
  color: var(--white);
  border-color: rgba(255,255,255,.5);
}

.logout-btn:hover {
  background: rgba(255,255,255,.15);
}

/* Main wrapper */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
}

/* Top bar (always visible on mobile, hidden on desktop) */
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--primary);
  color: #fff;
  padding: .6rem 1rem;
  position: sticky;
  top: 0;
  z-index: 300;
  gap: .5rem;
}
.topbar-title {
  font-weight: 700;
  font-size: 1rem;
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-logout {
  white-space: nowrap;
  font-size: .8rem;
  padding: .4rem .75rem;
  min-height: 36px;
}
.hamburger-top {
  display: flex !important;
}

.main-content {
  padding: 1.5rem;
  max-width: 1400px;
}

/* Hamburger */
.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: .25rem;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--white);
  border-radius: 2px;
  transition: .2s;
}

/* Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 199;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 1rem;
}

/* ============================================================
   Metrics Grid
   ============================================================ */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1rem;
  text-align: center;
  border-top: 3px solid var(--primary);
}

.metric-card--danger { border-top-color: var(--danger); }
.metric-card--success { border-top-color: var(--success); }

.metric-icon { font-size: 1.75rem; margin-bottom: .25rem; }
.metric-value { font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.metric-card--danger .metric-value { color: var(--danger); }
.metric-card--success .metric-value { color: var(--success); }
.metric-label { font-size: .8rem; color: var(--text-muted); margin-top: .2rem; }

/* ============================================================
   Page Header
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .6rem 1.25rem;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  border: 2px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
  min-height: 44px;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: var(--white); text-decoration: none; }

.btn-secondary {
  background: var(--white);
  color: var(--secondary);
  border-color: var(--border);
}
.btn-secondary:hover { background: #f5f5f5; text-decoration: none; }

.btn-danger {
  background: var(--danger);
  color: var(--white);
  border-color: var(--danger);
}
.btn-danger:hover { background: #b71c1c; text-decoration: none; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline:hover { background: var(--primary-light); text-decoration: none; }

.btn-full { width: 100%; }

.btn-sm {
  padding: .35rem .75rem;
  font-size: .8rem;
  min-height: 36px;
}

/* ============================================================
   Forms
   ============================================================ */
.field-group {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  margin-bottom: .9rem;
}

.field-group label {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="email"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: .6rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--white);
  transition: border-color .15s;
  min-height: 44px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(21,101,192,.15);
}

textarea { min-height: 80px; resize: vertical; }

.input-readonly {
  background: #f5f5f5;
  color: var(--text-muted);
  cursor: default;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: flex-end;
}

/* ============================================================
   Tables
   ============================================================ */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.data-table th {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  padding: .65rem .75rem;
  text-align: left;
  white-space: nowrap;
  border-bottom: 2px solid var(--primary);
}

.data-table td {
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: #fafafa; }

.data-table tfoot td {
  background: #f5f5f5;
  font-weight: 600;
  border-top: 2px solid var(--border);
}

.actions { white-space: nowrap; display: flex; gap: .4rem; align-items: center; }

/* ============================================================
   Alerts
   ============================================================ */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .9rem;
  border-left: 4px solid;
}

.alert-success { background: var(--success-bg); color: var(--success); border-color: #4caf50; }
.alert-error   { background: var(--danger-bg);  color: var(--danger);  border-color: #f44336; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #ffc107; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-super-admin, .badge-super_admin { background: #e8eaf6; color: #3949ab; }
.badge-admin   { background: #e3f2fd; color: var(--primary); }
.badge-user    { background: #f3e5f5; color: #7b1fa2; }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-issue   { background: #fff3e0; color: #e65100; }
.badge-return  { background: var(--success-bg); color: var(--success); }
.badge-payment { background: #e3f2fd; color: var(--primary); }

/* ============================================================
   Modals
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
}

.modal-box {
  position: relative;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-header h2 { font-size: 1.1rem; color: var(--primary); }

.modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: .25rem;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-footer {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Tabs
   ============================================================ */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
}

.tab {
  padding: .6rem 1.1rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  transition: .15s;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.tab:hover { color: var(--primary); text-decoration: none; background: var(--primary-light); }
.tab-active { color: var(--primary); background: var(--white); border-color: var(--border); border-bottom-color: var(--white); font-weight: 600; }

/* ============================================================
   Report Toolbar
   ============================================================ */
.report-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
}

.toolbar-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ============================================================
   Grid helpers
   ============================================================ */
.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

/* ============================================================
   Quick Actions
   ============================================================ */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

/* ============================================================
   Ledger row colors
   ============================================================ */
.row-issue   td { background: #fff8f0; }
.row-return  td { background: #f0fff4; }
.row-payment td { background: #f0f4ff; }

/* ============================================================
   Low stock / balance
   ============================================================ */
.low-stock td { background: #fff5f5 !important; }
.low-stock td:first-child { border-left: 3px solid var(--danger); }

.balance-positive { color: var(--success); font-weight: 700; }
.balance-negative { color: var(--danger);  font-weight: 700; }

.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted   { color: var(--text-muted); }
.text-center  { text-align: center; }

/* ============================================================
   Login Page
   ============================================================ */
.login-body {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-container {
  width: 100%;
  max-width: 400px;
}

.login-card {
  padding: 2rem;
}

.login-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-header h1 {
  font-size: 1.4rem;
  color: var(--primary);
  margin-bottom: .35rem;
}

.login-header p { color: var(--text-muted); font-size: .9rem; }

.login-hint {
  text-align: center;
  margin-top: 1rem;
  font-size: .8rem;
  color: var(--text-muted);
}

/* ============================================================
   Billing
   ============================================================ */
.bill-area {
  max-width: 800px;
}

.bill-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.bill-logo {
  height: 64px;
  width: auto;
  object-fit: contain;
}

.bill-company-info h2 { font-size: 1.2rem; color: var(--primary); }
.bill-company-info p  { font-size: .85rem; color: var(--text-muted); }

.bill-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: 1rem;
  font-size: .9rem;
}

.bill-table select,
.bill-table input {
  min-height: 36px;
  font-size: .85rem;
}

/* ============================================================
   Responsive — Mobile
   ============================================================ */
@media (max-width: 768px) {
  .topbar {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .hamburger {
    display: flex;
  }

  .main-wrapper {
    margin-left: 0;
  }

  .main-content {
    padding: 1rem;
  }

  .grid-2col {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .page-header h1 { font-size: 1.1rem; }

  .data-table { font-size: .8rem; }
  .data-table th, .data-table td { padding: .5rem .5rem; }

  .modal-box { padding: 1rem; }

  .tabs { gap: 0; }
  .tab { padding: .5rem .75rem; font-size: .8rem; }
}

@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .quick-actions .btn { flex: 1; min-width: 140px; }
}

/* ============================================================
   Dashboard — Hero + Glass Cards
   ============================================================ */

/* Hero bar */
.dash-hero {
  background: linear-gradient(135deg, #1565C0 0%, #0D47A1 60%, #1a237e 100%);
  border-radius: 14px;
  padding: 1.4rem 1.6rem;
  margin-bottom: 1.5rem;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dash-hero h1 { font-size: 1.4rem; font-weight: 700; margin: 0 0 .2rem; }
.dash-hero p  { font-size: .85rem; opacity: .8; margin: 0; }

/* Cards grid */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* Glass card base */
.glass-card {
  position: relative;
  border-radius: 16px;
  padding: 1.2rem 1.1rem 1rem;
  display: flex;
  align-items: center;
  gap: .9rem;
  text-decoration: none;
  color: #fff;
  overflow: hidden;
  transition: transform .18s, box-shadow .18s;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
}
.glass-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.12);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: inherit;
  border: 1px solid rgba(255,255,255,.25);
  pointer-events: none;
}
.glass-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 30px rgba(0,0,0,.22);
  color: #fff;
}

/* Icon circle */
.gc-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 12px;
  background: rgba(255,255,255,.22);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}
.gc-icon svg,
.gc-icon img {
  width: 24px !important;
  height: 24px !important;
  max-width: 24px !important;
  max-height: 24px !important;
  min-width: 24px;
  min-height: 24px;
  stroke: #fff;
  display: block;
  flex-shrink: 0;
}
.gc-ico-txt {
  font-size: 1.4rem;
  line-height: 1;
  display: block;
}

/* Text */
.gc-content { flex: 1; position: relative; z-index: 1; }
.gc-num   { font-size: 1.45rem; font-weight: 800; line-height: 1.1; }
.gc-title { font-size: .75rem; opacity: .85; margin-top: 2px; text-transform: uppercase; letter-spacing: .05em; }

/* Arrow */
.gc-arrow {
  font-size: 1.1rem;
  opacity: .6;
  position: relative;
  z-index: 1;
  transition: opacity .15s, transform .15s;
}
.glass-card:hover .gc-arrow { opacity: 1; transform: translateX(3px); }

/* Color variants */
.gc-blue    { background: linear-gradient(135deg, #1565C0, #1e88e5); }
.gc-emerald { background: linear-gradient(135deg, #065f46, #059669); }
.gc-red     { background: linear-gradient(135deg, #991b1b, #ef4444); }
.gc-teal    { background: linear-gradient(135deg, #0f766e, #14b8a6); }
.gc-orange  { background: linear-gradient(135deg, #c2410c, #f97316); }
.gc-violet  { background: linear-gradient(135deg, #6d28d9, #a78bfa); }
.gc-indigo  { background: linear-gradient(135deg, #3730a3, #6366f1); }

/* Quick Action grid */
.qa-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: .75rem;
}
.qa-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: 1rem .75rem;
  border-radius: 12px;
  background: #f8faff;
  border: 1.5px solid #e0e7ff;
  text-decoration: none;
  color: #1565C0;
  font-size: .82rem;
  font-weight: 600;
  transition: background .15s, border-color .15s, transform .15s, box-shadow .15s;
  text-align: center;
}
.qa-card svg {
  width: 26px !important;
  height: 26px !important;
  max-width: 26px;
  max-height: 26px;
  stroke: #1565C0;
  stroke-width: 2;
  display: block;
}
.qa-ico {
  font-size: 1.6rem;
  line-height: 1;
  display: block;
}
.qa-card:hover {
  background: #1565C0;
  border-color: #1565C0;
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(21,101,192,.25);
}
.qa-card:hover svg { stroke: #fff; }

/* ============================================================
   Autocomplete / Searchable Input
   ============================================================ */
.ac-wrap {
  position: relative;
}
.ac-input {
  width: 100%;
}
.ac-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  list-style: none;
  padding: 0;
  margin: 0;
}
.ac-item {
  padding: .6rem .9rem;
  cursor: pointer;
  font-size: .95rem;
  border-bottom: 1px solid #f0f0f0;
  transition: background .1s;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover,
.ac-item.ac-active {
  background: var(--primary-light);
  color: var(--primary);
}

/* Table search input */
.table-search {
  width: 100%;
  margin-bottom: .75rem;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
}

/* ============================================================
   Print Styles
   ============================================================ */
@media print {

  .no-print,
  .sidebar,
  .sidebar-overlay,
  .hamburger,
  .page-header .btn,
  .tabs,
  .report-toolbar .toolbar-actions,
  .alert,
  .btn { display: none !important; }

  .main-wrapper { margin-left: 0 !important; }
  .main-content { padding: 0 !important; }
  .app-wrapper  { display: block !important; }

  .card {
    box-shadow: none !important;
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }

  body { background: white; font-size: 12px; }

  .data-table th { background: #eee !important; color: #000 !important; }
  .data-table td, .data-table th { border: 1px solid #ccc !important; }

  .bill-area { max-width: 100%; border: none; }
  .bill-header { margin-bottom: .5rem; }

  a { color: #000; text-decoration: none; }
}
