/* HabitFill admin design system.
   Dark is the default; `html.light` switches to the light palette. */

:root {
  color-scheme: dark;
  --bg: #000000;
  --panel: #1c1c1e;
  --panel-2: #2c2c2e;
  --panel-3: #3a3a3c;
  --border: #2c2c2e;
  --border-soft: #242426;
  --text: #f5f5f7;
  --muted: #8e8e93;
  --muted-2: #636366;
  --hover: #2c2c2e;
  --selected: #2c2c2e;
  --selected-text: #f5f5f7;
  --accent: #3b82f6;
  --accent-strong: #2f6fe0;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --link: #3b8eff;
  --danger: #ff453a;
  --danger-bg: rgba(255, 69, 58, 0.12);
  --ok: #30d158;
  --ok-bg: rgba(48, 209, 88, 0.12);
  --warn: #ff9f0a;
  --warn-bg: rgba(255, 159, 10, 0.12);
  --ring: rgba(59, 142, 255, 0.55);
  --tooltip-bg: rgba(44, 44, 46, 0.96);
  --backdrop: rgba(0, 0, 0, 0.6);
  --shadow-float: 0 24px 64px rgba(0, 0, 0, 0.55);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "Cascadia Code", "Roboto Mono", Consolas, ui-monospace, monospace;
  --radius-lg: 16px;
  --radius: 14px;
  --radius-sm: 10px;
  --page-max: 1320px;
}

:root.light {
  color-scheme: light;
  --bg: #f2f2f7;
  --panel: #ffffff;
  --panel-2: #f2f2f7;
  --panel-3: #e5e5ea;
  --border: #e5e5ea;
  --border-soft: #efeff4;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --muted-2: #aeaeb2;
  --hover: #f2f2f7;
  --selected: #eef3fe;
  --selected-text: #1c1c1e;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --link: #0a66e4;
  --danger: #d70015;
  --danger-bg: rgba(215, 0, 21, 0.08);
  --ok: #248a3d;
  --ok-bg: rgba(36, 138, 61, 0.1);
  --warn: #c93400;
  --warn-bg: rgba(201, 52, 0, 0.08);
  --ring: rgba(10, 102, 228, 0.45);
  --tooltip-bg: rgba(255, 255, 255, 0.98);
  --backdrop: rgba(0, 0, 0, 0.32);
  --shadow-float: 0 24px 64px rgba(0, 0, 0, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.sep {
  margin: 0 6px;
  color: var(--muted-2);
}

/* Loading skeleton */

body.is-loading .metric-value,
body.is-loading .insight-value,
body.is-loading .summary strong {
  color: transparent;
  background: var(--panel-2);
  border-radius: 8px;
  animation: shell-pulse 1.1s ease-in-out infinite;
}

body.is-loading .metric-foot,
body.is-loading .metric-change {
  opacity: 0.4;
}

@keyframes shell-pulse {
  0%,
  100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* Top navigation */

.topbar-main {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  max-width: var(--page-max);
  min-height: 56px;
  margin: 0 auto;
  padding: 0 24px;
}

.topbar-main.wide .topbar-inner {
  max-width: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: block;
  flex: 0 0 auto;
  border-radius: 7px;
  object-fit: cover;
}

.brand strong {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.top-nav::-webkit-scrollbar {
  display: none;
}

.top-link {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.top-link:hover {
  color: var(--text);
}

.top-link.active {
  background: var(--panel-2);
  color: var(--text);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.sync-state,
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot,
.dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-bg);
}

.status-dot.offline,
.dot.offline,
.dot.off {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-bg);
}

/* Controls that sit directly on the light page background */

:root.light .top-link.active,
:root.light .topbar-main .refresh-button,
:root.light .topbar-main .text-button,
:root.light .page-title .search-box,
:root.light .console-toolbar .search-box,
:root.light .console-toolbar .icon-button.filled,
:root.light .login-theme {
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--border), 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* Page */

.page {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 20px 24px 40px;
}

.page-title {
  margin: 0 0 22px;
}

.page-title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.page-title p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* Buttons */

.icon-button {
  position: relative;
  width: 34px;
  height: 34px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
}

.icon-button:hover {
  background: var(--panel-2);
  color: var(--text);
}

.icon-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.icon-button:disabled:hover {
  background: transparent;
  color: var(--muted);
}

.icon-button.filled {
  background: var(--panel-2);
}

.refresh-button,
.text-button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.refresh-button:hover,
.text-button:hover {
  background: var(--panel-3);
}

.refresh-button:disabled,
.text-button:disabled {
  opacity: 0.5;
  cursor: default;
}

.primary-button,
.text-button.primary {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.primary-button:hover,
.text-button.primary:hover {
  background: var(--accent-strong);
}

.primary-button:disabled {
  opacity: 0.5;
  cursor: default;
}

.danger-button,
.text-button.danger-action {
  background: var(--danger);
  color: #fff;
  font-weight: 600;
}

.danger-button:hover,
.text-button.danger-action:hover {
  background: color-mix(in srgb, var(--danger) 85%, #000);
}

.link-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.link-button i {
  font-size: 11px;
  transition: transform 160ms ease;
}

.link-button:hover i {
  transform: translateX(2px);
}

.link-button[hidden] {
  display: none;
}

/* Cards */

.card,
.panel {
  min-width: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--panel);
}

:root.light .card,
:root.light .panel {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 0 0 1px rgba(0, 0, 0, 0.03);
}

.eyebrow {
  display: block;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.3;
  text-transform: uppercase;
}

.card-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* Inputs */

.search-box {
  width: min(320px, 34vw);
  min-width: 180px;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}

.search-box:focus-within {
  box-shadow: 0 0 0 2px var(--ring);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.input,
.field-input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  outline: 0;
}

.input:focus,
.field-input:focus {
  border-color: var(--link);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--link) 22%, transparent);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-2);
}

/* Segmented control and chips */

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--panel-2);
}

.segmented button,
.chip {
  min-height: 28px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.segmented button:hover,
.chip:hover {
  color: var(--text);
}

.segmented button.active,
.chip.active {
  background: var(--panel-3);
  color: var(--text);
}

:root.light .segmented button.active,
:root.light .chip.active {
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge.ok,
.badge.done {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge.warn,
.badge.open {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge.accent {
  background: var(--accent-soft);
  color: var(--link);
}

/* Tables */

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 0 16px;
  text-align: left;
  white-space: nowrap;
}

.data-table th:first-child,
.data-table td:first-child {
  padding-left: 20px;
}

.data-table th:last-child,
.data-table td:last-child {
  padding-right: 20px;
}

.data-table th {
  height: 36px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.data-table td {
  height: 48px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: color-mix(in srgb, var(--panel-2) 55%, transparent);
}

.num {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

.avatar {
  width: 32px;
  height: 32px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

/* Feedback states */

.error-banner {
  display: none;
  margin: 0 0 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.error-banner.show {
  display: block;
}

.error-banner[hidden] {
  display: none;
}

/* Confirm dialog */

.confirm-panel {
  width: min(420px, calc(100vw - 32px));
  padding: 28px 24px 22px;
}

.confirm-icon {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 17px;
}

.confirm-panel h2 {
  margin: 18px 0 0;
  font-size: 19px;
  font-weight: 600;
}

.confirm-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.confirm-target {
  margin-top: 16px;
  padding: 11px 14px;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.confirm-target:empty {
  display: none;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

.danger-text {
  color: var(--danger);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 160px;
  padding: 28px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-state strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

/* Modals */

.modal[hidden],
.drawer[hidden] {
  display: none;
}

.modal,
.drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.modal-backdrop,
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: ds-fade 160ms ease both;
}

.modal-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(480px, calc(100vw - 32px));
  max-height: min(680px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow-float);
  transform: translate(-50%, -50%);
  animation: ds-pop 200ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes ds-fade {
  from { opacity: 0; }
}

@keyframes ds-pop {
  from { opacity: 0; transform: translate(-50%, -48%) scale(0.98); }
}

body.modal-open {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 860px) {
  .topbar-inner {
    flex-wrap: wrap;
    gap: 0 12px;
    padding: 10px 16px 0;
  }

  .top-nav {
    order: 3;
    width: 100%;
    margin: 0 -4px;
    padding: 8px 0 10px;
  }

  .page {
    padding: 20px 16px 36px;
  }
}

@media (max-width: 560px) {
  .sync-state,
  .refresh-button span {
    display: none;
  }

  .refresh-button {
    width: 34px;
    padding: 0;
  }

  .search-box {
    width: 100%;
  }
}
