:root {
  --bg: #f7f4ee;
  --panel: #ffffff;
  --ink: #1e1b16;
  --muted: #6e675b;
  --accent: #c2572f;
  --accent-dark: #8f3f1c;
  --line: #e6dfd3;
  --shadow: 0 12px 30px rgba(34, 26, 20, 0.12);
  --radius: 18px;
  --max-width: 1100px;
  --font: "Space Grotesk", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(circle at top, #fff8ed, #f3eee5 60%, #efe6d8);
  color: var(--ink);
}

.content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.site-header {
  max-width: var(--max-width);
  margin: 24px auto 0;
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  display: grid;
  place-items: center;
  letter-spacing: 1px;
  box-shadow: var(--shadow);
}

.brand-title {
  font-weight: 700;
  font-size: 18px;
}

.brand-sub {
  color: var(--muted);
  font-size: 13px;
}

.brand-meta {
  color: var(--muted);
  font-size: 11px;
}

.user {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.user-name {
  font-weight: 600;
}

.user-id {
  color: var(--muted);
  font-size: 12px;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  text-decoration: none;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

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

.button.primary:hover {
  background: var(--accent-dark);
}

.button.ghost {
  border-color: var(--line);
  color: var(--ink);
  background: white;
}

.button.small {
  padding: 6px 12px;
  font-size: 12px;
}

.hero {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
}

.hero h1 {
  margin: 0;
  font-size: 32px;
}

.hero p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.alert {
  padding: 12px 16px;
  border-radius: 12px;
  background: #ffe6d9;
  color: #7a3217;
  border: 1px solid #f7c8ad;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.group-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 16px;
}

.group-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.group-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.group-actions form {
  margin: 0;
}

.search-row {
  margin-top: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.domain-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-button {
  border: 1px solid var(--line);
  background: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-button.is-active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.search-row input[type='text'] {
  flex: 1;
}

.search-count {
  color: var(--muted);
  font-size: 13px;
}

.star-button {
  border: 1px solid var(--line);
  background: #fff;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.report-button {
  border: 1px solid var(--line);
  background: #fff;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.star-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
}

.report-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #b91c1c;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.star-button.is-starred {
  box-shadow: 0 6px 16px rgba(194, 87, 47, 0.2);
  transform: translateY(-1px);
}

.star-button.is-starred svg {
  fill: var(--accent);
}

.report-button.is-reported {
  box-shadow: 0 6px 16px rgba(185, 28, 28, 0.2);
  transform: translateY(-1px);
}

.report-button.is-reported svg {
  stroke: #b91c1c;
}

.report-button.is-reported {
  background: #fee2e2;
  border-color: #fecaca;
}

.group-title {
  font-weight: 600;
  margin-bottom: 6px;
}

.group-meta {
  color: var(--muted);
  font-size: 13px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.tag {
  background: #efe6d8;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: #5c4b3a;
}

.form-row {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

.add-member-form {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  align-items: start;
}

.add-member-form .autocomplete-wrapper {
  min-width: 0;
}

.add-member-form input[type='text'] {
  width: 100%;
}

.add-member-form .button {
  width: 100%;
  justify-content: center;
}

input[type='text'] {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 14px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}

.table th,
.table td {
  text-align: left;
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.table td:last-child {
  text-align: right;
}

.table td:nth-child(3),
.table th:nth-child(3) {
  color: var(--muted);
  font-size: 12px;
}

.log-table td,
.log-table th,
.log-table td div {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.log-table td:last-child {
  text-align: left;
}

.callout {
  padding: 12px 16px;
  border-radius: 12px;
  margin-top: 12px;
  font-size: 14px;
}

.callout.success {
  background: #e7f6ec;
  color: #1f5d2a;
  border: 1px solid #bde0c7;
}

.callout.error {
  background: #ffe6e6;
  color: #7d1a1a;
  border: 1px solid #f2bcbc;
}

.action-status {
  margin-bottom: 16px;
}

.action-status.pending {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

.member-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
  font-size: 14px;
  color: var(--muted);
}

.member-tools select {
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 13px;
}

@media (max-width: 768px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .user {
    align-items: flex-start;
  }

  .group-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .group-actions {
    width: 100%;
    justify-content: space-between;
  }

  .member-tools {
    flex-wrap: wrap;
  }

  .form-row {
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .content {
    padding: 20px 16px 56px;
  }

  .site-header {
    margin: 12px 16px 0;
    padding: 16px;
    background: var(--panel);
    border-radius: 22px;
    box-shadow: var(--shadow);
  }

  .brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    font-size: 18px;
  }

  .brand-title {
    font-size: 20px;
  }

  .brand-sub {
    font-size: 13px;
  }

  .brand-meta {
    font-size: 11px;
  }

  .user {
    width: 100%;
    align-items: flex-start;
    padding-top: 12px;
    border-top: 1px solid var(--line);
  }

  .user-name {
    font-size: 16px;
  }

  .user-id {
    font-size: 13px;
  }

  .user .button {
    width: 100%;
    justify-content: center;
  }

  .panel {
    padding: 18px;
    border-radius: 22px;
  }

  .panel-header-row {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .panel-actions .button {
    width: 100%;
    justify-content: center;
  }

  .panel-actions .button.primary {
    grid-column: 1 / -1;
  }

  .search-row {
    margin-top: 14px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    align-items: start;
  }

  .domain-tabs {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .tab-button {
    white-space: normal;
    word-break: break-word;
  }

  .search-row input[type='text'] {
    width: 100%;
  }

  .search-count {
    text-align: right;
    font-size: 12px;
  }

  .group-list {
    gap: 12px;
  }

  .group-card {
    padding: 16px;
    border-radius: 20px;
  }

  .group-card .group-title {
    font-size: 16px;
  }

  .group-card .group-meta {
    gap: 8px;
  }

  .group-card .group-meta span:first-child {
    flex-basis: 100%;
    font-size: 13px;
  }

  .group-actions {
    width: 100%;
    justify-content: flex-start;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
  }

  .star-button,
  .report-button {
    width: 44px;
    height: 44px;
    border-radius: 14px;
  }

  .star-button svg,
  .report-button svg {
    width: 20px;
    height: 20px;
  }

  .tag {
    font-size: 11px;
  }

  .panel-header {
    padding: 18px;
  }

  .panel-content {
    padding: 18px;
  }

  .panel-section {
    padding: 16px;
  }

  .hero {
    padding: 24px;
  }

  .hero h1 {
    font-size: 26px;
  }

  .hero p {
    font-size: 15px;
  }

  .button {
    min-height: 42px;
  }

  input[type='text'] {
    font-size: 16px;
  }

  .member-tools {
    flex-direction: column;
    align-items: stretch;
  }

  .member-tools select,
  .member-tools .button {
    width: 100%;
  }

  .tools-user-search {
    flex-direction: column;
    align-items: stretch;
  }

  .tools-user-search .button {
    width: 100%;
  }

  .table {
    border-collapse: separate;
    border-spacing: 0;
  }

  .table thead {
    display: none;
  }

  .table tbody,
  .table tr {
    display: block;
    width: 100%;
  }

  .table tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }

  .table td {
    display: grid;
    grid-template-columns: minmax(0, 110px) minmax(0, 1fr);
    gap: 8px;
    padding: 6px 0;
    border-bottom: none;
    text-align: left;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .table td:last-child {
    text-align: left;
  }
}

/* Side Panel */
.side-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 27, 22, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 100;
}

.side-panel-overlay.open {
  opacity: 1;
  visibility: visible;
}

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 816px;
  max-width: 100%;
  background: var(--bg);
  box-shadow: -8px 0 30px rgba(34, 26, 20, 0.15);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 101;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.side-panel.open {
  transform: translateX(0);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  gap: 16px;
}

.panel-header h2 {
  margin: 0;
  font-size: 20px;
  word-break: break-word;
}

.panel-header-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.close-button {
  background: none;
  border: 1px solid var(--line);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.close-button:hover {
  background: var(--line);
  color: var(--ink);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.panel-section {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.panel-section h3 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.members-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.members-header h3 {
  margin: 0;
}

.member-search {
  margin-bottom: 12px;
}

.member-search input {
  width: 100%;
}

.panel-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--muted);
}

.group-card-clickable {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.group-card-clickable:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 40px rgba(34, 26, 20, 0.16);
}

@media (max-width: 768px) {
  .side-panel {
    width: 100%;
  }
}

/* Autocomplete */
.autocomplete-wrapper {
  position: relative;
  flex: 1;
}

.autocomplete-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 280px;
  overflow-y: auto;
  z-index: 200;
  display: none;
  margin-top: 4px;
}

.autocomplete-item {
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover {
  background: #f7f4ee;
}

.autocomplete-name {
  font-weight: 500;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.autocomplete-email {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* Panel Header Row */
.panel-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.panel-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.panel-header-row h2 {
  margin: 0 0 4px;
}

/* Admin Tags Page */
.admin-grid {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.admin-section h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.section-desc {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 16px;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
}

/* Tag List */
.tag-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.tag-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 10px;
}

.tag-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tag-name {
  flex: 1;
  font-weight: 500;
}

.tag-item-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--line);
  color: var(--ink);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.create-tag-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.create-tag-form input[type="text"] {
  flex: 1;
}

.create-tag-form input[type="color"] {
  width: 40px;
  height: 40px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

/* Assignment List */
.assignment-search {
  margin-bottom: 12px;
}

.assignment-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.assignment-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: 10px;
}

.assignment-info {
  flex: 1;
  min-width: 0;
}

.assignment-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.assignment-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Tag Pills */
.tag-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-pill {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: white;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--muted);
}

.tag-pill:hover {
  border-color: var(--tag-color, var(--accent));
  color: var(--tag-color, var(--accent));
}

.tag-pill.active {
  background: var(--tag-color, var(--accent));
  border-color: var(--tag-color, var(--accent));
  color: white;
}

.no-tags-hint {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

/* User Assignment */
.user-search-wrapper {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tools-user-search {
  display: flex;
  align-items: stretch;
}

.tools-user-search .autocomplete-wrapper {
  min-width: 0;
  flex: 1;
}

.tools-user-search .button {
  width: auto;
  min-width: 160px;
  justify-content: center;
}

.tools-user-search input[type='text'] {
  width: 100%;
}

.user-search-wrapper input {
  flex: 1;
}

.user-tags-container {
  background: var(--bg);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 24px;
}

.user-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 500;
}

.current-assignments h4 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
}

.user-assignment-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 6px;
}

.user-email {
  flex: 1;
  font-size: 14px;
}

.user-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.mini-tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}

@media (min-width: 1024px) {
  .admin-grid {
    grid-template-columns: 1fr 1fr;
  }

  .admin-grid .admin-section:last-child {
    grid-column: span 2;
  }
}

/* Activity Log */
.log-section h3 {
  display: flex;
  align-items: center;
  gap: 12px;
}

.activity-log {
  background: #1e1e1e;
  border-radius: 8px;
  padding: 12px;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 12px;
  max-height: 200px;
  overflow-y: auto;
  color: #d4d4d4;
}

.log-entry {
  padding: 4px 0;
  border-bottom: 1px solid #333;
  word-break: break-word;
}

.log-entry:last-child {
  border-bottom: none;
}

.log-time {
  color: #6b7280;
  margin-right: 8px;
}

.log-info {
  color: #d4d4d4;
}

.log-success {
  color: #34d399;
}

.log-error {
  color: #f87171;
}
