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

:root,
:host {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1c1e21;
  --text-secondary: #65676b;
  --text-muted: #8a8d91;
  --primary: #4361ee;
  --primary-hover: #3451d1;
  --success: #1b874b;
  --success-hover: #157a3e;
  --accent: #818cf8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
}

body,
:host {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: block;
}

/* ---------- Header ---------- */
header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #fff;
  padding: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-header {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 0.78rem;
  padding: 0.35rem 0.75rem;
}

.btn-header:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.header-link {
  color: inherit;
  text-decoration: none;
}

.header-link:hover {
  opacity: 0.85;
}

header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.header-accent {
  color: var(--accent);
  font-weight: 400;
}

/* ---------- Main ---------- */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ---------- Top Grid ---------- */
.top-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 860px) {
  .top-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.card-header h2 .report-ts {
  display: block;
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
  margin-top: 0.2rem;
  font-variant-numeric: tabular-nums;
}

.card-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

/* ---------- Badge ---------- */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.2rem 0.6rem;
  border-radius: 100px;
  background: #eef0fb;
  color: var(--primary);
}

.badge.has-selection {
  background: var(--primary);
  color: #fff;
}

/* ---------- Client Panel ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.search-wrap {
  position: relative;
  flex: 1;
}

.search-icon {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  padding: 0.45rem 0.75rem 0.45rem 2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.12);
}

.toolbar-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.client-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.25rem;
  max-height: 320px;
  overflow-y: auto;
  padding: 0.25rem;
  margin: -0.25rem;
}

.client-list::-webkit-scrollbar {
  width: 5px;
}

.client-list::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 10px;
}

.client-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}

.client-item:hover {
  background: #f5f6fa;
}

.client-item.checked {
  background: #eef0fb;
  border-color: #d4d9f7;
}

.client-item input[type="checkbox"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.client-item .name {
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-item .weekend-icon {
  color: #e09f3e;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  margin-left: 0.15rem;
}

.client-item .slug {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: "SF Mono", Monaco, Consolas, monospace;
  flex-shrink: 0;
}

/* ---------- Actions Panel ---------- */
#actions-panel {
  display: flex;
  flex-direction: column;
}

#actions-panel .card-header {
  flex-shrink: 0;
}

.action-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.action-card:last-child {
  margin-bottom: 0;
}

.action-card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.action-card p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.action-card > .btn {
  align-self: stretch;
}

.action-card-buttons {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.5rem;
}

.action-card-buttons .btn {
  min-width: 0;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.inline-field label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.inline-field input[type="number"] {
  width: 60px;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.8rem;
  text-align: center;
  background: var(--surface);
}

.inline-field input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.12);
}

.field-suffix {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 2px 6px rgba(67, 97, 238, 0.3);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

.btn-ghost:hover {
  background: #eef0f4;
  color: var(--text);
}

.btn-success {
  background: var(--success);
  color: #fff;
  font-size: 0.8rem;
  padding: 0.4rem 0.85rem;
}

.btn-success:hover {
  background: var(--success-hover);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* ---------- Loading ---------- */
.loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid #e2e5ea;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}

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

/* ---------- Results ---------- */
.results-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.results-toolbar input[type="text"] {
  flex: 1;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.results-toolbar input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.12);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
}

/* ---------- Client Summary ---------- */
.client-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.summary-chip {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.2rem 0.55rem;
  border-radius: 100px;
  background: #eef0fb;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.chip-people {
  color: #8b92a5;
  font-weight: 400;
}

.title-people {
  color: #8b92a5;
  font-weight: 400;
  font-size: 0.85em;
}

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

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

thead th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

thead th.sortable {
  cursor: pointer;
  user-select: none;
}

thead th.sortable:hover {
  color: var(--text);
  background: #e8eaef;
}

tbody td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #f0f2f5;
  vertical-align: top;
}

tbody td a {
  color: var(--primary);
  text-decoration: none;
}

tbody td a:hover {
  text-decoration: underline;
}

tbody tr:nth-child(even) {
  background: #f8f9fb;
}

tbody tr:nth-child(even):hover,
tbody tr:hover {
  background: #eff1f5;
}

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

tbody tr.client-group-last td {
  border-bottom: 2px solid var(--border);
}

/* Numeric columns right-aligned */
td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.ts {
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.error-msg {
  color: #c0392b;
  padding: 0.85rem 1rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 0.88rem;
}

.empty-msg {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ---------- Summary Modal ---------- */
.summary-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 30, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1.5rem;
}

.summary-modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  max-width: min(90vw, 1100px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.summary-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.summary-modal-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-modal-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.summary-modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.35rem;
  border-radius: 4px;
}

.summary-modal-close:hover {
  background: #eef0f4;
  color: var(--text);
}

.summary-modal-body {
  padding: 1rem 1.1rem;
  overflow: auto;
}

.summary-modal-code {
  background: #0f1220;
  color: #e6e8ef;
  border-radius: 6px;
  padding: 0.9rem 1rem;
  margin: 0;
  font-family: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre;
  overflow: auto;
}

.summary-modal-code code {
  font-family: inherit;
  color: inherit;
  background: transparent;
  padding: 0;
}

/* ---------- Utility ---------- */
.hidden {
  display: none !important;
}
