/* Internal Delivery CRM - Grey + #cc0000 palette */
:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e5e7eb;
  --shadow: 0 10px 28px rgba(2,6,23,.08);
  --shadow2: 0 6px 16px rgba(2,6,23,.06);
  --radius: 16px;
  --radius2: 12px;
  --brand: #cc0000;
  --brand2: #4a5568;
  --good: #16a34a;
  --warn: #f59e0b;
  --bad: #ef4444;
  --chip: #f1f5f9;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }

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

/* Sidebar */
.sidebar {
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 16px;
  margin-bottom: 8px;
}
.brand .logo, .logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), #e63939);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow2);
  color: white;
  font-weight: 800;
  letter-spacing: .5px;
  flex-shrink: 0;
}
.brand h1 {
  font-size: 14px;
  margin: 0;
  line-height: 1.2;
  letter-spacing: .4px;
}
.brand small {
  display: block;
  color: var(--muted);
  font-weight: 600;
  margin-top: 2px;
}

.nav-section {
  margin: 16px 0 10px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 6px 6px;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  color: #111827;
  font-weight: 650;
}
.nav a:hover { background: #f3f4f6; }
.nav a.active {
  background: rgba(204, 0, 0, .1);
  color: var(--brand);
  border: 1px solid rgba(204, 0, 0, .2);
}
.ico {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: #f3f4f6;
  display: grid;
  place-items: center;
  font-size: 14px;
  flex-shrink: 0;
}
.nav a.active .ico { background: rgba(204, 0, 0, .12); }
.sidebar-footer {
  margin-top: 18px;
  padding: 10px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 12px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: #f8fafc;
  border: 1px solid var(--line);
  font-weight: 650;
}
.dot { width: 8px; height: 8px; border-radius: 999px; background: var(--good); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* Main */
.main { padding: 22px 22px 34px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-title h2 { margin: 0; font-size: 18px; letter-spacing: .2px; }
.page-title p { margin: 4px 0 0; color: var(--muted); font-weight: 600; font-size: 13px; }
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(2,6,23,.03);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
}
.btn:hover { background: #fafafa; }
.btn.primary {
  background: var(--brand);
  color: white;
  border-color: rgba(0,0,0,.05);
  box-shadow: 0 10px 18px rgba(204, 0, 0, .25);
}
.btn.primary:hover { filter: brightness(.98); }

.avatar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  font-weight: 750;
  font-size: 13px;
}
.badge {
  width: 30px;
  height: 30px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand2), #718096);
  display: grid;
  place-items: center;
  color: white;
  font-weight: 900;
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
  align-items: start;
}
@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .grid { grid-template-columns: 1fr; }
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow2);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.card-header h3 {
  margin: 0;
  font-size: 13px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #334155;
}
.card-header .sub { margin: 6px 0 0; font-size: 12px; color: var(--muted); font-weight: 650; }
.card-body { padding: 16px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid #e2e8f0;
  color: #334155;
  font-weight: 800;
  font-size: 12px;
}

/* Table */
.table-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 10px;
}
.table-title h3 { margin: 0; font-size: 16px; letter-spacing: .2px; }
.table-title p { margin: 3px 0 0; color: var(--muted); font-size: 12px; font-weight: 650; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
thead th {
  text-align: left;
  color: #334155;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid #eef2f7;
  vertical-align: middle;
  font-weight: 650;
}
tbody tr:hover td { background: #fafafa; }
tbody tr { cursor: pointer; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: white;
  font-size: 12px;
  font-weight: 800;
}
.status .s { width: 8px; height: 8px; border-radius: 999px; background: var(--good); }
.status.wait .s { background: var(--warn); }
.status.block .s { background: var(--bad); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, monospace; }

/* Forms */
input, select, textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 100%;
  max-width: 100%;
}
label { display: block; font-weight: 650; font-size: 13px; margin-bottom: 4px; }
.form-group { margin-bottom: 14px; }
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.select {
  border: 1px solid var(--line);
  background: #fbfdff;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 650;
  color: #111827;
}

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-box {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand .logo { margin: 0 auto 12px; }
.login-brand h1 { font-size: 20px; margin: 0 0 8px; }
.login-brand .muted { color: var(--muted); font-size: 13px; }
.login-form label { margin-top: 12px; }
.login-form input { margin-bottom: 4px; }
.login-form button { margin-top: 20px; width: 100%; }
.alert { padding: 12px; border-radius: 12px; margin-bottom: 16px; font-size: 13px; }
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.muted { color: var(--muted); }

/* Summary, rows */
.summary { display: grid; gap: 10px; }
.summary .line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed #e5e7eb;
  font-weight: 750;
  font-size: 13px;
}
.summary .line:last-child { border-bottom: none; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fbfdff;
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 8px;
}
.row small { color: var(--muted); font-weight: 750; }
.section-gap { margin-top: 18px; }
.quick { display: flex; gap: 10px; flex-wrap: wrap; }
.quick .btn { flex: 1; min-width: 140px; }

/* Work item detail */
.work-item-detail .thread { max-height: 400px; overflow-y: auto; }
.thread-msg {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 10px;
  background: #fafafa;
}
.thread-msg.internal { border-left: 4px solid var(--muted); }
.thread-msg.dev { border-left: 4px solid var(--brand2); }
.thread-msg.client { border-left: 4px solid var(--brand); }
.thread-msg.inbound { border-left: 4px solid var(--good); }
.msg-meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.handoff-packet {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  margin-bottom: 16px;
}

.client-load-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
}
.client-tile {
  padding: 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4a5568, #718096);
  color: white;
  text-decoration: none;
  font-weight: 700;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.client-tile.at-risk {
  background: linear-gradient(135deg, #cc0000, #e63939);
}
.tile-name { opacity: .9; }
.tile-count { font-size: 18px; font-weight: 900; }
