/* CRM UI — light admin dashboard style (inspired by the screenshot) */
:root{
  --app-bg:#f4f7fe;
  --card:#ffffff;
  --text:#1f2a44;
  --muted:#6c7a92;
  --muted2:#93a1b8;
  --border:#e8eef7;
  --primary:#4f46e5;
  --primary2:#6d5efc;
  --danger:#ef4444;
  --ok:#22c55e;
  --warn:#f59e0b;
  --shadow:0 18px 35px rgba(16,24,40,.06);
  --shadow2:0 10px 22px rgba(16,24,40,.06);
  --radius:18px;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  color:var(--text);
  background:var(--app-bg);
  letter-spacing:.2px;
}

/* App layout */
.app{ display:flex; min-height:100vh; }
.sidebar{
  width:92px;
  background:var(--card);
  border-right:1px solid var(--border);
  display:flex;
  flex-direction:column;
  align-items:center;
  padding:14px 10px;
  position:sticky;
  top:0;
  height:100vh;
}
.sidebar.expanded{ width:250px; align-items:stretch; padding:14px 14px; }
.brand{ width:100%; display:flex; justify-content:center; margin-bottom:10px; }
.sidebar.expanded .brand{ justify-content:flex-start; }
.brand-mark{
  width:44px; height:44px;
  border-radius:14px;
  background:linear-gradient(135deg, var(--primary), #22c55e);
  display:flex; align-items:center; justify-content:center;
  box-shadow:var(--shadow2);
  text-decoration:none;
}
.brand-dot{
  width:14px; height:14px; border-radius:6px;
  background:rgba(255,255,255,.9);
  box-shadow:0 8px 16px rgba(0,0,0,.12);
}

.side-nav{ width:100%; margin-top:6px; display:flex; flex-direction:column; gap:10px; align-items:center; }
.sidebar.expanded .side-nav{ align-items:stretch; }

.side-link{
  width:44px; height:44px;
  border-radius:14px;
  display:flex; align-items:center; justify-content:center;
  color:var(--muted);
  text-decoration:none;
  position:relative;
  transition:background .15s ease, color .15s ease, transform .15s ease;
}
.sidebar.expanded .side-link{
  width:auto; height:48px;
  justify-content:flex-start;
  padding:0 14px;
  gap:12px;
}
.side-link:hover{ background:rgba(79,70,229,.08); color:var(--primary); transform:translateY(-1px); }
.side-link.active{
  background:rgba(79,70,229,.12);
  color:var(--primary);
}
.side-ico{ display:inline-flex; }
.side-text{
  display:none;
  font-weight:600;
  color:inherit;
}
.sidebar.expanded .side-text{ display:inline; }

.side-spacer{ flex:1; }
.side-footer{ width:100%; display:flex; justify-content:center; padding-top:12px; }
.sidebar.expanded .side-footer{ justify-content:flex-start; padding-left:6px; }
.side-avatar{
  width:36px; height:36px; border-radius:14px;
  background:linear-gradient(135deg, #60a5fa, #a78bfa);
  box-shadow:var(--shadow2);
}

/* Main */
.main{ flex:1; display:flex; flex-direction:column; min-width:0; }
.topbar{
  height:70px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:0 22px;
  position:sticky;
  top:0;
  background:rgba(244,247,254,.88);
  backdrop-filter: blur(10px);
  z-index:5;
}
.topbar-title{ display:flex; flex-direction:column; gap:2px; min-width:0; }
.topbar-h1{ font-size:18px; font-weight:800; letter-spacing:.2px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.topbar-sub{ font-size:12px; color:var(--muted2); }

.topbar-right{ display:flex; align-items:center; gap:10px; }
.icon-btn{
  border:1px solid transparent;
  background:transparent;
  width:40px; height:40px;
  border-radius:14px;
  display:inline-flex; align-items:center; justify-content:center;
  color:var(--muted);
  cursor:pointer;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.icon-btn:hover{ background:#fff; border-color:var(--border); color:var(--text); transform:translateY(-1px); }

.search{
  display:flex; align-items:center; gap:10px;
  background:#fff;
  border:1px solid var(--border);
  border-radius:999px;
  padding:10px 14px;
  min-width:320px;
  box-shadow:0 12px 25px rgba(16,24,40,.04);
}
.search-ico{ color:var(--muted2); display:flex; }
.search-input{
  border:0; outline:0; width:100%;
  font-size:13px;
  color:var(--text);
}
.search-input::placeholder{ color:var(--muted2); }

.content{ padding:22px; max-width:1500px; width:100%; margin:0 auto; }

/* Flash */
.flash{
  border-radius:16px;
  padding:12px 14px;
  border:1px solid var(--border);
  background:#fff;
  box-shadow:var(--shadow2);
  margin-bottom:16px;
  font-weight:600;
}
.flash.ok{ border-color:rgba(34,197,94,.25); background:rgba(34,197,94,.08); color:#14532d; }
.flash.err{ border-color:rgba(239,68,68,.25); background:rgba(239,68,68,.08); color:#7f1d1d; }
.flash.warn{ border-color:rgba(245,158,11,.25); background:rgba(245,158,11,.10); color:#7c2d12; }
.flash.hollow{ background:transparent; box-shadow:none; }

/* Cards + grid */
.grid{
  display:grid;
  grid-template-columns:repeat(12, minmax(0,1fr));
  gap:18px;
  align-items:start;
}
.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  overflow:hidden;
}
.card.hollow{ background:transparent; border:0; box-shadow:none; }
.card-hd{
  padding:16px 18px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  border-bottom:1px solid var(--border);
}
.card-hd h2{
  margin:0;
  font-size:14px;
  letter-spacing:.3px;
  font-weight:800;
  text-transform:none;
}
.card-bd{ padding:18px; }

.kpi{
  padding:14px 16px;
  border:1px solid var(--border);
  border-radius:16px;
  background:#fbfcff;
  box-shadow:0 10px 22px rgba(16,24,40,.04);
}
.kpi .label{ font-size:12px; color:var(--muted2); font-weight:700; }
.kpi .value{ font-size:22px; font-weight:900; margin-top:6px; }
.kpi .sub{ font-size:12px; color:var(--muted); margin-top:2px; }

/* Table */
.table{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
  overflow:hidden;
}
.table th, .table td{
  padding:12px 12px;
  border-bottom:1px solid var(--border);
  font-size:13px;
}
.table th{
  text-align:left;
  font-size:11px;
  letter-spacing:.6px;
  text-transform:uppercase;
  color:var(--muted2);
  background:#f7f9ff;
}
.table tr:last-child td{ border-bottom:0; }
.table td.right, .right{ text-align:right; }
.nowrap{ white-space:nowrap; }
.muted{ color:var(--muted); }
.actions{ display:flex; gap:8px; justify-content:flex-end; }

/* Badges */
.badge{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:6px 10px;
  border-radius:999px;
  font-size:12px;
  font-weight:800;
  border:1px solid var(--border);
  background:#fff;
  color:var(--muted);
}
.badge.ok{ background:rgba(34,197,94,.10); border-color:rgba(34,197,94,.18); color:#166534; }
.badge.err{ background:rgba(239,68,68,.10); border-color:rgba(239,68,68,.18); color:#7f1d1d; }
.badge.warn{ background:rgba(245,158,11,.12); border-color:rgba(245,158,11,.22); color:#7c2d12; }

/* Forms */
.form-row{ display:grid; grid-template-columns:repeat(12, minmax(0,1fr)); gap:12px; }
.field{ grid-column: span 6; }
.field.full{ grid-column: span 12; }
label{ display:block; font-size:12px; color:var(--muted2); font-weight:800; margin-bottom:6px; }
input, select, textarea{
  width:100%;
  padding:11px 12px;
  border-radius:14px;
  border:1px solid var(--border);
  background:#fff;
  color:var(--text);
  outline:none;
  transition:border-color .15s ease, box-shadow .15s ease;
  font-size:13px;
}
textarea{ min-height:96px; resize:vertical; }
input:focus, select:focus, textarea:focus{
  border-color:rgba(79,70,229,.35);
  box-shadow:0 0 0 4px rgba(79,70,229,.10);
}

/* Buttons */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid var(--border);
  background:#fff;
  color:var(--text);
  font-weight:800;
  font-size:13px;
  text-decoration:none;
  cursor:pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}
.btn:hover{ transform:translateY(-1px); box-shadow:0 12px 24px rgba(16,24,40,.06); border-color:#dde6f3; }
.btn.primary{
  background:linear-gradient(135deg, var(--primary), var(--primary2));
  color:#fff;
  border-color:rgba(79,70,229,.1);
}
.btn.primary:hover{ box-shadow:0 16px 30px rgba(79,70,229,.18); }
.btn.small, .btn.sm{ padding:8px 10px; font-size:12px; border-radius:12px; }
.btn.danger{ background:rgba(239,68,68,.08); border-color:rgba(239,68,68,.18); color:#7f1d1d; }
.btn.ghost{ background:transparent; }
.btn.ghost:hover{ background:#fff; }

/* Utilities */
.table-wrap{ overflow:auto; border:1px solid var(--border); border-radius:16px; }
/* Orders: prevent horizontal scroll by wrapping content */
.no-scroll-x{ overflow-x:hidden; }
.orders-table{ width:100%; table-layout:fixed; }
.orders-table th, .orders-table td{ word-break:break-word; white-space:normal; }
.orders-table td.nowrap, .orders-table th.nowrap{ white-space:nowrap; }

/* Purchases: keep table readable (no horizontal scrollbar, no vertical letter-stacking) */
.purchases-table{ width:100%; table-layout:auto; }

/* Headers should never break into single letters */
.purchases-table th{ white-space:nowrap; word-break:normal; overflow-wrap:normal; }

/* Default cell behaviour */
.purchases-table td{ vertical-align:middle; }

/* Vendor + Customer: single-line with ellipsis (full value on hover via title attr) */
.purchases-table td:nth-child(3),
.purchases-table td:nth-child(4){
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  max-width:220px;
}

/* Courier + Tracking: wrap long strings so the table doesn't overflow */
.purchases-table td:nth-child(7),
.purchases-table td:nth-child(8){
  white-space:normal;
  overflow-wrap:anywhere;
  word-break:break-word;
  max-width:260px;
}

/* Delivery badge: never split onto 2 lines */
.purchases-table td:nth-child(5) .badge{ white-space:nowrap; }

/* Gentle column hints (auto layout will adapt based on available space) */
.purchases-table th:nth-child(1), .purchases-table td:nth-child(1){ width:60px; }
.purchases-table th:nth-child(2), .purchases-table td:nth-child(2){ width:110px; }
.purchases-table th:nth-child(6), .purchases-table td:nth-child(6){ width:110px; }
.purchases-table th:nth-child(9), .purchases-table td:nth-child(9){ width:170px; }

/* Actions: allow wrapping (on small widths) instead of forcing horizontal scroll */
.row-actions{ display:flex; gap:8px; justify-content:flex-end; flex-wrap:wrap; }

.pager{ display:flex; align-items:center; justify-content:space-between; gap:12px; margin-top:14px; }
.kv{ display:grid; gap:8px; }

/* Emails */
.email-meta{ margin-bottom:14px; }
.email-subject{ font-size:18px; font-weight:900; margin-bottom:8px; }
.email-line{ font-size:13px; margin-top:4px; }
.email-body{ border:1px solid var(--border); border-radius:16px; background:#fff; overflow:hidden; }
.email-body pre{ margin:0; padding:14px; white-space:pre-wrap; word-break:break-word; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size:12.5px; }
.email-iframe{ width:100%; height:70vh; border:0; display:block; background:#fff; }
.btn.danger:hover{ box-shadow:0 16px 30px rgba(239,68,68,.10); }
.btn:disabled{ opacity:.6; cursor:not-allowed; transform:none; }

/* Footer */
.footer{
  padding:14px 22px 22px;
  color:var(--muted2);
  font-size:12px;
}

/* Small screens */
@media (max-width: 900px){
  .search{ min-width:200px; width:200px; }
  .content{ padding:18px; }
  .sidebar{ position:fixed; left:0; top:0; z-index:20; transform:translateX(-110%); transition:transform .2s ease; }
  .sidebar.expanded{ transform:translateX(0); }
  .topbar{ padding:0 14px; }
}


/* Dashboard chart bits */
.dash-legend{
  display:flex;
  align-items:center;
  gap:14px;
  padding:14px 2px 6px;
}
.legend-item{
  display:inline-flex;
  align-items:center;
  gap:8px;
  font-size:12px;
  color:var(--muted);
  font-weight:800;
}
.legend-dot{
  width:10px; height:10px;
  border-radius:4px;
  display:inline-block;
}
.legend-dot.income{ background:var(--primary); }
.legend-dot.expense{ background:#10b981; }
.legend-spacer{ flex:1; }
.legend-note{ font-size:12px; color:var(--muted2); font-weight:800; }

/* Emails */
.table-wrap{ overflow:auto; border:1px solid var(--border); border-radius:16px; }
.pager{ display:flex; align-items:center; justify-content:center; gap:12px; margin-top:14px; }
.kv{ display:flex; flex-direction:column; gap:8px; font-size:13px; }
.email-meta{ margin-bottom:14px; }
.email-subject{ font-size:16px; font-weight:900; margin-bottom:8px; }
.email-line{ font-size:13px; margin-top:4px; }
.email-body{ border:1px solid var(--border); border-radius:16px; background:#fff; padding:14px; overflow:auto; }
.email-body pre{ margin:0; white-space:pre-wrap; word-break:break-word; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size:12.5px; }
.email-iframe{ width:100%; min-height:540px; border:0; border-radius:12px; background:#fff; }

.dash-chart-wrap{
  padding:4px 0 4px;
}
.dash-chart{
  width:100%;
  height:240px;
}
.chart-grid{ stroke: #edf2fb; stroke-width:2; }
.chart-base{ stroke: #e7eef9; stroke-width:2; }
.chart-label{ fill: #93a1b8; font-size:12px; font-weight:800; }

.chart-bar.income{ fill: rgba(79,70,229,.75); }
.chart-bar.expense{ fill: rgba(16,185,129,.65); }


/* Pills / small status chips */
.pill{
  display:inline-flex;
  align-items:center;
  padding:4px 10px;
  border-radius:999px;
  font-weight:800;
  font-size:12px;
  border:1px solid var(--border);
  background:#fff;
  color:var(--text);
}
.pill.ok{
  background:rgba(22,163,74,.10);
  border-color:rgba(22,163,74,.25);
  color:#14532d;
}
.pill.warn{
  background:rgba(234,179,8,.12);
  border-color:rgba(234,179,8,.25);
  color:#713f12;
}

.hide{ display:none; }

.divider{
  height:1px;
  background:var(--border);
  margin:16px 0;
}

.pre{
  background:#fff;
  border:1px solid var(--border);
  border-radius:14px;
  padding:12px;
  white-space:pre-wrap;
  overflow:auto;
}

.email-body{ margin-top:10px; }
.email-frame{
  width:100%;
  min-height:560px;
  border:1px solid var(--border);
  border-radius:14px;
  background:#fff;
}

/* Auth pages */
.auth-wrap{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
}
.auth-card{
  width: min(460px, 100%);
  background:var(--card);
  border:1px solid var(--border);
  border-radius:22px;
  box-shadow:0 18px 40px rgba(15, 23, 42, .08);
  padding:22px;
}
.auth-title{ font-size:22px; font-weight:900; margin-bottom:4px; }
.auth-sub{ color:var(--muted); margin-bottom:14px; font-weight:700; }
.auth-foot{ margin-top:14px; color:var(--muted); font-size:12px; }

/* Topbar user area */
.topbar-user{
  display:flex;
  align-items:center;
  gap:10px;
  margin-right:10px;
}
