@import url("https://fonts.googleapis.com/css2?family=Fraunces:wght@600;700&family=Sora:wght@400;500;600;700&display=swap");

:root {
  color-scheme: light;
  --bg: #eef3f9;
  --bg-deep: #dbe6f2;
  --bg-2: var(--bg-deep);
  --card: #ffffff;
  --sidebar: rgba(255, 255, 255, 0.9);
  --panel: rgba(255, 255, 255, 0.82);
  --ink: #1f2430;
  --ink-dim: #5b6778;
  --muted: #6b778a;
  --accent: #05508a;
  --accent-dark: #043a66;
  --accent-cool: #1f8a70;
  --border: rgba(31, 36, 48, 0.12);
  --shadow: 0 26px 60px rgba(31, 36, 48, 0.16);
  --tree-line: rgba(31, 36, 48, 0.14);
  --green: #22c55e;
  --topbar-bg: rgba(238, 243, 249, 0.9);
  --topbar-border: rgba(31, 36, 48, 0.08);
  --ghost-bg: rgba(31, 36, 48, 0.08);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

:root[data-theme="dark"],
body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-deep: #0b0f14;
  --bg-2: var(--bg-deep);
  --card: rgba(17, 21, 26, 0.96);
  --sidebar: rgba(17, 21, 26, 0.96);
  --panel: rgba(20, 24, 30, 0.94);
  --ink: #e5e7eb;
  --ink-dim: #c0c8d6;
  --muted: #a3b0c2;
  --accent: #4aa3ff;
  --accent-dark: #1d6fc2;
  --accent-cool: #46c4a8;
  --border: rgba(226, 232, 240, 0.12);
  --shadow: 0 26px 60px rgba(5, 6, 10, 0.55);
  --tree-line: rgba(226, 232, 240, 0.16);
  --topbar-bg: rgba(15, 19, 26, 0.94);
  --topbar-border: rgba(226, 232, 240, 0.08);
  --ghost-bg: rgba(226, 232, 240, 0.1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  height: 100vh;
  font-family: "Sora", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 600px at 10% -10%, #d7e6f7 0%, transparent 60%),
    radial-gradient(1000px 720px at 95% 15%, #b9f1e5 0%, transparent 55%),
    linear-gradient(145deg, var(--bg) 0%, var(--bg-deep) 100%);
  display: block;
  overflow: hidden;
}

body[data-theme="dark"],
:root[data-theme="dark"] body {
  background: radial-gradient(1200px 600px at 10% -10%, rgba(30, 64, 175, 0.22) 0%, transparent 60%),
    radial-gradient(1000px 720px at 95% 15%, rgba(16, 185, 129, 0.18) 0%, transparent 55%),
    linear-gradient(145deg, var(--bg) 0%, var(--bg-deep) 100%);
}

.shell {
  width: 100%;
  margin: 0;
  padding: 8px 22px 18px;
  min-height: 100%;
}

.shell.app-layout {
  padding: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  gap: 8px;
  padding: 12px 22px 10px;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--topbar-border);
}

.topbar-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

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

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  object-fit: contain;
}

.brand-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Sora", "Segoe UI", sans-serif;
}

h2 {
  font-size: 1.6rem;
  margin: 0 0 12px;
}

.logo-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.brand-logo.logo-img {
  width: 36px;
  height: 36px;
}

.logo-dark {
  display: none;
}

body[data-theme="dark"] .logo-light,
:root[data-theme="dark"] .logo-light {
  display: none;
}

body[data-theme="dark"] .logo-dark,
:root[data-theme="dark"] .logo-dark {
  display: inline-block;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  font-weight: 600;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--ink-dim);
}

body.is-embedded,
:root.is-embedded {
  background: transparent;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
}

body.is-embedded .shell {
  padding: 16px 18px 20px;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.is-embedded .card {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

body.is-embedded .card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  flex: 1;
}

body.is-embedded .card .kanban {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  align-items: stretch;
}

body.is-embedded .card .lane {
  min-height: 0;
}

body.is-embedded .card .lane-body {
  min-height: 0;
  overflow-y: auto;
  padding-right: 6px;
}

body.is-embedded .bg,
body.is-embedded .bg-orb {
  display: none;
}

input,
select,
textarea {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 14px;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(5, 80, 138, 0.2);
}

body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] textarea,
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
  background: rgba(17, 21, 26, 0.96);
}

.primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 10px 20px rgba(5, 80, 138, 0.24);
}

.ghost {
  background: var(--ghost-bg);
  border: 1px solid transparent;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink);
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--ghost-bg);
  color: var(--ink);
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.theme-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(31, 36, 48, 0.2);
}

.theme-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.muted {
  color: var(--muted);
}

.error {
  color: #b00020;
  margin-top: 8px;
}

/* Login */
.login-wrapper {
  position: relative;
  display: grid;
  place-items: center;
  min-height: calc(100vh - var(--topbar-height, 0px));
  padding: 32px 16px 40px;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}

.orb-a {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle at 30% 30%, #c7dcf2, transparent 70%);
  top: -140px;
  left: -140px;
}

.orb-b {
  width: 520px;
  height: 520px;
  background: radial-gradient(circle at 30% 30%, #b3efe6, transparent 70%);
  bottom: -180px;
  right: -140px;
}

.orb-c {
  width: 320px;
  height: 320px;
  background: radial-gradient(circle at 60% 40%, #b7d0ec, transparent 70%);
  top: 35%;
  right: 20%;
}

.login-shell {
  width: min(420px, 90vw);
  background: var(--panel);
  border-radius: 26px;
  border: 1px solid var(--border);
  padding: 32px;
  box-shadow: var(--shadow);
  z-index: 1;
}

.login-panel {
  display: grid;
  gap: 12px;
}

.login-panel h1 {
  margin: 14px 0 8px;
  font-family: "Fraunces", serif;
  font-size: 2.2rem;
}

.login-panel p {
  margin: 0 0 18px;
  color: var(--muted);
}

.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  object-fit: contain;
  display: grid;
  place-items: center;
  justify-self: center;
  background: #fff;
  box-shadow: 0 12px 24px rgba(31, 36, 48, 0.18);
}

.login-logo .logo-img {
  width: 52px;
  height: 52px;
}

.hero-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(5, 80, 138, 0.16);
  color: var(--accent-dark);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7rem;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.status-line {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(31, 36, 48, 0.08);
  color: var(--muted);
  font-size: 0.85rem;
}

.status-line.error {
  color: #b00020;
}

/* Header user */
.profile {
  position: relative;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(31, 36, 48, 0.04);
}

.profile-trigger {
  border: none;
  cursor: pointer;
  padding-right: 18px;
  position: relative;
  font-family: inherit;
  background: transparent;
}

.profile-trigger:focus-visible {
  outline: 2px solid rgba(5, 80, 138, 0.45);
  outline-offset: 2px;
}

.profile-caret {
  margin-left: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.profile-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  min-width: 200px;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 18px 36px rgba(31, 36, 48, 0.16);
  padding: 10px;
  display: none;
  z-index: 6;
}

.profile-menu.is-open {
  display: grid;
  gap: 6px;
}

.menu-item {
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}

.menu-item:hover {
  background: rgba(5, 80, 138, 0.1);
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-cool);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 0.85rem;
}

.user-name {
  margin: 0;
  font-weight: 600;
  font-size: 0.85rem;
}

.user-role {
  margin: 2px 0 0;
  font-size: 0.68rem;
  color: var(--muted);
}

/* Shell */
.app-shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 22px 18px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  box-shadow: 20px 0 40px rgba(31, 36, 48, 0.08);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 36px;
  border-radius: 14px;
  border: 1px solid rgba(31, 36, 48, 0.16);
  background: rgba(255, 255, 255, 0.9);
  padding: 0;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(31, 36, 48, 0.1);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.sidebar-toggle-icon {
  width: 20px;
  height: 12px;
  display: inline-block;
  color: inherit;
  background:
    linear-gradient(currentColor 0 0) 0 0/100% 2px,
    linear-gradient(currentColor 0 0) 0 50%/100% 2px,
    linear-gradient(currentColor 0 0) 0 100%/100% 2px;
  background-repeat: no-repeat;
}

body:not(.is-sidebar-collapsed) .sidebar-toggle-icon {
  background:
    linear-gradient(currentColor 0 0) 0 0/100% 2px,
    linear-gradient(currentColor 0 0) 0 100%/100% 2px;
  background-repeat: no-repeat;
}

.sidebar-toggle:hover {
  transform: translateY(-1px);
  background: #fff;
  box-shadow: 0 10px 20px rgba(31, 36, 48, 0.16);
}

.sidebar-toggle:focus-visible {
  outline: 2px solid rgba(5, 80, 138, 0.45);
  outline-offset: 2px;
}

.sidebar-label {
  font-weight: 600;
  font-size: 0.8rem;
}

.sidebar-sub {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.routine-list {
  display: grid;
  gap: 10px;
  min-height: 0;
}

.routine-group {
  display: grid;
  gap: 8px;
}

.routine-group-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: inherit;
}

.routine-item {
  display: grid;
  gap: 4px;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
}

.routine-item.is-active {
  border-color: rgba(5, 80, 138, 0.5);
}

.routine-item:hover {
  transform: translateY(-1px);
}

.routine-code {
  font-weight: 600;
  color: inherit;
}

.routine-name {
  font-size: 0.72rem;
  color: var(--muted);
}

.search-block {
  display: grid;
  gap: 6px;
}

.filter-input {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(31, 36, 48, 0.2);
  font-family: inherit;
  font-size: 0.92rem;
  background: #fff;
}

.filter-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(5, 80, 138, 0.2);
}

.tree-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  flex: 1;
}

.tree-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(31, 36, 48, 0.06);
  border: 1px solid rgba(31, 36, 48, 0.08);
}

.tree-label {
  display: block;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-weight: 700;
}

.tree-count {
  display: block;
  font-size: 1.15rem;
}

.tree-total {
  font-size: 0.72rem;
  color: var(--muted);
}

.tree-list {
  display: grid;
  gap: 10px;
  overflow-y: auto;
  padding-right: 6px;
  min-height: 0;
}

.tree-empty {
  padding: 16px;
  border-radius: 14px;
  border: 1px dashed rgba(31, 36, 48, 0.18);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.7);
}

.tree-group {
  border-radius: 16px;
  padding: 10px;
  border: 1px solid rgba(31, 36, 48, 0.08);
  background: rgba(255, 255, 255, 0.9);
}

.tree-group.is-collapsed .tree-group-list {
  display: none;
}

.tree-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tree-group-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tree-toggle {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid rgba(31, 36, 48, 0.2);
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tree-toggle::before {
  content: "+";
}

.tree-toggle[aria-expanded="true"]::before {
  content: "-";
}

.tree-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 14px rgba(31, 36, 48, 0.12);
}

.tree-toggle:focus-visible {
  outline: 2px solid rgba(5, 80, 138, 0.6);
  outline-offset: 2px;
}

.tree-group-title {
  margin: 0;
  font-size: 0.95rem;
}

.tree-group-count {
  font-size: 0.66rem;
  color: var(--muted);
  background: linear-gradient(135deg, rgba(14, 116, 144, 0.12), rgba(59, 130, 246, 0.12));
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 600;
  border: 1px solid rgba(31, 36, 48, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.tree-group-list {
  position: relative;
  display: grid;
  gap: 10px;
  padding-left: 18px;
  margin: 10px 0 2px 8px;
}

.tree-group-list::before {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 6px;
  width: 1px;
  background: var(--tree-line);
}

.tree-item {
  position: relative;
  border: 1px solid rgba(31, 36, 48, 0.08);
  background: #fff;
  border-radius: 16px;
  padding: 12px 14px 12px 20px;
  width: 100%;
  display: grid;
  gap: 6px;
  text-align: left;
  color: inherit;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border 0.2s ease;
}

.tree-item::before {
  content: "";
  position: absolute;
  left: -9px;
  top: 14px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-cool);
  box-shadow: 0 0 0 4px rgba(31, 138, 112, 0.2);
}

.tree-item::after {
  content: "";
  position: absolute;
  left: -2px;
  top: 18px;
  width: 9px;
  height: 1px;
  background: var(--tree-line);
}

.tree-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(31, 36, 48, 0.12);
}

.tree-item:focus-visible {
  outline: 2px solid rgba(5, 80, 138, 0.6);
  outline-offset: 2px;
}

.tree-item.is-active {
  border-color: rgba(5, 80, 138, 0.5);
  box-shadow: 0 12px 22px rgba(5, 80, 138, 0.2);
}

.tree-item.is-active::before {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(5, 80, 138, 0.22);
}

.tree-item-title {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--ink);
}

.tree-item-meta {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.45;
}

.tree-item-note {
  font-size: 0.68rem;
  color: var(--muted);
}

.routine-version {
  font-weight: 600;
}

.tree-item[data-accent="sun"]::before {
  background: #6ea8d8;
  box-shadow: 0 0 0 4px rgba(110, 168, 216, 0.25);
}

.tree-item[data-accent="ocean"]::before {
  background: #2dd4bf;
  box-shadow: 0 0 0 4px rgba(45, 212, 191, 0.22);
}

.tree-item[data-accent="slate"]::before {
  background: #94a3b8;
  box-shadow: 0 0 0 4px rgba(148, 163, 184, 0.22);
}

.tree-item[data-accent="amber"]::before {
  background: #2f6ea7;
  box-shadow: 0 0 0 4px rgba(47, 110, 167, 0.22);
}

.tree-item[data-accent="rose"]::before {
  background: #fb7185;
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.22);
}

.tree-item[data-accent="mint"]::before {
  background: #34d399;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.22);
}

.main-panel {
  position: relative;
  background: radial-gradient(900px 520px at 70% 10%, rgba(255, 255, 255, 0.6), transparent 60%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.6) 0%, rgba(236, 226, 214, 0.7) 100%);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 20px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.routine-shell {
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  flex: 1;
}

.routine-frame-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.routine-frame-wrap.is-visible {
  display: grid;
  grid-template-rows: auto 1fr;
}

.routine-frame-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  min-height: 44px;
}

.routine-frame-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.routine-frame-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

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

.routine-label {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.routine-actions {
  display: flex;
  gap: 8px;
}

.routine-actions.pill {
  gap: 10px;
}

.routine-pill {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  cursor: pointer;
  background: #f3f4f6;
  color: #111827;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.routine-pill .pill-icon {
  font-size: 14px;
}

.routine-pill.danger {
  background: #ef4444;
  border-color: #dc2626;
  color: #fff;
}

.routine-pill.success {
  background: #22c55e;
  border-color: #16a34a;
  color: #fff;
}

:root[data-theme="dark"] .routine-pill {
  background: #1f2937;
  color: #fff;
  border-color: rgba(226, 232, 240, 0.2);
}

.routine-frame {
  width: 100%;
  height: 100%;
  flex: 1;
  min-height: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  display: block;
  animation: routineIn 0.25s ease;
}

@keyframes routineIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.empty-state {
  width: 100%;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 32px;
}

.routine-shell .empty-state {
  padding: 18px;
}

.empty-card {
  width: min(520px, 90%);
  text-align: center;
  border-radius: 26px;
  padding: 48px 36px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(31, 36, 48, 0.08);
  color: var(--ink);
  box-shadow: 0 24px 50px rgba(31, 36, 48, 0.16);
}

.empty-card h3 {
  margin: 16px 0 8px;
  font-family: "Fraunces", serif;
  font-size: 2.2rem;
}

.empty-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.empty-logo {
  width: 84px;
  height: 84px;
  margin: 0 auto;
  border-radius: 22px;
  object-fit: cover;
  box-shadow: 0 12px 24px rgba(31, 36, 48, 0.18);
  background: #fff;
  padding: 10px;
  display: grid;
  place-items: center;
}

.empty-logo .logo-img {
  width: 54px;
  height: 54px;
}

.empty-status {
  margin-top: 18px;
  font-size: 0.8rem;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.2);
}

:root[data-theme="dark"] .sidebar {
  box-shadow: 20px 0 40px rgba(2, 4, 8, 0.6);
}

:root[data-theme="dark"] .sidebar-toggle {
  background: rgba(15, 19, 26, 0.9);
  border-color: var(--border);
  color: var(--ink);
  box-shadow: 0 8px 16px rgba(5, 6, 10, 0.5);
}

:root[data-theme="dark"] .sidebar-toggle:hover {
  background: rgba(20, 24, 30, 0.9);
}

:root[data-theme="dark"] .user-card {
  background: rgba(226, 232, 240, 0.06);
}

:root[data-theme="dark"] .profile-menu {
  background: rgba(19, 24, 30, 0.96);
  border-color: rgba(226, 232, 240, 0.12);
  box-shadow: 0 18px 36px rgba(5, 6, 10, 0.5);
}

:root[data-theme="dark"] .menu-item {
  color: var(--ink);
}

:root[data-theme="dark"] .menu-item:hover {
  background: rgba(148, 163, 184, 0.12);
}

:root[data-theme="dark"] .login-logo {
  background: rgba(19, 24, 30, 0.92);
}

:root[data-theme="dark"] .tree-header {
  background: rgba(226, 232, 240, 0.06);
  border-color: rgba(226, 232, 240, 0.12);
}

:root[data-theme="dark"] .filter-input {
  background: rgba(19, 24, 30, 0.9);
  border-color: rgba(226, 232, 240, 0.14);
  color: var(--ink);
}

:root[data-theme="dark"] .tree-toggle {
  background: rgba(19, 24, 30, 0.92);
  border-color: rgba(226, 232, 240, 0.16);
  color: var(--ink);
  box-shadow: 0 8px 14px rgba(5, 6, 10, 0.4);
}

:root[data-theme="dark"] .tree-empty {
  background: rgba(19, 24, 30, 0.85);
  border-color: rgba(226, 232, 240, 0.16);
}

:root[data-theme="dark"] .tree-group {
  background: rgba(19, 24, 30, 0.92);
  border-color: rgba(226, 232, 240, 0.12);
}

:root[data-theme="dark"] .tree-item {
  background: rgba(19, 23, 30, 0.92);
  border-color: rgba(226, 232, 240, 0.14);
  box-shadow: 0 10px 22px rgba(5, 6, 10, 0.35);
}

:root[data-theme="dark"] .tree-item:hover {
  box-shadow: 0 14px 26px rgba(5, 6, 10, 0.45);
}

:root[data-theme="dark"] .tree-item.is-active {
  border-color: rgba(74, 163, 255, 0.55);
  box-shadow: 0 16px 28px rgba(74, 163, 255, 0.22);
}

:root[data-theme="dark"] .tree-item.is-active::before {
  box-shadow: 0 0 0 4px rgba(74, 163, 255, 0.28);
}

:root[data-theme="dark"] .tree-group-count {
  background: linear-gradient(135deg, rgba(14, 116, 144, 0.22), rgba(59, 130, 246, 0.22));
  color: var(--ink);
  border-color: rgba(226, 232, 240, 0.12);
  box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.4);
}

:root[data-theme="dark"] .main-panel {
  background: radial-gradient(900px 520px at 70% 10%, rgba(30, 64, 175, 0.24) 0%, transparent 60%),
    linear-gradient(145deg, rgba(13, 17, 23, 0.9) 0%, rgba(7, 10, 14, 0.9) 100%);
}

:root[data-theme="dark"] .routine-frame-wrap {
  border-color: rgba(226, 232, 240, 0.12);
  box-shadow: 0 26px 60px rgba(5, 6, 10, 0.55);
}

:root[data-theme="dark"] .routine-frame-bar {
  background: rgba(19, 24, 30, 0.92);
  border-bottom-color: rgba(226, 232, 240, 0.12);
}

:root[data-theme="dark"] .routine-frame {
  background: #0b0f14;
}

:root[data-theme="dark"] .empty-card {
  background: rgba(19, 24, 30, 0.92);
  border-color: rgba(226, 232, 240, 0.12);
  box-shadow: 0 24px 50px rgba(5, 6, 10, 0.5);
}

:root[data-theme="dark"] .empty-logo {
  background: rgba(19, 24, 30, 0.92);
}

:root[data-theme="dark"] .toast {
  background: rgba(19, 24, 30, 0.95);
  border-color: rgba(226, 232, 240, 0.12);
}

:root[data-theme="dark"] .modal {
  background: rgba(6, 8, 12, 0.62);
}

:root[data-theme="dark"] .status-line {
  background: rgba(226, 232, 240, 0.08);
  color: var(--muted);
}

:root[data-theme="dark"] .empty-state {
  background: transparent;
  border-color: transparent;
}

.filters.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.toolbar-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
  flex: 1 1 680px;
}

.toolbar-group label {
  margin-bottom: 0;
}

.toolbar-group .grow {
  grid-column: span 2;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.status {
  background: rgba(5, 80, 138, 0.08);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 12px;
  color: var(--ink-dim);
}

.kanban {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.lane {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  min-height: 440px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lane header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.lane h3 {
  margin: 0;
  font-family: 'Sora', sans-serif;
  font-size: 20px;
}

.lane-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 320px;
}

.lane.locked {
  opacity: 0.9;
}

.lane-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.badge {
  background: rgba(5, 80, 138, 0.08);
  color: var(--ink);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}

.card-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  cursor: pointer;
  transition: transform 0.18s ease, border 0.18s ease;
}

.card-item.dragging {
  opacity: 0.6;
  transform: scale(0.98);
}

.lane-body.drag-over {
  outline: 2px dashed rgba(5, 80, 138, 0.35);
  outline-offset: 6px;
  border-radius: 12px;
}

.card-item h4 {
  margin: 0 0 6px;
  font-size: 15px;
}

.card-meta {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.card-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(5, 80, 138, 0.12);
  color: var(--accent-dark);
  margin-top: 8px;
}

.card-item:hover {
  transform: translateY(-1px);
  border-color: rgba(5, 80, 138, 0.25);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 25, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 7;
}

.modal-card {
  background: var(--card);
  border-radius: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 24px;
  width: min(420px, 92vw);
  display: grid;
  gap: 14px;
}

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

.modal-body {
  display: grid;
  gap: 16px;
}

.modal-info {
  font-size: 13px;
  color: var(--muted);
  background: var(--panel);
  padding: 10px;
  border-radius: var(--radius-sm);
}

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

.modal-footer-note {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.auto-cnpj-card {
  width: min(520px, 94vw);
}

.auto-cnpj-form {
  display: grid;
  gap: 12px;
}

.auto-cnpj-list {
  display: grid;
  gap: 10px;
  max-height: 280px;
  overflow: auto;
  padding-right: 4px;
}

.auto-cnpj-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.auto-cnpj-meta {
  display: grid;
  gap: 4px;
}

.auto-cnpj-code {
  font-weight: 600;
  letter-spacing: 0.3px;
}

.auto-cnpj-status {
  font-size: 12px;
  color: var(--muted);
}

.auto-cnpj-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.auto-cnpj-actions .ghost {
  font-size: 12px;
  padding: 6px 12px;
}

.ghost.danger {
  background: rgba(239, 68, 68, 0.12);
  color: #b91c1c;
  border-color: rgba(239, 68, 68, 0.2);
}

body[data-theme="dark"] .ghost.danger,
:root[data-theme="dark"] .ghost.danger {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.18);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  min-width: 220px;
  max-width: 320px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid rgba(31, 36, 48, 0.18);
  box-shadow: 0 14px 28px rgba(31, 36, 48, 0.2);
  font-size: 0.82rem;
  font-weight: 600;
}

body.is-sidebar-collapsed .app-shell {
  grid-template-columns: 1fr;
}

body.is-sidebar-collapsed .sidebar {
  position: absolute;
  top: 22px;
  left: 22px;
  width: auto;
  height: auto;
  min-height: 0;
  padding: 0;
  gap: 0;
  background: transparent;
  border-right: none;
  box-shadow: none;
  overflow: visible;
  z-index: 6;
}

body.is-sidebar-collapsed .sidebar-toggle {
  width: 42px;
  height: 38px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 12px 22px rgba(31, 36, 48, 0.18);
}

body.is-sidebar-collapsed .main-panel {
  padding-left: 86px;
}

body.is-sidebar-collapsed .sidebar-head {
  justify-content: flex-start;
}

body.is-sidebar-collapsed .sidebar-label,
body.is-sidebar-collapsed .sidebar-sub,
body.is-sidebar-collapsed .search-block,
body.is-sidebar-collapsed .tree-panel {
  display: none;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 300px 1fr;
  }

  .sidebar {
    padding: 18px;
  }
}

@media (max-width: 900px) {
  body {
    height: auto;
    overflow: auto;
  }

  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
    margin-top: var(--topbar-height, 0px);
  }

  .login-wrapper {
    margin-top: var(--topbar-height, 0px);
  }

  .sidebar {
    height: auto;
    overflow: visible;
  }

  .tree-list {
    max-height: 45vh;
  }

  .main-panel {
    min-height: 70vh;
    height: auto;
  }
}

@media (max-width: 600px) {
  .topbar-main {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .empty-card {
    padding: 36px 24px;
  }

  .empty-card h3 {
    font-size: 1.8rem;
  }

  .toast {
    left: 16px;
    right: 16px;
    max-width: none;
  }

  .toolbar-group .grow {
    grid-column: span 1;
  }
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.dashboard-card {
  position: relative;
  overflow: hidden;
}

.dashboard-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(600px 220px at 10% -20%, rgba(74, 163, 255, 0.12), transparent 60%);
  pointer-events: none;
  opacity: 0.7;
}

.dashboard-card > * {
  position: relative;
  z-index: 1;
}

.dashboard-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.dashboard-meta .badge {
  font-weight: 600;
}

.dash-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: grid;
  gap: 6px;
  min-height: 120px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  animation: dashRise 0.45s ease both;
  cursor: pointer;
}

.dash-card::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 4px;
  opacity: 0.6;
  background: var(--accent);
}

.dash-card[data-tone="warn"]::after {
  background: #f59e0b;
}

.dash-card[data-tone="info"]::after {
  background: var(--accent);
}

.dash-card[data-tone="success"]::after {
  background: #22c55e;
}

.dash-card[data-tone="total"]::after {
  background: var(--accent-cool);
}

.dash-card:hover {
  transform: translateY(-2px);
  border-color: rgba(5, 80, 138, 0.28);
  box-shadow: 0 14px 24px rgba(31, 36, 48, 0.18);
}

.dash-label {
  font-size: 0.85rem;
  color: var(--ink-dim);
  font-weight: 600;
}

.dash-count {
  font-size: 2rem;
  font-weight: 700;
  color: var(--ink);
}

.dash-sub {
  font-size: 0.85rem;
  color: var(--muted);
}

.dash-bar {
  margin-top: 18px;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--ghost-bg);
  display: flex;
}

.dash-bar-seg {
  height: 100%;
  width: 0%;
  transition: width 0.35s ease;
}

.dash-bar-seg.warn {
  background: #f59e0b;
}

.dash-bar-seg.info {
  background: var(--accent);
}

.dash-bar-seg.success {
  background: #22c55e;
}

.dashboard-visuals {
  margin-top: 22px;
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(200px, 1fr) minmax(220px, 280px) minmax(220px, 280px);
  gap: 18px;
  align-items: stretch;
}

.dash-donut-card {
  display: grid;
  place-items: center;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  background: var(--panel);
  height: 100%;
  transition: transform 0.2s ease, border-color 0.2s ease;
  animation: dashRise 0.5s ease both;
}

.dash-donut {
  position: relative;
  width: 220px;
  height: 220px;
}

.donut {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.donut-ring {
  fill: none;
  stroke: var(--ghost-bg);
  stroke-width: 16;
}

.donut-seg {
  fill: none;
  stroke-width: 16;
  stroke-linecap: round;
  transition: stroke-dasharray 0.35s ease, stroke-dashoffset 0.35s ease;
}

.donut-seg.seg-aguardando {
  stroke: #f59e0b;
}

.donut-seg.seg-agendadas {
  stroke: var(--accent);
}

.donut-seg.seg-concluidas {
  stroke: #22c55e;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2px;
  line-height: 1;
  transform: translateY(2px);
}

.donut-total {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.donut-label {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1;
}

.dash-legend {
  display: grid;
  gap: 12px;
}

.legend-item {
  display: flex;
  gap: 12px;
  align-items: center;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.legend-dot.warn {
  background: #f59e0b;
}

.legend-dot.info {
  background: var(--accent);
}

.legend-dot.success {
  background: #22c55e;
}

.legend-label {
  font-weight: 600;
  color: var(--ink);
}

.legend-value {
  font-size: 0.85rem;
  color: var(--muted);
}

.ranking-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: grid;
  gap: 12px;
  grid-template-rows: auto 1fr;
  height: 100%;
  max-height: 260px;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  animation: dashRise 0.55s ease both;
}

.ranking-card header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ranking-card h3 {
  margin: 0;
  font-size: 1rem;
}

.rank-list {
  display: grid;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
  padding-right: 4px;
}

.ranking-card .rank-list {
  max-height: 190px;
}

.rank-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.rank-row:hover {
  transform: translateY(-1px);
  border-color: rgba(5, 80, 138, 0.25);
  background: rgba(74, 163, 255, 0.08);
}

.dash-donut-card:hover,
.ranking-card:hover {
  transform: translateY(-2px);
  border-color: rgba(5, 80, 138, 0.24);
  box-shadow: 0 14px 24px rgba(31, 36, 48, 0.18);
}

.rank-pos {
  font-weight: 700;
  color: var(--accent);
  width: 42px;
}

.rank-name {
  font-weight: 600;
  color: var(--ink);
}

.rank-total {
  font-weight: 700;
  color: var(--ink-dim);
}

.rank-empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 6px 4px;
}

.items-modal-card {
  width: min(820px, 94vw);
  max-height: 82vh;
}

.items-list {
  display: grid;
  gap: 12px;
  max-height: 52vh;
  overflow-y: auto;
  padding-right: 4px;
}

.items-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.items-row:hover {
  transform: translateY(-1px);
  border-color: rgba(5, 80, 138, 0.2);
}

.items-main {
  display: grid;
  gap: 4px;
}

.items-title {
  font-weight: 700;
  color: var(--ink);
}

.items-sub {
  font-size: 0.82rem;
  color: var(--muted);
}

.items-aside {
  display: grid;
  gap: 6px;
  justify-items: end;
  align-content: start;
}

.items-status {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(5, 80, 138, 0.12);
  color: var(--accent-dark);
  font-weight: 600;
}

.items-empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 8px 4px;
}

@keyframes dashRise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dash-card,
  .dash-donut-card,
  .ranking-card {
    animation: none;
    transition: none;
  }

  .rank-row {
    transition: none;
  }
}

@media (max-width: 1300px) {
  .dashboard-visuals {
    grid-template-columns: minmax(220px, 260px) 1fr;
  }

  .ranking-card {
    grid-column: 1 / -1;
    max-height: none;
  }
}

@media (max-width: 840px) {
  .dashboard-visuals {
    grid-template-columns: 1fr;
  }
}
