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

/* Grid items default to min-width:auto, so a child's intrinsic content
   width (an unbroken URL, a wide form row) can force its track — and the
   whole page — wider than the viewport. This is the standard fix, applied
   to every grid container in the app rather than patched one at a time. */
.dashboard-grid > *, .detail-grid > *, .settings-grid > *, .charts-grid > *,
.kpi-row > *, .gauges-row > *, .stat-chip-row > *, .entity-grid > *,
.readme-split > *, .quick-stats > * {
  min-width: 0;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
  width: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s var(--ease-out), color 0.3s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, p {
  margin: 0;
}

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

button {
  font-family: inherit;
  cursor: pointer;
}
button:disabled { cursor: not-allowed; opacity: 0.55; }

input, select, textarea {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  transition: border-color 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Shared view utility classes ---------- */

.view-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.25rem;
}

.search-wrap {
  position: relative;
  flex: 1 1 240px;
}
.search-wrap input { padding-left: 2.1rem; }
.search-wrap::before {
  content: "🔍";
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  opacity: 0.6;
}

.view-toolbar select { width: auto; min-width: 150px; }
.spacer { flex: 1; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.2rem;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.9rem;
}
.panel-header h2 { font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: 0.5rem; }
.panel-header h2::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--gradient-primary);
  flex-shrink: 0;
}
.panel-header-tight { margin-top: 1.1rem; margin-bottom: 0.6rem; }

.panel-link { font-size: 0.82rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.panel-link:hover { text-decoration: underline; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-faint);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}
.empty-hint { color: var(--text-faint); font-size: 0.85rem; line-height: 1.5; }
.empty-hint-inline { color: var(--text-faint); font-size: 0.82rem; font-style: italic; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  text-decoration: none;
  margin-bottom: 1rem;
}
.back-link:hover { color: var(--accent); }

.info-rows { display: flex; flex-direction: column; gap: 0.55rem; }
.info-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.88rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
}
.info-row:last-child { border-bottom: none; padding-bottom: 0; }
.info-row span:first-child { color: var(--text-faint); }

.due-list, .activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.due-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
}
.due-item.overdue { background: var(--danger-soft); }
.due-item.overdue .due-date { color: var(--danger); font-weight: 700; }
.due-name { font-weight: 600; font-size: 0.88rem; }
.due-meta { font-size: 0.76rem; color: var(--text-faint); }
.due-date { font-size: 0.8rem; color: var(--text-dim); white-space: nowrap; }

.activity-item {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-size: 0.85rem;
}
.activity-dot {
  width: 7px; height: 7px;
  border-radius: 999px;
  background: var(--accent);
  margin-top: 0.4rem;
  flex-shrink: 0;
}
.activity-text { font-weight: 500; }
.activity-meta { font-size: 0.75rem; color: var(--text-faint); margin-top: 0.1rem; }
.activity-list-full { max-height: 340px; overflow-y: auto; padding-right: 0.3rem; }

/* ---------- Entity grid (clients list) ---------- */

.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.entity-grid-tight { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.entity-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.1rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  transition: transform 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out), border-color 0.2s;
  animation: cardIn 0.4s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 50ms);
}
.entity-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--accent);
}
.entity-card-tight { padding: 0.85rem; gap: 0.4rem; }
.entity-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; }
.entity-card-head h3 { font-size: 1rem; font-weight: 700; }
.entity-card-title-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.entity-card-meta { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; font-size: 0.8rem; color: var(--text-dim); }
.meta-item { display: inline-flex; align-items: center; gap: 0.2rem; white-space: nowrap; }
.entity-card-services { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.entity-avatar {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: var(--radius-sm);
  background: var(--gradient-primary);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.entity-card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}
.entity-card-arrow { font-weight: 600; color: var(--accent); }

footer.app-footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 0.8rem;
  margin-top: 3rem;
}
