/* 
  Kiryana Store Manager Design System
  A professional, responsive, and elegant UI
*/

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Core variables and reset */
:root {
  /* Primary colors */
  --primary: #4361ee;
  --primary-light: #5e72f0;
  --primary-dark: #3854d1;
  
  /* Secondary colors */
  --secondary: #2ec4b6;
  --secondary-light: #38ead8;
  --secondary-dark: #25a094;
  
  /* Surface colors */
  --bg: #f8fafc;
  --surface-0: #ffffff;
  --surface-1: #f1f5f9;
  --surface-2: #e2e8f0;
  
  /* Text colors */
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-tertiary: #64748b;
  --text-inverse: #ffffff;
  
  /* Status colors */
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;
  
  /* Layout */
  --header-h: 64px;
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  
  /* Effects */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition: 0.2s ease;
  --transition-slow: 0.3s ease;
}

/* Dark theme overrides */
.theme-dark {
  /* Surface colors */
  --bg: #0f172a;
  --surface-0: #1e293b;
  --surface-1: #334155;
  --surface-2: #475569;
  
  /* Text colors */
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-tertiary: #94a3b8;
  
  /* Adapted colors */
  --primary-light: #6476ff;
  --secondary-light: #44ffe6;
}

/* Base styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  margin: 0 0 1rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
}

h1 { font-size: 1.875rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--primary-light);
}

small {
  font-size: 0.875rem;
  color: var(--text-tertiary);
}

/* Header */
.app-header {
  height: var(--header-h);
  background: var(--surface-0);
  border-bottom: 1px solid var(--surface-2);
  position: sticky;
  top: 0;
  width: 100%;
  z-index: 40;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  transition: transform var(--transition-slow), box-shadow var(--transition);
}

.header-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
}

.brand a {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand a:hover {
  color: var(--primary-light);
}

/* Logo icon */
.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
}

/* Search */
.header-search {
  flex: 1;
  max-width: 28rem;
  margin: 0 1rem;
}

.search-input {
  width: 100%;
  height: 2.5rem;
  padding: 0 1rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--surface-2);
  background: var(--surface-1);
  color: var(--text-primary);
  transition: all var(--transition);
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-light);
  background: var(--surface-0);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

/* Header actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Buttons */
.btn,
.btn-ghost,
.btn-outline,
.btn-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2.5rem;
  padding: 0 1rem;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  white-space: nowrap;
}

.btn {
  background: var(--primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

.btn:hover {
  background: var(--primary-light);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-sm {
  height: 2rem;
  padding: 0 0.75rem;
  font-size: 0.75rem;
}

.btn-lg {
  height: 3rem;
  padding: 0 1.5rem;
  font-size: 1rem;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--surface-1);
  color: var(--text-primary);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--surface-2);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-text {
  background: transparent;
  color: var(--text-secondary);
  height: auto;
  padding: 0;
}

.btn-text:hover {
  color: var(--text-primary);
}

/* Button variations */
.btn-success {
  background: var(--success);
}

.btn-success:hover {
  background: color-mix(in srgb, var(--success), white 10%);
}

.btn-error {
  background: var(--error);
}

.btn-error:hover {
  background: color-mix(in srgb, var(--error), white 10%);
}

.btn-warning {
  background: var(--warning);
}

.btn-warning:hover {
  background: color-mix(in srgb, var(--warning), white 10%);
}

/* Layout with sidebar */
.app-layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

.sidebar {
  width: 260px;
  background: var(--surface-0);
  border-right: 1px solid var(--surface-2);
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow: auto;
  padding: 1.25rem 1rem;
  transition: all var(--transition-slow);
  z-index: 70; /* sidebar above overlay, below modals */
}

.sidebar-header {
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--surface-2);
}

.sidebar .nav {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.sidebar .nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-weight: 500;
  transition: all var(--transition);
  position: relative;
}

.sidebar .nav a:hover {
  background: var(--surface-1);
  color: var(--text-primary);
}

.sidebar .nav a.active {
  background: var(--primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

.sidebar .nav a .icon {
  width: 1.25rem;
  height: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.75;
}

.sidebar .nav a.active .icon {
  opacity: 1;
}

.sidebar .nav a span.label {
  transition: opacity var(--transition);
}

/* Collapsed sidebar */
.sidebar.collapsed {
  width: 70px;
  padding: 1.25rem 0.5rem;
}

.sidebar.collapsed .sidebar-header {
  text-align: center;
  padding-bottom: 0.75rem;
}

.sidebar.collapsed .nav a {
  justify-content: center;
  padding: 0.75rem;
}

.sidebar.collapsed .nav a span.label {
  display: none;
  opacity: 0;
}

/* Main content */
.main {
  flex: 1;
  padding: 1.5rem;
  background: var(--bg);
  min-height: calc(100vh - var(--header-h));
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

/* Card */
.card {
  background: var(--surface-0);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  transition: box-shadow var(--transition), transform var(--transition);
  border: 1px solid var(--surface-1);
}

.card-hover:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.card-body {
  color: var(--text-secondary);
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--surface-1);
}

/* Dashboard widgets */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.widget {
  background: var(--surface-0);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--surface-1);
  position: relative;
  overflow: hidden;
}

.widget-icon {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: rgba(67, 97, 238, 0.1);
  color: var(--primary);
}

.widget h3 {
  font-size: 0.875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
  margin-bottom: 1rem;
}

.widget .value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.widget .sub {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

.widget-success .widget-icon { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.widget-warning .widget-icon { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.widget-error .widget-icon { background: rgba(239, 68, 68, 0.1); color: var(--error); }
.widget-info .widget-icon { background: rgba(59, 130, 246, 0.1); color: var(--info); }

/* Tables */
.table-container {
  overflow-x: auto;
  margin: 1.25rem 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--surface-2);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0.875rem 1.5rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--surface-2);
}

td {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--surface-1);
  color: var(--text-primary);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr {
  transition: background-color var(--transition);
}

tbody tr:hover {
  background-color: var(--surface-1);
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem;
  color: var(--text-tertiary);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  color: var(--text-tertiary);
  opacity: 0.5;
}

/* Form elements */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text-primary);
}

.form-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--surface-0);
  background-clip: padding-box;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus {
  border-color: var(--primary);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

textarea.form-input {
  min-height: 100px;
  resize: vertical;
}

select.form-input {
  padding-right: 2rem;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 1rem;
}

/* Form layout */
.form-row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -0.75rem;
  margin-left: -0.75rem;
}

.form-col {
  flex: 1 0 0%;
  padding-right: 0.75rem;
  padding-left: 0.75rem;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1;
  border-radius: var(--radius-full);
  background: var(--surface-1);
  color: var(--text-secondary);
}

.badge-success { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.badge-error { background: rgba(239, 68, 68, 0.1); color: var(--error); }
.badge-info { background: rgba(59, 130, 246, 0.1); color: var(--info); }
.badge-primary { background: rgba(67, 97, 238, 0.1); color: var(--primary); }

/* Auth pages */
.auth-card {
  max-width: 28rem;
  margin: 4rem auto;
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  background: var(--surface-0);
  border: 1px solid var(--surface-1);
}

.auth-logo {
  margin-bottom: 2rem;
  display: flex;
  justify-content: center;
}

.auth-heading {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  text-align: center;
}

.auth-form .form-group:last-child {
  margin-bottom: 0;
}

.auth-footer {
  margin-top: 1.5rem;
  text-align: center;
}

/* Mobile menu overlay */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 60; /* below sidebar (70) but above header (40); modals will be above */
  display: none;
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity var(--transition);
}

.overlay.show {
  display: block;
  opacity: 1;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90; /* ensure modal is the topmost layer */
  padding: 1rem;
}
.modal.show {
  display: flex;
}
.modal .modal-content,
.modal .card {
  width: 100%;
  max-width: 720px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl);
  background: var(--surface-0);
  border: 1px solid var(--surface-1);
  overflow: hidden;
}
.modal .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--surface-1);
}
.modal .modal-body {
  padding: 1rem 1.25rem;
}
.modal .modal-close {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-secondary);
}

/* ensure overlay visible z-index > header */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 50;
  display: none;
  opacity: 0;
  transition: opacity var(--transition);
}
.overlay.show {
  display: block;
  opacity: 1;
}

/* Loader */
.loader {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--surface-2);
  border-radius: 50%;
  border-top-color: var(--primary);
  animation: spin 1s infinite linear;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Helper classes */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-lg { font-size: 1.125rem; }
.flex-wrap { flex-wrap: wrap; }

/* Responsive */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    left: -280px;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    left: 0;
  }
  
  .header-search {
    display: none;
  }
}

@media (max-width: 767px) {
  .main {
    padding: 1rem;
  }
  
  /* allow header-row content to wrap on narrow screens to avoid horizontal scroll */
  .header-row {
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
  }
  
  .widget-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .card {
    padding: 1rem;
  }
  
  .auth-card {
    margin: 2rem 1rem;
    padding: 1.5rem;
  }
  
  .form-row {
    flex-direction: column;
    gap: 0; /* Reset gap for column layout */
  }
  
  .form-col {
    margin-bottom: 1rem;
    padding-right: 0;
    padding-left: 0;
  }
  
  .form-col:last-child {
    margin-bottom: 0;
  }
  
  th, td {
    padding: 0.75rem;
    font-size: 0.875rem; /* Slightly smaller font in tables on mobile */
  }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }

  .app-header {
    padding: 0 1rem;
  }

  .header-actions .btn-outline span {
    display: none;
  }

  .header-actions .btn-outline {
    padding: 0;
    width: 2.5rem;
    justify-content: center;
  }

  .flex.justify-between.items-center {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  /* Utility to hide elements on mobile */
  .hide-on-mobile {
    display: none;
  }

  /* POS layout adjustments */
  #posLayout {
    flex-direction: column;
  }
  #posLayout aside {
    width: 100% !important;
  }
  .cart-summary {
    position: static;
  }
}

/* sidebar toggle button */
#sidebarToggle {
  font-size: 1.25rem;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--surface-2);
  cursor: pointer;
  transition: all var(--transition);
}

#sidebarToggle:hover {
  background: var(--surface-1);
  color: var(--text-primary);
}

/* Theme toggle button */
#themeToggle {
  font-size: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--surface-2);
  cursor: pointer;
  transition: all var(--transition);
}

#themeToggle:hover {
  background: var(--surface-1);
  color: var(--text-primary);
}

/* Page transitions */
.page-enter {
  opacity: 0;
  transform: translateY(10px);
}

.page-enter-active {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 300ms, transform 300ms;
}
