:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #6b7280;
  --line: #e7e9f0;
  --accent: #4c6fff;
  --accent-soft: #eef1ff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1016; --card: #161a23; --text: #e8eaf0; --muted: #8b93a7;
    --line: #232838; --accent: #6f8bff; --accent-soft: #1b2236;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 44px; height: 44px; display: grid; place-items: center;
  font-size: 22px; background: var(--accent-soft); border-radius: 12px;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.sub { margin: 0; color: var(--muted); font-size: 13px; }

.btn {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  padding: 9px 16px; border-radius: 10px; cursor: pointer; font-size: 14px;
  font-weight: 600; transition: .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger:hover { border-color: #c0344a; color: #c0344a; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.btn-primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.btn-primary:hover { filter: brightness(1.07); color: #fff; border-color: var(--accent); }

/* Row/item action buttons (edit / delete) */
.item-actions, .row-actions { display: flex; gap: 2px; flex-shrink: 0; }
.item-btn {
  border: 1px solid transparent; background: transparent; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 5px 7px; border-radius: 8px;
  opacity: .55; transition: .15s;
}
.item-btn:hover { opacity: 1; background: var(--accent-soft); border-color: var(--accent); }
.item-btn[data-del]:hover { background: #fde8ea; border-color: #f3b6bf; }
@media (prefers-color-scheme: dark) {
  .item-btn[data-del]:hover { background: #3a1a1f; border-color: #5e2a31; }
}

/* Edit modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  z-index: 100; backdrop-filter: blur(2px);
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; width: 100%; max-width: 420px;
}
.modal.modal-sm { max-width: 380px; }
.modal h3 { margin: 0 0 16px; font-size: 18px; }
.confirm-message { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.container { max-width: 1080px; margin: 0 auto; padding: 24px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow);
}
.stat-num { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.stat-label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }

/* Toolbar */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 220px; }
.search-ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); opacity: .5; }
.search input {
  width: 100%; padding: 11px 14px 11px 40px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 14px;
}
.select {
  padding: 11px 14px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 14px;
}
.search input:focus, .select:focus { outline: none; border-color: var(--accent); }

.tabs { display: flex; background: var(--accent-soft); border-radius: 11px; padding: 4px; }
.tab {
  border: 0; background: transparent; color: var(--muted); padding: 7px 14px;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.tab.active { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }

.result-count { color: var(--muted); font-size: 13px; margin: 6px 2px 16px; }

/* Boxes grid */
.boxes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.box-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.box-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.box-title { font-size: 17px; font-weight: 700; }
.box-meta { display: flex; align-items: center; gap: 8px; }
.room-badge {
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
}
.count-badge { color: var(--muted); font-size: 12px; }
.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: 9px 11px; background: var(--bg); border-radius: 10px;
}
.item-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item-text { font-weight: 500; }
.item-sub { color: var(--muted); font-size: 12.5px; }
.item-empty { color: var(--muted); font-size: 13px; font-style: italic; }

/* Activity table */
.table-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--bg); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--accent-soft); }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }

/* Pills */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.add { background: #e4f8ee; color: #138a55; }
.pill.remove { background: #fde8ea; color: #c0344a; }
.pill.update_room { background: #e6edff; color: #3858cc; }
.pill.create { background: #efe9ff; color: #6b46d9; }
@media (prefers-color-scheme: dark) {
  .pill.add { background: #11331f; color: #5fd896; }
  .pill.remove { background: #3a1a1f; color: #ff8a99; }
  .pill.update_room { background: #1d2a44; color: #84a9ff; }
  .pill.create { background: #2a2733; color: #c8b6ff; }
}

/* Empty state */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty-ico { font-size: 40px; margin-bottom: 8px; }
.empty code { background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 6px; }

@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .stat { padding: 14px; }
  .stat-num { font-size: 22px; }
  .container { padding: 16px; }
}
