:root {
  --primary: #1e40af;
  --primary-dark: #17337f;
  --primary-soft: #dde1ff;
  --primary-soft-text: #1e3a8a;
  --on-primary: #ffffff;
  --bg: #f7f9fb;
  --surface: #ffffff;
  --surface-alt: #f2f4f6;
  --surface-hover: #eceef0;
  --border: #e0e3e5;
  --border-strong: #c4c5d5;
  --text: #191c1e;
  --text-muted: #505f76;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --radius-card: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 24, 32, 0.05), 0 8px 20px rgba(20, 24, 32, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.material-symbols-outlined {
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  vertical-align: middle;
  line-height: 1;
}

a {
  color: var(--primary);
}

/* ---------- App shell: sidebar + topbar ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface-alt);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 22px;
}

.sidebar .brand .material-symbols-outlined {
  color: var(--primary);
  font-size: 30px;
}

.sidebar .brand h1 {
  font-size: 1.05rem;
  margin: 0;
  color: var(--primary);
}

.sidebar .brand p {
  margin: 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}

.sidebar nav button:hover {
  background: var(--surface-hover);
}

.sidebar nav button.active {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-weight: 600;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.sidebar-footer .who .name {
  font-size: 0.85rem;
  font-weight: 600;
}

.sidebar-footer .who .role {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.sidebar-footer .logout-btn {
  margin-left: auto;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.sidebar-footer .logout-btn:hover {
  background: var(--surface-hover);
  color: var(--error-text);
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h2 {
  margin: 0;
  font-size: 1.3rem;
}

.topbar .subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
}

.search-box .material-symbols-outlined {
  color: var(--text-muted);
  font-size: 20px;
}

.search-box input {
  border: none;
  background: none;
  outline: none;
  font-family: inherit;
  font-size: 0.88rem;
  width: 100%;
  color: var(--text);
}

.page-content {
  padding: 28px;
  flex: 1;
}

/* ---------- Generic surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}

.card h2, .card h3 {
  margin-top: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; }
}

/* ---------- Stat tiles ---------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 720px) {
  .stat-row { grid-template-columns: 1fr; }
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 20px;
}

.stat-tile .top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}

.stat-tile .label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-tile .icon-chip {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-tile .value {
  font-size: 1.8rem;
  font-weight: 700;
}

/* ---------- Tables ---------- */

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

th, td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface-alt);
}

tbody tr:hover {
  background: var(--surface-alt);
}

.name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-sm {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.72rem;
  flex-shrink: 0;
}

.row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn .material-symbols-outlined {
  font-size: 18px;
}

.icon-btn:hover {
  background: var(--surface-alt);
  color: var(--primary);
}

.icon-btn.danger:hover {
  color: var(--error-text);
}

/* ---------- Buttons ---------- */

.btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.15s ease;
}

.btn .material-symbols-outlined {
  font-size: 18px;
}

.btn::after {
  content: "";
  position: absolute;
  top: 0;
  left: -120%;
  width: 55%;
  height: 100%;
  background: linear-gradient(115deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  transform: skewX(-20deg);
  pointer-events: none;
}

.btn:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  transform: translateY(-1px);
}

.btn:hover::after {
  animation: btnShineSweep 0.7s ease-out forwards;
}

@keyframes btnShineSweep {
  to { left: 130%; }
}

.btn.secondary {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border-strong);
}

.btn.secondary:hover {
  background: var(--surface-alt);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input, select {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}

label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 600;
}

.field {
  margin-bottom: 14px;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

/* ---------- Status pills ---------- */

.status-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.status-tag.active { background: var(--success-bg); color: var(--success-text); }
.status-tag.depleted { background: var(--surface-hover); color: var(--text-muted); }
.status-tag.pending { background: var(--warning-bg); color: var(--warning-text); }
.status-tag.approved { background: var(--success-bg); color: var(--success-text); }
.status-tag.rejected { background: var(--error-bg); color: var(--error-text); }

/* ---------- Sidebar request badge ---------- */

.req-badge {
  margin-left: auto;
  background: var(--error-text);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 999px;
  line-height: 1.5;
}

/* ---------- Secondary tab switcher (requests etc.) ---------- */

.tabs {
  display: flex;
  gap: 4px;
}

.tabs button {
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.tabs button.active {
  background: var(--primary-soft);
  border-color: var(--primary-soft);
  color: var(--primary-soft-text);
  font-weight: 600;
}

/* ---------- Balance / tally ---------- */

.balance-display {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--primary);
}

.balance-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.tally-grid .denom-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 7px;
}

.tally-grid .denom-label {
  width: 58px;
  flex-shrink: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: right;
  padding-top: 2px;
}

.tally-grid .boxes {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.tally-grid .box {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  background: var(--surface-hover);
}

.tally-grid .box.used {
  background: var(--primary);
}

/* ---------- Person / customer picker ---------- */

.person-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.person-list button {
  text-align: left;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
}

.person-list button:hover {
  background: var(--surface-alt);
}

.person-list button.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-soft-text);
}

.person-list .amount {
  margin-left: auto;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.customer-card {
  background: var(--primary-soft);
  border: 1px solid var(--primary-soft);
  border-radius: var(--radius-card);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.customer-card .who {
  display: flex;
  align-items: center;
  gap: 12px;
}

.customer-card .avatar {
  width: 46px;
  height: 46px;
  background: var(--primary);
  color: #fff;
  font-size: 1.05rem;
}

.customer-card .name {
  font-weight: 700;
  font-size: 1.02rem;
}

.customer-card .sub {
  font-size: 0.78rem;
  color: var(--primary-soft-text);
}

.customer-card .balance {
  text-align: right;
}

.customer-card .balance .amount {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.customer-card .balance .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary-soft-text);
}

/* ---------- Product icon buttons ---------- */

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
}

.product-tile {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-family: inherit;
}

.product-tile .material-symbols-outlined {
  font-size: 28px;
  color: var(--primary);
}

.product-tile .name {
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
}

.product-tile .price {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.product-tile:hover {
  background: var(--surface-alt);
  border-color: var(--primary);
}

/* ---------- Pending transaction / activity log ---------- */

.pending-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}

.pending-panel .accent-bar {
  height: 4px;
  background: var(--primary);
}

.pending-panel .body {
  padding: 16px;
}

.pending-panel .row-item {
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.pending-panel .row-item .amount {
  color: var(--error-text);
  font-weight: 700;
}

.pending-panel .actions {
  display: flex;
  gap: 8px;
}

.pending-panel .actions button {
  flex: 1;
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.activity-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--border);
}

.activity-list li:last-child {
  border-bottom: none;
}

.activity-list .icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--success-bg);
  color: var(--success-text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.activity-list .icon .material-symbols-outlined {
  font-size: 17px;
}

.activity-list .title {
  font-size: 0.86rem;
  font-weight: 600;
}

.activity-list .meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.activity-list .value {
  margin-left: auto;
  font-size: 0.88rem;
  font-weight: 600;
}

.muted {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.error-msg {
  color: var(--error-text);
  font-size: 0.86rem;
  margin-top: 6px;
  min-height: 1.2em;
}

/* ---------- Login screen ---------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.login-card .header {
  padding: 30px 30px 20px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.login-card .header .logo {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
}

.login-card .header .logo::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 16px;
  border: 1px solid transparent;
  border-top-color: rgba(30, 64, 175, 0.5);
  border-left-color: rgba(30, 64, 175, 0.2);
  animation: logoRingSpin 10s linear infinite;
  pointer-events: none;
}

.login-card .header .logo .sparkle-dot {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent-strong, #d4af37);
  box-shadow: 0 0 6px rgba(212, 175, 55, 0.8);
  animation: sparklePulse 2.6s ease-in-out infinite;
}

.login-card .header .logo .sparkle-dot:nth-child(2) {
  top: -3px;
  right: 2px;
}

.login-card .header .logo .sparkle-dot:nth-child(3) {
  bottom: 0px;
  left: -3px;
  animation-delay: 1.1s;
}

@keyframes logoRingSpin {
  to { transform: rotate(360deg); }
}

@keyframes sparklePulse {
  0%, 100% { opacity: 0; transform: scale(0.6); }
  50% { opacity: 1; transform: scale(1.1); }
}

.login-card .header .logo .material-symbols-outlined {
  font-size: 30px;
}

.login-card .header h1 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

.login-card .header p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.login-card .body {
  padding: 24px 28px 28px;
}

.login-card .section-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 10px;
}

.user-menu {
  position: relative;
  margin-bottom: 4px;
}

.user-menu-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.user-menu-btn:hover {
  border-color: var(--primary);
}

.user-menu-btn .material-symbols-outlined {
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.user-menu-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 10px;
}

.link-btn {
  display: block;
  margin: 10px auto 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--primary);
}

.user-search {
  margin-bottom: 10px;
}

.user-list {
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 22px;
}

.user-list button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  text-align: left;
}

.user-list button:last-child {
  border-bottom: none;
}

.user-list button:hover {
  background: var(--surface-alt);
}

.user-list button.selected {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-weight: 600;
}

.user-list .empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.pin-input {
  width: 100%;
  text-align: center;
  letter-spacing: 0.5em;
  font-size: 1.1rem;
  padding: 12px;
}
