@import url('./variables.css');

/* ==========================================================================
   RESET & CORE BASE STYLES
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ==========================================================================
   LAYOUT STRUCTURE
   ========================================================================== */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ==========================================================================
   DARK HIGH-CONTRAST SIDEBAR
   ========================================================================== */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: var(--transition);
  z-index: 40;
}

.sidebar-header {
  height: var(--topbar-height);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-icon {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.brand-text h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #ffffff;
  line-height: 1.2;
}

.brand-text span {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #2dd4bf;
  font-weight: 700;
  display: block;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-section-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  padding: 0.85rem 0.75rem 0.3rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.nav-item:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.06);
}

.nav-item.active {
  color: #ffffff;
  background: rgba(13, 148, 136, 0.22);
  border-left: 3px solid var(--primary);
  font-weight: 600;
}

.nav-item i {
  font-size: 1.1rem;
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-badge {
  margin-left: auto;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
}

.nav-badge.warning {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}

.nav-badge.danger {
  background: rgba(244, 63, 94, 0.2);
  color: #fda4af;
}

.sidebar-footer {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--sidebar-border);
  background: #090d16;
}

.store-status-card {
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.store-status-dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 6px #10b981;
}

.store-status-info h4 {
  font-size: 0.78rem;
  font-weight: 600;
  color: #f8fafc;
}

.store-status-info p {
  font-size: 0.68rem;
  color: #94a3b8;
}

/* ==========================================================================
   TOPBAR HEADER (Compact & Single-Line Sleek)
   ========================================================================== */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background-color: var(--bg-app);
}

.topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  max-height: var(--topbar-height);
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  z-index: 30;
  box-shadow: var(--shadow-xs);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  overflow: hidden;
  flex-shrink: 1;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
}

.topbar-title h2 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.store-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: #f8fafc;
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.store-selector-wrapper:hover {
  border-color: var(--primary);
  background: #ffffff;
}

.store-selector-wrapper i {
  color: var(--primary);
  font-size: 0.95rem;
}

.store-select {
  background: transparent;
  border: none;
  font-size: 0.82rem;
  font-weight: 600;
  color: #0f172a;
  outline: none;
  cursor: pointer;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* Role Selector Badge Switcher */
.role-badge-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.32rem 0.65rem;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-full);
  color: #15803d;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.role-badge-btn select {
  background: transparent;
  border: none;
  color: #15803d;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  font-size: 0.76rem;
}

/* Compact Buttons */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 6px var(--primary-glow);
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.28);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #ffffff;
  border: 1px solid var(--border-color-strong);
  color: var(--text-secondary);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-secondary:hover {
  background: #f8fafc;
  color: var(--text-primary);
  border-color: #94a3b8;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding-left: 0.65rem;
  border-left: 1px solid var(--border-color);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0d9488, #0284c7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
  color: white;
}

.user-meta {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.2;
}

.user-role-label {
  font-size: 0.68rem;
  color: var(--primary);
  font-weight: 600;
}

/* ==========================================================================
   PAGE CONTENT VIEWPORT
   ========================================================================== */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.view-panel {
  display: none;
  animation: fadeIn 0.2s ease-out;
}

.view-panel.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   METRIC & KPI CARDS
   ========================================================================== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.15rem;
}

.metric-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  transition: var(--transition);
}

.metric-card:hover {
  transform: translateY(-2px);
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-accent, var(--primary));
}

.metric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.metric-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.metric-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.metric-value {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-family: var(--font-mono);
  color: #0f172a;
  line-height: 1.15;
}

.metric-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.trend-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-weight: 700;
  font-size: 0.68rem;
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-xs);
}

.trend-badge.positive {
  background: #dcfce7;
  color: #15803d;
}

.trend-badge.warning {
  background: var(--accent-amber-light);
  color: #b45309;
}

.trend-badge.danger {
  background: var(--accent-rose-light);
  color: var(--accent-rose);
}

/* ==========================================================================
   CARDS, PANELS & TABLES
   ========================================================================== */
.card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.35rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  box-shadow: var(--shadow-xs);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: #0f172a;
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.grid-2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.25rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

@media (max-width: 1024px) {
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
}

/* Data Table */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table th {
  background: #f8fafc;
  color: #475569;
  text-transform: uppercase;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: #0f172a;
  vertical-align: middle;
}

.data-table tbody tr {
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 600;
}

.badge-h1 {
  background: var(--accent-rose-light);
  color: #be123c;
  border: 1px solid #fecdd3;
}

.badge-h {
  background: var(--accent-amber-light);
  color: #b45309;
  border: 1px solid #fde68a;
}

.badge-general {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.badge-success {
  background: #dcfce7;
  color: #15803d;
}

.badge-warning {
  background: var(--accent-amber-light);
  color: #b45309;
}

.badge-danger {
  background: var(--accent-rose-light);
  color: #be123c;
}

.badge-info {
  background: var(--accent-cyan-light);
  color: #0369a1;
}

/* Compact Filter Bar & Search */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.search-input-box {
  position: relative;
  min-width: 280px;
}

.search-input-box i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: 0.95rem;
}

.search-input-box input {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem 0.45rem 2.2rem;
  color: var(--text-primary);
  outline: none;
  font-size: 0.82rem;
  height: 35px;
  transition: var(--transition);
}

.search-input-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.select-filter {
  background: #ffffff;
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  color: var(--text-primary);
  font-size: 0.82rem;
  height: 35px;
  outline: none;
  cursor: pointer;
}

.action-btn-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
}

.icon-btn:hover {
  background: #e2e8f0;
  color: var(--text-primary);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: scale(0.96);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.35rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  background: #f8fafc;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #334155;
}

.form-input, .form-select, .form-textarea {
  background: #ffffff;
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  color: var(--text-primary);
  font-size: 0.82rem;
  outline: none;
  transition: var(--transition);
}

.form-input:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  z-index: 200;
  pointer-events: none;
}

.toast {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: #0f172a;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: slideInRight 0.2s ease-out;
  min-width: 260px;
}

.toast.success { border-left: 4px solid var(--accent-emerald); }
.toast.warning { border-left: 4px solid var(--accent-amber); }
.toast.danger { border-left: 4px solid var(--accent-rose); }

.toast-message {
  font-size: 0.8rem;
  font-weight: 600;
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Branch Cards Grid */
.branch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.branch-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow-xs);
  transition: var(--transition);
}

.branch-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
}

.branch-code {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--primary);
  font-weight: 700;
}

.branch-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-secondary);
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 0.35rem;
}

.branch-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  background: #f8fafc;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.branch-stat-item p {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.branch-stat-item h5 {
  font-size: 0.95rem;
  font-family: var(--font-mono);
  font-weight: 700;
}
