/* ============================================================
   ValadhuKai - Teal Theme
   ============================================================ */

:root {
  --teal-900: #003d40;
  --teal-800: #00565a;
  --teal-700: #006d73;
  --teal-600: #00838a;
  --teal-500: #009ba3;
  --teal-400: #00b4be;
  --teal-300: #2ecdd6;
  --teal-200: #7de4ea;
  --teal-100: #b8f4f7;
  --teal-50:  #e6fafb;

  --accent-amber: #f59e0b;
  --accent-red:   #ef4444;
  --accent-green: #22c55e;
  --accent-blue:  #3b82f6;
  --accent-orange:#f97316;

  --gray-900: #111827;
  --gray-800: #1f2937;
  --gray-700: #374151;
  --gray-600: #4b5563;
  --gray-500: #6b7280;
  --gray-400: #9ca3af;
  --gray-300: #d1d5db;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50:  #f9fafb;
  --white:    #ffffff;

  --sidebar-width: 260px;
  --header-height: 60px;
  --border-radius: 8px;
  --border-radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.12);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.16);
  --transition: .2s ease;
}

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

html { font-size: 15px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--teal-600); text-decoration: none; }
a:hover { color: var(--teal-800); }

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--teal-900) 0%, var(--teal-800) 100%);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform var(--transition);
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-logo .logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -.5px;
}
.sidebar-logo .logo-sub {
  font-size: .72rem;
  color: var(--teal-200);
  margin-top: 2px;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.sidebar-user {
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-user .avatar {
  width: 36px; height: 36px;
  background: var(--teal-600);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 600; color: var(--white);
  flex-shrink: 0;
}
.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name {
  font-size: .82rem; font-weight: 600; color: var(--white);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user .user-role {
  font-size: .7rem; color: var(--teal-200);
  background: rgba(255,255,255,.1);
  padding: 1px 7px; border-radius: 10px; display: inline-block; margin-top: 2px;
}

.sidebar-nav { flex: 1; padding: 10px 0; }

.nav-section-label {
  font-size: .65rem; font-weight: 600;
  color: var(--teal-300);
  letter-spacing: 1px; text-transform: uppercase;
  padding: 14px 20px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,.75);
  font-size: .85rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
}
.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: var(--white);
  border-left-color: var(--teal-300);
}
.nav-item.active {
  background: rgba(255,255,255,.12);
  color: var(--white);
  border-left-color: var(--teal-300);
  font-weight: 500;
}
.nav-item .nav-icon {
  width: 18px; height: 18px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.nav-item svg { width: 17px; height: 17px; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-footer a {
  display: flex; align-items: center; gap: 8px;
  color: rgba(255,255,255,.65); font-size: .82rem;
  transition: color var(--transition);
}
.sidebar-footer a:hover { color: var(--white); }

/* Header */
.main-header {
  position: fixed;
  top: 0; left: var(--sidebar-width); right: 0;
  height: var(--header-height);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center;
  padding: 0 24px;
  z-index: 90;
  box-shadow: var(--shadow-sm);
  gap: 16px;
}

.hamburger {
  display: none;
  background: none; border: none;
  cursor: pointer; padding: 6px;
  color: var(--gray-600);
}

.page-title {
  font-size: 1rem; font-weight: 600;
  color: var(--gray-800);
  flex: 1;
}

.header-actions { display: flex; align-items: center; gap: 10px; }

/* Main content */
.main-content {
  margin-left: var(--sidebar-width);
  padding-top: var(--header-height);
  min-height: 100vh;
  flex: 1;
}

.page-body {
  padding: 24px;
  max-width: 1400px;
}

/* ============================================================
   COMPONENTS
   ============================================================ */

/* Cards */
.card {
  background: var(--white);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: 12px;
}
.card-title {
  font-size: .95rem; font-weight: 600;
  color: var(--gray-800); flex: 1;
}
.card-body { padding: 20px; }

/* Stat Cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--border-radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: 16px;
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon.teal    { background: var(--teal-50);   color: var(--teal-600); }
.stat-icon.amber   { background: #fffbeb;           color: #d97706; }
.stat-icon.green   { background: #f0fdf4;           color: #16a34a; }
.stat-icon.red     { background: #fef2f2;           color: #dc2626; }
.stat-icon.blue    { background: #eff6ff;           color: #2563eb; }
.stat-icon svg     { width: 24px; height: 24px; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); }
.stat-label { font-size: .78rem; color: var(--gray-500); margin-top: 2px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--border-radius);
  font-size: .85rem; font-weight: 500;
  border: none; cursor: pointer;
  transition: all var(--transition);
  text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

.btn-primary   { background: var(--teal-600); color: var(--white); }
.btn-primary:hover   { background: var(--teal-700); color: var(--white); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-success   { background: var(--accent-green); color: var(--white); }
.btn-success:hover   { background: #16a34a; color: var(--white); }
.btn-danger    { background: var(--accent-red); color: var(--white); }
.btn-danger:hover    { background: #dc2626; color: var(--white); }
.btn-warning   { background: var(--accent-amber); color: var(--white); }
.btn-warning:hover   { background: #d97706; color: var(--white); }
.btn-info      { background: var(--accent-blue); color: var(--white); }
.btn-sm  { padding: 5px 11px; font-size: .78rem; }
.btn-lg  { padding: 11px 22px; font-size: .95rem; }
.btn-icon { padding: 7px; }

.btn-outline-teal {
  background: transparent;
  color: var(--teal-600);
  border: 1.5px solid var(--teal-500);
}
.btn-outline-teal:hover { background: var(--teal-600); color: var(--white); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; gap: 16px; margin-bottom: 16px; }
.form-row.cols-2 { grid-template-columns: repeat(2, 1fr); }
.form-row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-row.cols-4 { grid-template-columns: repeat(4, 1fr); }
.form-row.cols-5 { grid-template-columns: repeat(5, 1fr); }
.form-row.cols-6 { grid-template-columns: repeat(6, 1fr); }

label {
  display: block;
  font-size: .8rem; font-weight: 500;
  color: var(--gray-600); margin-bottom: 5px;
}
label .required { color: var(--accent-red); margin-left: 2px; }

input[type="text"], input[type="number"], input[type="email"],
input[type="tel"], input[type="date"], input[type="password"],
input[type="search"], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--border-radius);
  font-size: .85rem;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px rgba(0,155,163,.12);
}
input[readonly], input[disabled] {
  background: var(--gray-50);
  color: var(--gray-500);
  cursor: not-allowed;
}
select { cursor: pointer; }
textarea { resize: vertical; min-height: 80px; }

.input-group { display: flex; }
.input-group input { border-radius: var(--border-radius) 0 0 var(--border-radius); }
.input-group .btn { border-radius: 0 var(--border-radius) var(--border-radius) 0; }

.field-error { font-size: .75rem; color: var(--accent-red); margin-top: 4px; }
.form-hint   { font-size: .75rem; color: var(--gray-500); margin-top: 4px; }

/* Toggle / Switch */
.toggle-wrapper { display: flex; align-items: center; gap: 10px; }
.toggle {
  position: relative; display: inline-block;
  width: 42px; height: 24px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer;
  inset: 0; background: var(--gray-300);
  border-radius: 24px; transition: .3s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; bottom: 3px;
  background: var(--white);
  border-radius: 50%; transition: .3s;
  box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle-slider { background: var(--teal-500); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }
.toggle-label { font-size: .85rem; color: var(--gray-700); font-weight: 500; }

/* Tables */
.table-wrapper { overflow-x: auto; }
table {
  width: 100%; border-collapse: collapse;
  font-size: .83rem;
}
thead th {
  background: var(--gray-50);
  padding: 10px 12px;
  text-align: left;
  font-size: .75rem; font-weight: 600;
  color: var(--gray-500); letter-spacing: .5px;
  text-transform: uppercase;
  border-bottom: 1.5px solid var(--gray-200);
  white-space: nowrap;
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); }

.tfoot-total td {
  padding: 10px 12px;
  border-top: 2px solid var(--gray-200);
  font-weight: 600; color: var(--gray-800);
  background: var(--gray-50);
}

/* Badges */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 20px;
  font-size: .72rem; font-weight: 600; letter-spacing: .3px;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-teal    { background: var(--teal-50); color: var(--teal-800); }
.badge-gray    { background: var(--gray-100); color: var(--gray-600); }

/* Alerts */
.alert {
  padding: 12px 16px; border-radius: var(--border-radius);
  margin-bottom: 16px; font-size: .85rem;
  display: flex; align-items: flex-start; gap: 10px;
}
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger  { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* 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: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--white);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px);
  transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-sm  { max-width: 440px; }
.modal-md  { max-width: 640px; }
.modal-lg  { max-width: 900px; }
.modal-xl  { max-width: 1100px; }
.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: 12px;
}
.modal-title { font-size: 1rem; font-weight: 600; flex: 1; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--gray-400); padding: 4px;
  border-radius: 6px; transition: color var(--transition);
}
.modal-close:hover { color: var(--gray-700); }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--gray-200);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* Toast notifications */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 2000; display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--gray-900);
  color: var(--white);
  padding: 12px 18px; border-radius: var(--border-radius);
  font-size: .85rem; min-width: 280px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  animation: slideInRight .25s ease forwards;
}
.toast.success { background: #166534; }
.toast.error   { background: #991b1b; }
.toast.warning { background: #92400e; }
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}

/* Page toolbar */
.page-toolbar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.page-toolbar-left { flex: 1; display: flex; gap: 10px; flex-wrap: wrap; }
.page-toolbar-right { display: flex; gap: 10px; flex-wrap: wrap; }

/* Search input */
.search-input {
  position: relative; min-width: 240px;
}
.search-input svg {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--gray-400);
}
.search-input input { padding-left: 34px; }

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  background: linear-gradient(135deg, var(--teal-900) 0%, var(--teal-700) 50%, var(--teal-600) 100%);
}
.login-art {
  flex: 1; display: none;
  align-items: center; justify-content: center;
  padding: 40px;
}
.login-art svg { width: 300px; opacity: .2; }
.login-panel {
  width: 420px; flex-shrink: 0;
  background: var(--white);
  display: flex; align-items: center; justify-content: center;
  padding: 48px 40px;
}
.login-form-wrap { width: 100%; }
.login-logo { margin-bottom: 32px; }
.login-logo h1 { font-size: 1.7rem; font-weight: 800; color: var(--teal-700); }
.login-logo p { font-size: .82rem; color: var(--gray-500); margin-top: 4px; }
.login-submit { width: 100%; margin-top: 8px; padding: 11px; font-size: .95rem; }

/* Items table in forms */
.items-table-wrap {
  border: 1.5px solid var(--gray-200);
  border-radius: var(--border-radius);
  overflow: hidden; margin-bottom: 16px;
}
.items-table {
  width: 100%; border-collapse: collapse;
  font-size: .82rem;
}
.items-table th {
  background: var(--teal-900);
  color: var(--white);
  padding: 9px 10px;
  text-align: left; font-weight: 500;
  font-size: .75rem; white-space: nowrap;
}
.items-table td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
.items-table tr:last-child td { border-bottom: none; }
.items-table input, .items-table select {
  padding: 5px 7px; font-size: .8rem; min-width: 0;
}
.items-table .col-action { width: 36px; text-align: center; }
.items-table .col-num    { width: 44px; }
.items-table .col-barcode{ min-width: 130px; }
.items-table .col-qty    { width: 80px; }
.items-table .col-rate   { width: 90px; }
.items-table .col-disc   { width: 70px; }
.items-table .col-gst    { width: 70px; }
.items-table .col-calc   { width: 90px; }
.items-table .col-mrp    { width: 90px; }
.items-table .col-margin { width: 80px; }

.add-row-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: var(--teal-50); color: var(--teal-700);
  border: 1.5px dashed var(--teal-300);
  border-radius: var(--border-radius);
  font-size: .82rem; font-weight: 500;
  cursor: pointer; width: 100%;
  justify-content: center; margin-bottom: 16px;
  transition: all var(--transition);
}
.add-row-btn:hover { background: var(--teal-100); border-color: var(--teal-500); }
.add-row-btn svg { width: 16px; height: 16px; }

/* Summary totals */
.totals-panel {
  background: var(--gray-50);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--border-radius);
  padding: 16px 20px;
  min-width: 280px;
  margin-left: auto;
}
.total-row {
  display: flex; justify-content: space-between;
  align-items: center; padding: 5px 0;
  font-size: .85rem; color: var(--gray-600);
  border-bottom: 1px solid var(--gray-200);
}
.total-row:last-child {
  border-bottom: none; padding-top: 10px; margin-top: 6px;
  font-size: 1rem; font-weight: 700; color: var(--gray-900);
}
.total-row span:last-child { font-weight: 600; color: var(--gray-800); }

/* Margin warning */
.margin-warn { color: var(--accent-red); font-weight: 600; }
.margin-ok   { color: var(--accent-green); }

/* Pagination */
.pagination {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 4px; padding: 14px 20px;
  border-top: 1px solid var(--gray-200);
}
.page-btn {
  min-width: 32px; height: 32px; padding: 0 8px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  background: var(--white); color: var(--gray-700);
  font-size: .8rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.page-btn:hover { border-color: var(--teal-400); color: var(--teal-600); }
.page-btn.active { background: var(--teal-600); color: var(--white); border-color: var(--teal-600); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Print styles */
.print-bill {
  font-family: 'Courier New', monospace;
  width: 80mm; margin: 0 auto;
  font-size: 12px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--gray-100); }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .form-row.cols-6 { grid-template-columns: repeat(3, 1fr); }
  .form-row.cols-5 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .sidebar-overlay.open { display: block; }
  .main-content { margin-left: 0; }
  .main-header { left: 0; }
  .hamburger { display: flex; }
  .page-body { padding: 16px; }
  .form-row.cols-4,
  .form-row.cols-3 { grid-template-columns: repeat(2, 1fr); }
  .form-row.cols-6,
  .form-row.cols-5 { grid-template-columns: repeat(2, 1fr); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .login-panel { width: 100%; }
  .totals-panel { min-width: 100%; }
}

@media (max-width: 480px) {
  .form-row.cols-2,
  .form-row.cols-3,
  .form-row.cols-4 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr; }
  .page-toolbar { flex-direction: column; align-items: stretch; }
  .page-toolbar-right { justify-content: flex-end; }
}

/* Smart TV / Large screens */
@media (min-width: 1920px) {
  :root { font-size: 16px; }
  .page-body { max-width: 1600px; }
}

/* PWA standalone */
@media (display-mode: standalone) {
  .main-header { padding-top: env(safe-area-inset-top, 0); }
}
