/**
 * Modern 2026 Design System
 * Glassmorphism, soft gradients, smooth animations
 */

/* CSS Variables */
:root {
  --primary-500: #6366f1; --primary-600: #4f46e5; --primary-700: #4338ca;
  --success: #10b981; --warning: #f59e0b; --danger: #ef4444; --info: #3b82f6;
  --gray-50: #f9fafb; --gray-100: #f3f4f6; --gray-200: #e5e7eb; --gray-300: #d1d5db;
  --gray-400: #9ca3af; --gray-500: #6b7280; --gray-600: #4b5563; --gray-700: #374151;
  --gray-800: #1f2937; --gray-900: #111827;
  --bg: #f8fafc; --surface: #fff; --surface-hover: #f9fafb;
  --text: #111827; --text-secondary: #6b7280; --text-tertiary: #9ca3af;
  --border: #e5e7eb; --border-subtle: #f3f4f6;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --radius: 10px; --radius-lg: 16px; --radius-xl: 20px; --radius-full: 9999px;
  --transition: 200ms cubic-bezier(0.4,0,0.2,1);
}

@media (prefers-color-scheme: dark) {
  :root { --bg: #0f172a; --surface: #1e293b; --surface-hover: #283548; --text: #f9fafb; --text-secondary: #9ca3af; --border: #374151; }
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

/* Legacy auth page support */
.auth-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); padding: 2rem; box-shadow: var(--shadow-md); }
.auth-wrap h1 { margin-bottom: 1.5rem; font-size: 1.5rem; font-weight: 700; text-align: center; }
.auth-wrap .form-actions { margin-top: 1.5rem; display: flex; gap: 1rem; }
html { font-family: 'Inter', system-ui, sans-serif; font-size: 15px; -webkit-font-smoothing: antialiased; }
body { background: var(--bg); color: var(--text); line-height: 1.6; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { position: fixed; top: 0; left: 0; width: 260px; height: 100vh; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 100; }
.sidebar-header { height: 64px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid var(--border); }
.logo { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.logo-icon { width: 32px; height: 32px; background: linear-gradient(135deg, var(--primary-500), var(--primary-700)); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; }
.sidebar-nav { flex: 1; padding: 16px; overflow-y: auto; }
.nav-section { margin-bottom: 24px; }
.nav-section-title { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-tertiary); padding: 0 12px; margin-bottom: 8px; }
.nav-list { list-style: none; }
.nav-item { margin-bottom: 4px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 8px; color: var(--text-secondary); text-decoration: none; font-weight: 500; font-size: 0.9rem; transition: all var(--transition); position: relative; }
.nav-link::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary-500); transform: scaleY(0); transition: transform var(--transition); border-radius: 0 3px 3px 0; }
.nav-link:hover { background: var(--surface-hover); color: var(--text); }
.nav-link.active { background: rgba(99,102,241,0.1); color: var(--primary-700); }
.nav-link.active::before { transform: scaleY(1); }
.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); }
.user-card { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 8px; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--primary-500), var(--primary-700)); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 0.9rem; }
.user-name { font-weight: 600; font-size: 0.9rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.75rem; color: var(--text-tertiary); }

.main { flex: 1; margin-left: 260px; min-height: 100vh; display: flex; flex-direction: column; }
.top-header { height: 64px; background: rgba(255,255,255,0.9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 50; }
@media (prefers-color-scheme: dark) { .top-header { background: rgba(30,41,59,0.9); } }
.page-title { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--text-secondary); }
.breadcrumb a { color: var(--text-secondary); text-decoration: none; }
.breadcrumb a:hover { color: var(--primary-600); }
.content { flex: 1; padding: 24px; max-width: 1600px; }

/* Containers */
.container { width: 100%; max-width: 1400px; margin: 0 auto; padding: 24px; }
.container--narrow { max-width: 800px; }
.container--wide { max-width: 1600px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: 0 1px 3px rgb(0 0 0 / 0.1); overflow: hidden; transition: all var(--transition); }
.card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.card-elevated { box-shadow: var(--shadow); }
.card-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 1rem; font-weight: 600; color: var(--text); margin: 0; }
.card-body { padding: 24px; }
.card-footer { padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface-hover); display: flex; align-items: center; justify-content: space-between; }

/* Stat Cards */
.card-stat { padding: 24px; position: relative; overflow: hidden; }
.card-stat::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--primary-500), var(--primary-600)); }
.card-stat.success::before { background: linear-gradient(90deg, var(--success), #059669); }
.card-stat.warning::before { background: linear-gradient(90deg, var(--warning), #d97706); }
.card-stat.danger::before { background: linear-gradient(90deg, var(--danger), #dc2626); }
.stat-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-tertiary); margin-bottom: 8px; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--text); line-height: 1.2; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border: none; border-radius: var(--radius); font-family: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; text-decoration: none; transition: all var(--transition); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--primary-600), var(--primary-700)); color: #fff; box-shadow: 0 4px 14px rgba(79,70,229,0.4); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(79,70,229,0.3); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-success { background: linear-gradient(135deg, var(--success), #059669); color: #fff; }
.btn-danger { background: linear-gradient(135deg, var(--danger), #dc2626); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-icon { width: 36px; height: 36px; padding: 0; }

/* Forms */
.form-group { margin-bottom: 20px; }
.form-row { display: flex; gap: 16px; margin-bottom: 20px; }
.form-row .form-group { flex: 1; margin-bottom: 0; }
label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
input, select, textarea { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-family: inherit; font-size: 0.95rem; color: var(--text); background: var(--surface); transition: all var(--transition); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-500); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
input::placeholder { color: var(--text-tertiary); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' 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 12px center; padding-right: 40px; cursor: pointer; }
.search-box { width: 280px; background: var(--gray-50); border-color: transparent; }
.search-box:focus { background: var(--surface); }

/* Tables */
.table-container { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.9rem; }
th { background: var(--gray-50); padding: 14px 18px; text-align: left; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); border-bottom: 1px solid var(--border); }
td { padding: 14px 18px; border-bottom: 1px solid var(--border-subtle); color: var(--text); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-hover); }
.td-numeric { text-align: right; font-variant-numeric: tabular-nums; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary-600); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: var(--radius-full); font-size: 0.75rem; font-weight: 600; }
.badge-primary { background: rgba(99,102,241,0.1); color: var(--primary-700); }
.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-danger { background: rgba(239,68,68,0.1); color: var(--danger); }

/* Alerts */
.alert { padding: 16px 20px; border-radius: var(--radius); border: 1px solid transparent; display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.alert-success { background: rgba(16,185,129,0.1); border-color: rgba(16,185,129,0.2); color: #059669; }
.alert-warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.2); color: #d97706; }
.alert-danger { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.2); color: #dc2626; }
.alert-info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.2); color: #2563eb; }

.flash { padding: 14px 18px; border-radius: var(--radius); margin-bottom: 20px; font-size: 0.9rem; animation: slideIn 0.3s ease-out; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 20px; }
.page-btn { min-width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text-secondary); font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: all var(--transition); }
.page-btn:hover { background: var(--surface-hover); color: var(--text); }
.page-btn.active { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.page-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Grid */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 1024px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* Utilities */
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; } .gap-2 { gap: 8px; } .gap-4 { gap: 16px; }
.text-sm { font-size: 0.875rem; } .text-lg { font-size: 1.125rem; } .font-semibold { font-weight: 600; }
.text-muted { color: var(--text-secondary); } .text-primary { color: var(--primary-600); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Animations */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.animate-fadeInUp { animation: fadeInUp 0.5s ease-out; }
.stagger-1 { animation-delay: 0.05s; } .stagger-2 { animation-delay: 0.1s; } .stagger-3 { animation-delay: 0.15s; }

/* Auth Pages */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg, rgba(99,102,241,0.1) 0%, var(--bg) 100%); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: var(--radius-xl); box-shadow: var(--shadow-md); padding: 32px; }
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo-icon { width: 56px; height: 56px; margin: 0 auto 16px; background: linear-gradient(135deg, var(--primary-500), var(--primary-700)); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 1.5rem; box-shadow: 0 0 20px rgba(99,102,241,0.3); }
.auth-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }

/* Mobile */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.3s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .mobile-menu-btn { display: flex; }
}
@media (max-width: 768px) {
  .content { padding: 16px; }
  .card-header, .card-body { padding: 16px; }
  .page-title { font-size: 1.1rem; }
  th, td { padding: 10px 12px; }
}

/* Legacy Support */
.tag { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: var(--radius-full); font-size: 0.75rem; font-weight: 600; }
.tag-overdue { background: rgba(239,68,68,0.1); color: var(--danger); }
.tag-critical { background: rgba(245,158,11,0.1); color: var(--warning); }
.tag-warning { background: rgba(245,158,11,0.2); color: #b45309; }
.tag-ok { background: rgba(16,185,129,0.1); color: var(--success); }
.toast { position: fixed; bottom: 24px; right: 24px; padding: 14px 18px; border-radius: var(--radius); font-size: 0.9rem; font-weight: 500; z-index: 9999; opacity: 0; transform: translateY(20px); transition: all var(--transition); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { background: rgba(16,185,129,0.1); color: #059669; border: 1px solid rgba(16,185,129,0.2); box-shadow: var(--shadow); }
.toast.err { background: rgba(239,68,68,0.1); color: #dc2626; border: 1px solid rgba(239,68,68,0.2); box-shadow: var(--shadow); }
.product-thumb { width: 120px; height: 120px; object-fit: contain; border-radius: var(--radius); background: var(--gray-50); border: 1px solid var(--border); }
.stat-box { padding: 16px; background: var(--gray-50); border-radius: var(--radius); border: 1px solid var(--border-subtle); }
.stat-box .label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-tertiary); margin-bottom: 6px; }
.stat-box .val { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.top-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.stats-row { display: flex; gap: 16px; flex-wrap: wrap; }
.list-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: none; background: transparent; color: var(--text-secondary); border-radius: var(--radius); cursor: pointer; transition: all var(--transition); }
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.form-delete { margin-top: 24px; padding-top: 24px; border-top: 2px solid var(--border); }
.chart-wrap { position: relative; height: 300px; margin-top: 16px; }
.sync-bar { display: flex; align-items: center; gap: 16px; padding: 16px 20px; background: var(--gray-50); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.table-footer { padding: 16px 20px; border-top: 1px solid var(--border); background: var(--gray-50); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px; }
.no-data { padding: 40px; text-align: center; color: var(--text-tertiary); }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary-500); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
