/* ===== POS Modern UI - Clean & Beautiful ===== */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #0d9488;
  --primary-hover: #0f766e;
  --primary-light: #ccfbf1;
  --success: #059669;
  --success-bg: #d1fae5;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --info: #0284c7;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* ===== Header ===== */
.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  min-height: 64px;
}

.logo {
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--primary);
  text-decoration: none;
  letter-spacing: -0.03em;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.nav a:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.header-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-name {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.btn-logout {
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: transparent;
}

/* ===== Main ===== */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* ===== Cards ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: box-shadow 0.2s, transform 0.05s;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.card-value {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.card-primary .card-value { color: var(--primary); }
.card-success .card-value { color: var(--success); }
.card-info .card-value { color: var(--info); }
.card-danger .card-value { color: var(--danger); }

.card h2 { margin: 0 0 0.5rem; font-size: 0.95rem; font-weight: 600; color: var(--text-muted); }

/* ===== Section ===== */
.section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.section h1 { margin: 0 0 1rem; font-size: 1.25rem; }
.subheading { font-size: 1.05rem; font-weight: 600; margin: 0 0 0.75rem; color: var(--text); }

/* ===== Toolbar - Always visible ===== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.25rem;
}

.toolbar .search-input {
  flex: 1;
  min-width: 200px;
  max-width: 320px;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
}

.toolbar .search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.toolbar .filter-select {
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--bg-card);
  min-width: 150px;
}

.btn-add-page {
  flex-shrink: 0;
}

/* Products page: always show Add button and table */
.products-actions {
  margin-bottom: 1rem;
}

.products-actions .btn {
  padding: 0.65rem 1.35rem;
  font-size: 1rem;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 0.5rem;
  min-height: 120px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}

.table-wrap .table {
  margin-top: 0;
}

.table-wrap .empty-state {
  padding: 2.5rem 1rem !important;
  font-size: 1rem;
  color: var(--text-muted);
}

/* ===== Forms ===== */
.form { max-width: 440px; margin-bottom: 1.5rem; }
.form-row { margin-bottom: 1rem; }
.form-row label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
  color: var(--text);
  font-size: 0.9rem;
}

.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--bg-card);
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-row-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.form-row-inline .form-row { margin-bottom: 0; }
.form-actions { margin-top: 1.25rem; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.2s;
  font-family: inherit;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
  border-color: var(--text-muted);
}

.btn-link { background: transparent; color: var(--primary); font-weight: 500; }
.btn-link:hover { text-decoration: underline; }

/* ===== Table ===== */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  font-size: 0.95rem;
}

.table th,
.table td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table tbody tr:hover { background: #f8fafc; }
.table a { color: var(--primary); text-decoration: none; font-weight: 500; }
.table a:hover { text-decoration: underline; }
.link-delete { color: var(--danger) !important; }

.empty-state {
  text-align: center;
  padding: 2rem 1rem !important;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.table-filterable tbody tr.filter-hide { display: none; }
.filter-no-result { display: none; }

.btn-edit-inline {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: inherit;
  font-weight: 500;
  padding: 0;
  margin-right: 0.75rem;
}

.btn-edit-inline:hover { text-decoration: underline; }

/* ===== Alerts ===== */
.message {
  background: var(--success-bg);
  color: #065f46;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.95rem;
  border: 1px solid #a7f3d0;
}

.error {
  background: var(--danger-bg);
  color: #991b1b;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.95rem;
  border: 1px solid #fecaca;
}

.muted { color: var(--text-muted); font-size: 0.9rem; }
.hint { color: var(--text-muted); font-size: 0.9rem; }
.hint code, code { background: var(--bg); padding: 0.2rem 0.5rem; border-radius: 6px; font-size: 0.85em; }

/* ===== Modal - Beautiful & reliable close ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-overlay.is-open { display: flex; }

.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.35rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { margin: 0; font-size: 1.2rem; font-weight: 700; color: var(--text); }

.modal-close {
  background: var(--bg);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  font-size: 1.35rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: transparent;
}

.modal-body { padding: 1.5rem; }
.modal-body .form { max-width: none; }

/* ===== Auth ===== */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #e0f2fe 0%, #f0f9ff 50%, #f1f5f9 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.auth-card h1 { margin: 0 0 0.5rem; font-size: 1.5rem; font-weight: 700; color: var(--text); text-align: center; }
.auth-desc { color: var(--text-muted); text-align: center; margin-bottom: 1.5rem; font-size: 0.95rem; }
.auth-form .form-row { margin-bottom: 1rem; }
.auth-form .btn-block { margin-top: 0.5rem; }

/* ===== POS Sales ===== */
.pos-section .pos-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .pos-section .pos-grid { grid-template-columns: 1fr; }
}

.pos-products h2,
.pos-cart h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.product-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.product-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.product-item .p-name { font-weight: 500; color: var(--text); }
.product-item .p-price { color: var(--primary); font-weight: 600; }
.product-item .p-stock, .product-item .p-cat { color: var(--text-muted); font-size: 0.8rem; }

.btn-add {
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}

.btn-add:hover { background: #047857; }

.pos-cart {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 1.35rem;
  border: 1px solid var(--border);
  position: sticky;
  top: 88px;
}

.cart-optional { margin-bottom: 1rem; }
.cart-optional label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 0.35rem; color: var(--text-muted); }
.cart-optional select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--bg-card);
}

.cart-list { min-height: 60px; margin-bottom: 1rem; }

.cart-row {
  display: grid;
  grid-template-columns: 1fr 56px 72px 72px auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.cart-row input {
  width: 100%;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  max-width: 52px;
  font-size: 0.9rem;
}

.cart-remove {
  background: none;
  color: var(--danger);
  border: none;
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0 0.25rem;
  opacity: 0.85;
}

.cart-remove:hover { opacity: 1; }

.cart-summary {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
  margin-bottom: 0.85rem;
}

.cart-row-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
}

.cart-row-summary input {
  width: 100px;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.cart-total {
  padding: 0.75rem 0;
  border-top: 2px solid var(--border);
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

.cart-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.checkbox-label { font-size: 0.9rem; margin-right: auto; color: var(--text-muted); }
.checkbox-label input { margin-right: 0.4rem; }

/* ===== Reports ===== */
.report-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.25rem; margin-bottom: 1.5rem; }
.report-cards .card .inline-form { display: flex; gap: 0.5rem; margin: 0.5rem 0 0.25rem; align-items: center; }
.report-cards .card .inline-form input[type="date"],
.report-cards .card .inline-form input[type="month"] {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--bg-card);
}

.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }

.report-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 1rem;
}

.report-tabs a {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.report-tabs a:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-light); }
.report-tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== Finance ===== */
.table-finance { max-width: 440px; }
.table-finance .text-right { text-align: right; }
.table-finance .row-total { border-top: 2px solid var(--border); background: #f8fafc; }
.table-finance .row-net { font-size: 1.05rem; }
.table-finance .row-net td { padding: 0.85rem 1rem; }

/* ===== Settings ===== */
.settings-block { margin-bottom: 2rem; }
.settings-block:last-child { margin-bottom: 0; }
.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
  margin: 0.5rem 0 1rem;
  white-space: pre;
}

/* ===== Invoice ===== */
body .invoice-title { font-size: 1.25rem; margin-bottom: 1rem; }
body .invoice-meta { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }
body .invoice-table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
body .invoice-table th, body .invoice-table td { padding: 0.5rem; text-align: left; border-bottom: 1px solid var(--border); }
body .invoice-total { font-size: 1.1rem; margin-top: 1rem; text-align: right; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header-inner { min-height: auto; padding: 0.85rem 0; }
  .nav { order: 3; width: 100%; border-top: 1px solid var(--border); padding-top: 0.5rem; }
  .header-user { margin-left: 0; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .search-input { max-width: none; }
  .btn-add-page { width: 100%; }
  .table th, .table td { padding: 0.65rem 0.75rem; font-size: 0.9rem; }
  .cart-row { grid-template-columns: 1fr 50px 60px auto; }
  .cart-row .cart-subtotal { display: none; }
  .pos-cart { position: static; }
}

@media (max-width: 480px) {
  .main { padding: 1.25rem; }
  .section { padding: 1.25rem; }
  .card-value { font-size: 1.5rem; }
  .user-name { display: none; }
}

@media print {
  .site-header, .no-print, .main .btn, .main .nav { display: none !important; }
  body { background: #fff; }
}
