:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --border: #e2e2e8;
  --text: #1f1f26;
  --text-muted: #6b6b76;
  --accent: #3457d5;
  --accent-soft: #e8ecfd;
  --past: #c62828;
  --past-bg: #fdecea;
  --soon: #b3690a;
  --soon-bg: #fff3e0;
  --done: #2e7d32;
  --done-bg: #e8f5e9;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

header.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header.app-header h1 {
  font-size: 18px;
  margin: 0;
}

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

nav.app-nav {
  display: flex;
  gap: 8px;
}

nav.app-nav a {
  text-decoration: none;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
}

nav.app-nav a:hover { background: var(--accent-soft); color: var(--accent); }
nav.app-nav a.active { background: var(--accent); color: #fff; }

.app-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.auth-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

#current-user-name {
  font-size: 13px;
  color: var(--text-muted);
}

.auth-main {
  max-width: 400px;
  margin: 60px auto;
  padding: 0 24px;
}

.auth-form { gap: 16px; }
.auth-form .form-actions { align-items: center; }

.status-banner-error {
  background: var(--past-bg);
  color: var(--past);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

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

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }

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

.btn-primary:hover { opacity: 0.9; color: #fff; }

.btn-danger {
  color: var(--past);
  border-color: var(--past);
  background: var(--past-bg);
}

.btn-ghost {
  border: none;
  background: none;
  color: var(--text-muted);
  padding: 4px 8px;
}
.btn-ghost:hover { color: var(--past); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-icon:hover { background: var(--past-bg); }

.date-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.date-normal { background: var(--accent-soft); color: var(--accent); }
.date-soon { background: var(--soon-bg); color: var(--soon); }
.date-past { background: var(--past-bg); color: var(--past); }
.date-none { background: #eee; color: var(--text-muted); }

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.field input,
.field textarea,
.field select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}

.field textarea { min-height: 80px; resize: vertical; }

.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 180px; }

.input-with-action { display: flex; gap: 8px; }
.input-with-action input { flex: 1; min-width: 0; }

.confirm-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  padding: 20px;
  max-width: 360px;
  color: var(--text);
  background: var(--surface);
}

.confirm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.confirm-dialog p {
  margin: 0 0 18px;
  font-size: 14px;
}

.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.form-actions .right { display: flex; gap: 10px; }

.status-banner {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--done-bg);
  color: var(--done);
  font-size: 13px;
  font-weight: 600;
}

.rankings-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 24px;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

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

.rankings-table th { background: var(--bg); color: var(--text-muted); font-weight: 600; }
.rankings-table tr:last-child td { border-bottom: none; }

.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  text-align: center;
  user-select: none;
  line-height: 1;
}

/* Sortable table headers (loop dashboard) */
.rankings-table th.sortable { cursor: pointer; user-select: none; }
.rankings-table th.sortable:hover { color: var(--accent); }
.rankings-table th.sortable.sorted::after { content: attr(data-dir) ""; font-size: 10px; margin-left: 4px; }
.rankings-table th.sortable.sorted[data-dir="asc"]::after { content: "\25B2"; }
.rankings-table th.sortable.sorted[data-dir="desc"]::after { content: "\25BC"; }

.rankings-table tr.row-clickable { cursor: pointer; }
.rankings-table tr.row-clickable:hover td { background: var(--accent-soft); }
.rankings-table tr.is-done td { opacity: 0.55; }

.rankings-table .total-score-cell {
  font-weight: 800;
  font-size: 16px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.scope-menu { position: relative; }

.scope-menu-dropdown[hidden] { display: none; }

.scope-menu-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  min-width: 120px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.scope-menu-dropdown button {
  border: none;
  background: none;
  text-align: left;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
}

.scope-menu-dropdown button:hover { background: var(--accent-soft); color: var(--accent); }
.scope-menu-dropdown button[data-action="delete"]:hover { background: var(--past-bg); color: var(--past); }

.scope-picker { position: relative; }

.scope-picker-dropdown[hidden] { display: none; }

.scope-picker-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  min-width: 200px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: 6px;
}

.scope-picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
}

.scope-picker-item:hover { background: var(--accent-soft); }
.scope-picker-item input { cursor: pointer; }

.scope-picker-divider {
  margin-top: 4px;
  padding-top: 11px;
  border-top: 1px solid var(--border);
}

.scope-picker-empty {
  padding: 10px 8px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}

.scope-picker-edit-link {
  display: block;
  margin-top: 4px;
  padding: 8px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.scope-picker-edit-link:hover { text-decoration: underline; }
