/* ==========================================================================
   YW Wear ERP - Dark theme, mobile-first
   ========================================================================== */

:root {
  --bg: #0f1115;
  --bg-elevated: #161922;
  --bg-card: #1b1f2a;
  --bg-input: #10131a;
  --border: #2a2f3d;
  --border-light: #343b4d;
  --text: #e7e9ee;
  --text-muted: #8b93a7;
  --text-dim: #5c6478;

  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #60a5fa;

  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --info: #38bdf8;
  --info-bg: rgba(56, 189, 248, 0.12);

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 16px rgba(0,0,0,0.35);
  --nav-height: 58px;
  --topbar-height: 56px;
  --sidebar-width: 230px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary-light); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 12px; font-weight: 600; }
p { margin: 0 0 8px; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }

/* ---------------- Layout ---------------- */

.app-shell {
  min-height: 100vh;
  padding-bottom: calc(var(--nav-height) + 12px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-height);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
}

.topbar .brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar .brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }

.topbar .user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.topbar .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary-dark);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px;
}

/* Sidebar for larger screens (admin/manager/storekeeper) */
.with-sidebar { display: flex; }
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  min-height: calc(100vh - var(--topbar-height));
  padding: 14px 10px;
  display: none;
}
.sidebar a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 2px;
}
.sidebar a.active, .sidebar a:hover { background: var(--bg-card); color: var(--text); }
.sidebar .section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-dim); padding: 14px 12px 6px;
}
.main-content { flex: 1; min-width: 0; }

@media (min-width: 900px) {
  .sidebar { display: block; }
  .bottom-nav { display: none !important; }
  .app-shell { padding-bottom: 0; }
}

/* Bottom nav for mobile (primarily sales rep, but works for all on small screens) */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 50;
}
.bottom-nav a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  color: var(--text-dim);
  font-size: 10px;
}
.bottom-nav a.active { color: var(--primary-light); }
.bottom-nav svg { width: 20px; height: 20px; }

/* ---------------- Cards / Panels ---------------- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.card-title h3 { margin: 0; font-size: 15px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 700px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.stat-card .stat-value { font-size: 22px; font-weight: 700; }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---------------- Forms ---------------- */

label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.required-mark { color: var(--danger); margin-left: 2px; }
.form-group { margin-bottom: 14px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; }
.form-row > .form-group { flex: 1 1 160px; }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=search], input[type=tel], input[type=email], select, textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  font-size: 16px; /* 16px+ prevents iOS Safari from auto-zooming the page on focus */
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 70px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* ---------------- Line-item editor cards (invoices, GRN, orders, returns) ----------------
   Each product line stacks cleanly on narrow screens: product picker full-width on its
   own row, then qty/price/discount in a wrapping grid, remove button always reachable. */
.line-item-card { padding: 12px; margin-bottom: 10px; }
.line-item-card .line-item-top {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.line-item-card .line-item-top select { flex: 1; min-width: 0; }
.line-item-card .line-item-remove {
  flex: 0 0 auto; width: 34px; height: 34px; padding: 0;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.line-item-card .line-item-fields {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px;
}
.line-item-card .line-item-fields .form-group { margin-bottom: 0; }
.line-item-card label { font-size: 11px; margin-bottom: 3px; }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #06240f; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #241a02; }
.btn-ghost { background: transparent; border-color: var(--border-light); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------------- Badges ---------------- */

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: var(--bg-input); color: var(--text-muted); }

/* ---------------- Tables (responsive -> cards on mobile) ---------------- */

table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th {
  text-align: left; font-size: 12px; text-transform: uppercase;
  color: var(--text-dim); padding: 10px 12px; border-bottom: 1px solid var(--border);
}
table.data-table td {
  padding: 12px; border-bottom: 1px solid var(--border);
  font-size: 14px;
}
table.data-table tr:last-child td { border-bottom: none; }

@media (max-width: 700px) {
  table.data-table.responsive-cards thead { display: none; }
  table.data-table.responsive-cards, table.data-table.responsive-cards tbody, table.data-table.responsive-cards tr, table.data-table.responsive-cards td {
    display: block; width: 100%;
  }
  table.data-table.responsive-cards tr {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 6px 4px;
  }
  table.data-table.responsive-cards td {
    border-bottom: none;
    padding: 6px 10px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
  }
  table.data-table.responsive-cards td::before {
    content: attr(data-label);
    color: var(--text-dim);
    font-size: 12px;
    text-transform: uppercase;
    flex-shrink: 0;
  }
}

.table-wrap { overflow-x: auto; }

/* ---------------- Modal ---------------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: none; align-items: flex-end; justify-content: center;
  z-index: 100;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 560px;
  max-height: 92vh; overflow-y: auto;
  padding: 18px;
  animation: slideUp .15s ease-out;
}
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--radius); }
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header h3 { margin: 0; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------------- Toasts ---------------- */

.toast-container {
  position: fixed; top: 70px; right: 14px; left: 14px;
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
@media (min-width: 700px) { .toast-container { left: auto; } }
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-left: 4px solid var(--primary);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 14px;
  max-width: 360px;
  animation: fadeIn .15s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------- Login page ---------------- */

.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 30px 24px; width: 100%; max-width: 380px;
}
.login-card .brand-title { text-align: center; font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-card .brand-sub { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }

/* ---------------- Misc ---------------- */

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-input); border: 1px solid var(--border-light);
  padding: 4px 10px; border-radius: 100px; font-size: 12px;
}
.fab {
  position: fixed; bottom: calc(var(--nav-height) + 16px); right: 16px;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; box-shadow: var(--shadow); z-index: 45; cursor: pointer;
}
@media (min-width: 900px) { .fab { bottom: 24px; } }

.search-bar { position: relative; margin-bottom: 12px; }
.search-bar input { padding-left: 36px; }
.search-bar svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-dim); }

.spinner {
  border: 2px solid var(--border-light); border-top-color: var(--primary);
  border-radius: 50%; width: 18px; height: 18px; animation: spin .6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Mobile full menu sheet ---------------- */
.mobile-menu-list { max-height: 70vh; overflow-y: auto; }
.mobile-menu-link {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  border-bottom: 1px solid var(--border);
}
.mobile-menu-link:last-child { border-bottom: none; }
.mobile-menu-link.active { color: var(--primary-light); background: var(--bg-card); }
.mobile-menu-link:hover { background: var(--bg-card); }
