/* PENNYWISE ERP — design tokens
   Deep indigo sidebar, light neutral canvas, one accent color doing the
   work of "this is a money app": indigo primary, with blue/purple/orange/
   green reserved for the four stat categories so they stay meaningful
   rather than decorative. */

:root {
  --sidebar-bg: #14183B;
  --sidebar-bg-soft: #1B2050;
  --sidebar-text: #A6ACD6;
  --sidebar-text-active: #FFFFFF;
  --accent: #5B5FEF;
  --accent-soft: #EEF0FF;

  --bg: #F4F5FA;
  --panel: #FFFFFF;
  --border: #E7E8F2;
  --text: #1B1D2B;
  --muted: #767A94;

  --blue: #3B82F6;
  --blue-soft: #E7EFFE;
  --purple: #8B5CF6;
  --purple-soft: #F1EBFE;
  --orange: #F5871F;
  --orange-soft: #FDEEDC;
  --green: #1AA179;
  --green-soft: #E1F5EE;
  --red: #E5484D;
  --red-soft: #FCE8E8;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 24, 59, 0.04), 0 8px 24px rgba(20, 24, 59, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
}

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

/* ---------- LAYOUT ---------- */

.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

/* ---------- SIDEBAR ---------- */

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.brand-name {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.3px;
  display: block;
}

.brand-sub {
  color: var(--sidebar-text);
  font-size: 11px;
  display: block;
  margin-top: 1px;
}

.menu-title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: #5B6099;
  padding: 16px 12px 6px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--sidebar-text);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-item i { font-size: 15px; width: 18px; text-align: center; }

.nav-item:hover { background: var(--sidebar-bg-soft); color: #fff; }

.nav-item.active {
  background: var(--accent);
  color: var(--sidebar-text-active);
}

.sidebar-footer {
  margin-top: auto;
  position: relative;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.admin-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
}
.admin-trigger:hover { background: var(--sidebar-bg-soft); }
.admin-trigger > i { margin-left: auto; color: var(--sidebar-text); font-size: 13px; }

.admin-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--sidebar-bg-soft);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.admin-menu.open { display: block; }

.admin-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: none;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  text-align: left;
  color: var(--sidebar-text);
}
.admin-option:hover { background: rgba(255,255,255,0.06); }
.admin-option strong { color: #fff; font-size: 12.5px; display: block; }
.admin-option small { font-size: 11px; }
.admin-option.active { background: var(--accent); }
.admin-option.active strong, .admin-option.active small { color: #fff; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-footer strong { color: #fff; font-size: 12.5px; display: block; }
.sidebar-footer small { color: var(--sidebar-text); font-size: 11px; }

/* ---------- MAIN / TOPBAR ---------- */

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

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

.topbar h1 { margin: 0; font-size: 19px; font-weight: 700; }
.topbar span { color: var(--muted); font-size: 12.5px; }

.content { padding: 24px 28px 48px; }

/* ---------- TOAST ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }

/* ---------- VIEWS ---------- */

.view { display: none; }
.view.active { display: block; }

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.page-heading h2 { margin: 0 0 4px; font-size: 21px; font-weight: 700; }
.page-heading p { margin: 0; color: var(--muted); font-size: 13.5px; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--border); }

/* ---------- STAT CARDS ---------- */

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

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  box-shadow: var(--shadow);
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.stat-icon.blue { background: var(--blue-soft); color: var(--blue); }
.stat-icon.purple { background: var(--purple-soft); color: var(--purple); }
.stat-icon.orange { background: var(--orange-soft); color: var(--orange); }
.stat-icon.green { background: var(--green-soft); color: var(--green); }
.stat-icon.red { background: var(--red-soft); color: var(--red); }

.stat-card .label { color: var(--muted); font-size: 12.5px; margin-bottom: 3px; }
.stat-card .value { font-size: 21px; font-weight: 700; }

/* ---------- DASHBOARD GRID ---------- */

.dash-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 980px) {
  .dash-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- PANELS ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 8px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

.panel-header h3 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-header small { color: var(--muted); font-size: 12px; }
.panel-header a { color: var(--accent); font-size: 12.5px; font-weight: 600; text-decoration: none; }

.search-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  width: 220px;
  outline: none;
}
.search-box:focus { border-color: var(--accent); }

/* ---------- CHART (simple CSS bars) ---------- */

.chart {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  height: 170px;
  padding: 10px 4px 0;
}
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.bar {
  width: 60%;
  min-height: 4px;
  background: linear-gradient(180deg, var(--accent), #8386F5);
  border-radius: 5px 5px 2px 2px;
}
.bar-col span { font-size: 11.5px; color: var(--muted); }

/* ---------- INVENTORY ALERT LIST ---------- */

.alert-list { display: flex; flex-direction: column; }
.alert-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 2px;
  border-bottom: 1px solid var(--border);
}
.alert-row:last-child { border-bottom: none; }
.alert-row strong { font-size: 13.5px; display: block; }
.alert-row small { color: var(--muted); font-size: 12px; }

.badge-low {
  background: var(--orange-soft);
  color: var(--orange);
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ---------- TABLES ---------- */

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

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 11.5px;
  text-transform: none;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

.empty-state { text-align: center; color: var(--muted); padding: 28px 10px; }

.row-actions { display: flex; gap: 8px; justify-content: flex-end; white-space: nowrap; }
.row-actions button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.row-actions button:hover { background: var(--bg); }
.row-actions .delete-btn { color: var(--red); border-color: var(--red-soft); }
.row-actions .delete-btn:hover { background: var(--red-soft); }

/* ---------- STATUS / BADGES ---------- */

.status {
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  display: inline-block;
  white-space: nowrap;
}
.status.completed, .status.paid { background: var(--green-soft); color: var(--green); }
.status.pending, .status.unpaid { background: var(--orange-soft); color: var(--orange); }

/* ---------- AUTOMATION ---------- */

.automation-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 980px) { .automation-grid { grid-template-columns: 1fr; } }

.automation-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.automation-card i {
  width: 38px; height: 38px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  margin-bottom: 12px;
}
.automation-card h4 { margin: 0 0 6px; font-size: 14.5px; }
.automation-card p { margin: 0 0 12px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.automation-live { color: var(--green); font-size: 12px; font-weight: 700; }
.automation-live::before { content: "●"; margin-right: 5px; }

.workflow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 10px;
  flex-wrap: wrap;
}
.workflow-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 22px;
  text-align: center;
  min-width: 130px;
}
.workflow-box i { font-size: 20px; color: var(--accent); margin-bottom: 6px; display: block; }
.workflow-box strong { font-size: 13px; display: block; }
.workflow-box small { color: var(--muted); font-size: 11.5px; }
.workflow-arrow { color: var(--muted); font-size: 18px; }

/* ---------- REPORTS ---------- */

.report-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
@media (max-width: 980px) { .report-grid { grid-template-columns: 1fr; } }

.report-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.report-card i { font-size: 26px; color: var(--accent); margin-bottom: 10px; display: block; }
.report-card h4 { margin: 0 0 6px; font-size: 14.5px; }
.report-card p { margin: 0 0 16px; color: var(--muted); font-size: 12.5px; }

/* ---------- SETTINGS ---------- */

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 2px;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-row strong { display: block; font-size: 13.5px; }
.setting-row small { color: var(--muted); font-size: 12px; }

/* ---------- MODAL ---------- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 59, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--panel);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(20,24,59,0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 15.5px; }
.modal-close {
  background: none; border: none; font-size: 20px; color: var(--muted);
  cursor: pointer; line-height: 1;
}

.modal-body { padding: 18px 20px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

.form-group { margin-bottom: 13px; }
.form-group label {
  display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px;
}
.form-group input, .form-group select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none; background: var(--panel); color: var(--text);
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent); }

.order-item-row {
  display: grid;
  grid-template-columns: 1fr 70px auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.link-btn {
  background: none; border: none; color: var(--accent);
  font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 6px 0;
}

.field-note { color: var(--muted); font-size: 11.5px; margin-top: -6px; margin-bottom: 12px; }
