/* ============================================
   StockPilot — Main Stylesheet
   ============================================ */

:root {
  --bg:          #0f1117;
  --bg-2:        #161b27;
  --bg-3:        #1e2538;
  --border:      #2a3148;
  --border-light:#353d58;
  --text:        #e2e8f8;
  --text-muted:  #7a8aab;
  --text-dim:    #4a5578;
  --accent:      #6366f1;
  --accent-h:    #818cf8;
  --accent-dim:  rgba(99,102,241,.15);
  --green:       #10b981;
  --green-dim:   rgba(16,185,129,.15);
  --red:         #ef4444;
  --red-dim:     rgba(239,68,68,.15);
  --yellow:      #f59e0b;
  --yellow-dim:  rgba(245,158,11,.15);
  --sidebar-w:   240px;
  --topbar-h:    56px;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);
  --font:        'Space Grotesk', sans-serif;
  --mono:        'JetBrains Mono', monospace;
  --transition:  .18s cubic-bezier(.4,0,.2,1);
}

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

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  line-height: 1.5;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  letter-spacing: -.02em;
}

.logo-icon {
  font-size: 1.5rem;
  color: var(--accent);
  line-height: 1;
}

.sidebar-nav {
  list-style: none;
  padding: 12px 10px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: .9rem;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
}

.nav-item:hover { background: var(--bg-3); color: var(--text); }

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent-h);
}

.nav-item.active svg { stroke: var(--accent-h); }

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1.5px solid var(--accent);
  color: var(--accent-h);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}

.user-details { display: flex; flex-direction: column; overflow: hidden; }
.user-name { font-weight: 600; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

/* Role badges */
.badge-admin   { color: var(--accent-h); }
.badge-manager { color: var(--yellow); }
.badge-viewer  { color: var(--green); }

/* ============================================
   MAIN WRAPPER
   ============================================ */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ============================================
   TOPBAR
   ============================================ */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 90;
}

.sidebar-toggle {
  background: none; border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: color var(--transition), background var(--transition);
  display: none;
}

.sidebar-toggle:hover { color: var(--text); background: var(--bg-3); }

.topbar-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* Settings dropdown */
.settings-dropdown { position: relative; }

.btn-settings {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .85rem;
  font-family: var(--font);
  font-weight: 500;
  transition: all var(--transition);
}

.btn-settings:hover { border-color: var(--accent); color: var(--accent-h); }

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 220px;
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 200;
}

.dropdown-menu.open { display: block; animation: fadeDown .15s ease; }

@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.dropdown-item:hover { background: var(--border); color: var(--text); }

.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  background: var(--red-dim);
  color: var(--red);
  text-decoration: none;
  transition: background var(--transition);
}
.btn-logout:hover { background: var(--red); color: #fff; }

/* ============================================
   FLASH MESSAGES
   ============================================ */
.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  font-weight: 500;
  font-size: .9rem;
}

.flash button {
  background: none; border: none;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0 4px;
}

.flash-success { background: var(--green-dim); color: var(--green); }
.flash-success button { color: var(--green); }
.flash-error   { background: var(--red-dim); color: var(--red); }
.flash-error button { color: var(--red); }
.flash-warning { background: var(--yellow-dim); color: var(--yellow); }

/* ============================================
   CONTENT AREA
   ============================================ */
.content { padding: 28px 32px; flex: 1; }

/* ============================================
   CARDS & STATS
   ============================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color var(--transition);
}

.stat-card:hover { border-color: var(--border-light); }
.stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .8rem; color: var(--text-muted); }

.stat-card.accent .stat-value { color: var(--accent-h); }
.stat-card.green  .stat-value { color: var(--green); }
.stat-card.yellow .stat-value { color: var(--yellow); }
.stat-card.red    .stat-value { color: var(--red); }

/* ============================================
   TABLE
   ============================================ */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-title { font-weight: 700; font-size: .95rem; }
.card-actions { margin-left: auto; display: flex; gap: 8px; }

.table-responsive { overflow-x: auto; }

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

thead th {
  background: var(--bg-3);
  padding: 10px 16px;
  text-align: left;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-3); }

tbody td { padding: 12px 16px; color: var(--text); vertical-align: middle; }

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  font-size: .85rem;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: var(--accent-h); }
.btn-secondary{ background: var(--bg-3); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--border-light); }
.btn-danger   { background: var(--red-dim); color: var(--red); border: 1px solid transparent; }
.btn-danger:hover   { background: var(--red); color: #fff; }
.btn-success  { background: var(--green-dim); color: var(--green); border: 1px solid transparent; }
.btn-success:hover  { background: var(--green); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-icon { padding: 6px; width: 30px; height: 30px; justify-content: center; }

/* ============================================
   BADGES
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge-in     { background: var(--green-dim); color: var(--green); }
.badge-out    { background: var(--red-dim); color: var(--red); }
.badge-adjustment { background: var(--yellow-dim); color: var(--yellow); }
.badge-initial{ background: var(--accent-dim); color: var(--accent-h); }
.badge-low    { background: var(--red-dim); color: var(--red); }
.badge-ok     { background: var(--green-dim); color: var(--green); }

/* ============================================
   FORMS
   ============================================ */
.form-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 720px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: .9rem;
  padding: 9px 12px;
  width: 100%;
  transition: border-color var(--transition);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

textarea { min-height: 90px; resize: vertical; }

select option { background: var(--bg-3); }

.form-hint { font-size: .78rem; color: var(--text-dim); }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* Checkbox */
.checkbox-group { display: flex; align-items: center; gap: 8px; }
.checkbox-group input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.checkbox-group label { text-transform: none; letter-spacing: 0; font-size: .9rem; color: var(--text); }

/* ============================================
   SEARCH / FILTERS
   ============================================ */
.filters-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.search-input {
  flex: 1;
  min-width: 200px;
  max-width: 360px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  color: var(--text);
  font-family: var(--font);
  font-size: .9rem;
  outline: none;
  transition: border-color var(--transition);
}

.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-dim); }

.filter-select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: .88rem;
  outline: none;
  cursor: pointer;
}

/* ============================================
   PAGINATION
   ============================================ */
.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  padding: 16px;
  border-top: 1px solid var(--border);
}

.page-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-muted);
  background: var(--bg-3);
  border: 1px solid var(--border);
  transition: all var(--transition);
  padding: 0 8px;
}

.page-link:hover, .page-link.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ============================================
   COLOR DOT / GROUP INDICATOR
   ============================================ */
.group-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.group-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}

/* ============================================
   STOCK INDICATOR
   ============================================ */
.stock-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stock-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
  min-width: 60px;
}

.stock-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .3s;
}

.stock-qty { font-family: var(--mono); font-size: .85rem; white-space: nowrap; }

/* ============================================
   LOGIN PAGE
   ============================================ */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  min-height: 100vh;
}

.login-box {
  width: 100%;
  max-width: 400px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .logo-icon { font-size: 2.5rem; display: block; color: var(--accent); }
.login-logo h1 { font-size: 1.4rem; font-weight: 700; margin-top: 8px; }
.login-logo p { color: var(--text-muted); font-size: .88rem; margin-top: 4px; }

.login-error {
  background: var(--red-dim);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .88rem;
  font-weight: 500;
  margin-bottom: 20px;
}

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state svg { opacity: .3; margin-bottom: 12px; }
.empty-state h3 { font-size: 1rem; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: .88rem; }

/* ============================================
   PAGE HEADER
   ============================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
}

/* ============================================
   MOVEMENT TYPE LABELS
   ============================================ */
.movement-in  { color: var(--green); }
.movement-out { color: var(--red); }
.movement-adj { color: var(--yellow); }

/* ============================================
   SETTINGS TABS
   ============================================ */
.settings-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 24px;
  width: fit-content;
}

.tab-link {
  padding: 7px 18px;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}

.tab-link.active, .tab-link:hover { background: var(--bg-2); color: var(--text); }
.tab-link.active { color: var(--accent-h); }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-wrapper { margin-left: 0; }
  .sidebar-toggle { display: flex; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================
   MISC UTILITIES
   ============================================ */
.text-muted  { color: var(--text-muted); }
.text-mono   { font-family: var(--mono); }
.text-sm     { font-size: .82rem; }
.flex        { display: flex; }
.items-center{ align-items: center; }
.gap-2       { gap: 8px; }
.gap-1       { gap: 4px; }
.mt-1        { margin-top: 8px; }
.mb-0        { margin-bottom: 0; }
.w-full      { width: 100%; }
.hidden      { display: none; }
