:root {
  --plum-900: #1E0728;
  --plum-800: #2A0B37;
  --plum-700: #3A0F4A;
  --plum-600: #49155C;
  --plum-500: #5E1D75;
  --violet-600: #7A2A96;
  --violet-400: #A855F7;
  --violet-300: #C084FC;
  --violet-200: #DDBEFB;

  --bg: #F7F4FB;
  --surface: #FFFFFF;
  --line: #ECE4F4;
  --track: #F3EBFA;
  --ink: #1B0A24;
  --muted: #6C5A77;

  --good: #15803D;
  --good-bg: rgba(74, 222, 128, 0.16);
  --warn: #B45309;
  --warn-bg: rgba(245, 158, 11, 0.16);
  --danger: #B91C1C;
  --danger-bg: rgba(248, 113, 113, 0.16);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;

  --sidebar-w: 264px;
  --topbar-h: 68px;

  --font-display: 'Sora', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
}

body.is-login {
  display: grid;
  place-items: center;
  background:
    radial-gradient(760px 420px at 20% 0%, var(--plum-600) 0%, transparent 62%),
    linear-gradient(170deg, var(--plum-800) 0%, var(--plum-900) 100%);
}

body.drawer-open { overflow: hidden; }

img { max-width: 100%; display: block; }
h1, h2, h3 { margin: 0; font-family: var(--font-display); letter-spacing: -0.02em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

:focus-visible { outline: 3px solid var(--violet-400); outline-offset: 2px; border-radius: 8px; }

.svg-defs { position: absolute; width: 0; height: 0; }
.icon { width: 20px; height: 20px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 0.96rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 180ms ease, transform 160ms ease, opacity 160ms ease;
}

.btn-block { width: 100%; }
.btn-primary { background: var(--violet-400); color: #22062E; }
.btn-primary:hover { background: var(--violet-300); }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost {
  margin-top: var(--space-2);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.24);
  color: #FFFFFF;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn.is-loading { position: relative; color: transparent; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(34, 6, 46, 0.3);
  border-top-color: #22062E;
  animation: spin 700ms linear infinite;
}

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

.login { width: 100%; padding: var(--space-4); display: grid; place-items: center; }

.login-card {
  width: 100%;
  max-width: 420px;
  padding: var(--space-5);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  text-align: center;
  color: #FFFFFF;
}

.login-logo { height: 62px; width: auto; margin: 0 auto var(--space-3); object-fit: contain; }

.login-badge {
  display: inline-block;
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  background: rgba(168, 85, 247, 0.22);
  color: var(--violet-200);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.login h1 { margin-top: var(--space-3); font-size: 1.4rem; font-weight: 700; }
.login-text { margin-top: var(--space-2); font-size: 0.92rem; color: var(--violet-200); }

.form { display: grid; gap: var(--space-3); margin-top: var(--space-4); text-align: left; }
.field { display: grid; gap: var(--space-2); }

.field-label { font-family: var(--font-display); font-size: 0.86rem; font-weight: 600; }

.field-control {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-md);
  transition: border-color 180ms ease;
}

.field-control:focus-within { border-color: var(--violet-400); }
.field.has-error .field-control { border-color: #F87171; }

.field-prefix { padding-left: 14px; font-family: var(--font-display); font-weight: 600; color: var(--violet-200); }

.input {
  flex: 1;
  min-width: 0;
  min-height: 50px;
  padding: 0 14px;
  background: none;
  border: 0;
  color: #FFFFFF;
  font-family: var(--font-body);
  font-size: 1rem;
}

.input:focus { outline: none; }

.reveal {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-right: 3px;
  background: none;
  border: 0;
  border-radius: 10px;
  color: var(--violet-200);
  cursor: pointer;
}

.reveal:hover { background: rgba(255, 255, 255, 0.08); }
.field-error { font-size: 0.84rem; color: #F87171; }
.field-error:empty { display: none; }

.admin { display: flex; min-height: 100dvh; }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  height: 100dvh;
  padding: var(--space-4) var(--space-3);
  background: var(--plum-900);
  color: rgba(214, 194, 228, 0.75);
  transform: translateX(-100%);
  transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
}

.sidebar.is-open { transform: translateX(0); }

.sidebar-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-2) var(--space-4);
}

.sidebar-logo { height: 34px; width: auto; object-fit: contain; }

.sidebar-badge {
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  background: var(--violet-400);
  color: #22062E;
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
}

.sidebar-close { margin-left: auto; }

.nav {
  flex: 1;
  display: grid;
  align-content: start;
  gap: var(--space-4);
  overflow: hidden;
}

.nav-group { display: grid; gap: 2px; }

.nav-title {
  padding: 0 var(--space-2) var(--space-1);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(214, 194, 228, 0.45);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background-color 180ms ease, color 180ms ease;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #FFFFFF; }

.nav-item.is-active {
  background: var(--violet-400);
  color: #22062E;
  font-weight: 600;
}

.nav-icon { flex: 0 0 auto; width: 19px; height: 19px; }

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-top: var(--space-3);
  margin-top: var(--space-3);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--violet-400);
  color: #22062E;
  font-family: var(--font-display);
  font-weight: 700;
}

.sidebar-user { display: grid; min-width: 0; flex: 1; }

.sidebar-user-name {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  color: #FFFFFF;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-role { font-size: 0.76rem; color: rgba(214, 194, 228, 0.6); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  background: none;
  border: 0;
  border-radius: var(--radius-md);
  color: inherit;
  cursor: pointer;
  transition: background-color 180ms ease;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(27, 10, 36, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}

.scrim.is-visible { opacity: 1; pointer-events: auto; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--topbar-h);
  padding: 0 var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

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

.topbar-title {
  flex: 1;
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn.is-spinning .icon { animation: spin 700ms linear; }

.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: var(--space-4);
  padding: var(--space-4);
}

.page-intro h2 { font-size: 1.5rem; font-weight: 700; }
.page-intro p { margin-top: var(--space-1); color: var(--muted); font-size: 0.94rem; }

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-3);
}

.kpi {
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.kpi-label { font-size: 0.84rem; color: var(--muted); }

.kpi-value {
  margin-top: var(--space-2);
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.kpi-good .kpi-value { color: var(--good); }
.kpi-warn .kpi-value { color: var(--warn); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-4) var(--space-3);
}

.panel-head h3 { flex: 1; font-size: 1.05rem; font-weight: 700; }
.panel-body { padding: 0 var(--space-4) var(--space-4); }

.columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

.segment {
  position: relative;
  display: flex;
  gap: 4px;
  margin: 0 var(--space-4) var(--space-3);
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--track);
  overflow-x: auto;
  scrollbar-width: none;
}

.segment::-webkit-scrollbar { display: none; }

.segment-pill {
  position: absolute;
  top: 4px;
  left: 4px;
  height: calc(100% - 8px);
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: 0 3px 10px rgba(43, 12, 56, 0.1);
  transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1), width 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

.segment-pill.no-anim { transition: none; }

.segment-btn {
  position: relative;
  z-index: 1;
  flex: 1 0 auto;
  min-height: 38px;
  padding: 0 16px;
  background: none;
  border: 0;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color 220ms ease;
}

.segment-btn.is-active { color: var(--ink); }

.table { display: grid; }

.tr {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1fr 1.2fr 1.2fr;
  gap: var(--space-3);
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.tr:last-child { border-bottom: 0; }

.th {
  padding-top: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.cell-strong {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
}

.mini-bar {
  display: block;
  height: 5px;
  margin-top: 5px;
  border-radius: var(--radius-pill);
  background: var(--track);
  overflow: hidden;
}

.mini-bar span {
  display: block;
  height: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--plum-500), var(--violet-400));
}

.tag {
  display: inline-block;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  background: var(--track);
  color: var(--violet-600);
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
}

.tag-completed { background: var(--good-bg); color: var(--good); }
.tag-running { background: var(--warn-bg); color: var(--warn); }
.tag-cancelled { background: var(--danger-bg); color: var(--danger); }

.feed { margin: 0; padding: 0; list-style: none; }

.feed-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.feed-item:last-child { border-bottom: 0; }
.feed-main { display: grid; gap: 2px; min-width: 0; }

.feed-title {
  font-family: var(--font-display);
  font-size: 0.94rem;
  font-weight: 600;
}

.feed-sub { font-size: 0.8rem; color: var(--muted); }

.feed-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.feed-side { display: grid; gap: 4px; justify-items: end; flex: 0 0 auto; }

.feed-amount {
  font-family: var(--font-display);
  font-size: 0.94rem;
  font-weight: 700;
  white-space: nowrap;
}

.feed-amount.is-in { color: var(--good); }
.feed-amount.is-out { color: var(--danger); }

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  background: var(--violet-400);
  color: #22062E;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
}

.empty {
  padding: var(--space-5) 0;
  text-align: center;
  font-size: 0.92rem;
  color: var(--muted);
}

.building {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.building-mark {
  width: 54px;
  height: 54px;
  margin-bottom: var(--space-2);
  border: 2px dashed var(--line);
  border-radius: 16px;
}

.building h2 { font-size: 1.3rem; font-weight: 700; }
.building p { color: var(--muted); }

.skeleton {
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--track) 25%, #EFE6F7 37%, var(--track) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

.skeleton-kpi { height: 104px; border-radius: var(--radius-lg); }
.skeleton-row { height: 54px; margin-bottom: var(--space-2); }

@keyframes shimmer {
  from { background-position: 100% 50%; }
  to { background-position: 0 50%; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 60;
  width: min(420px, calc(100% - 32px));
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--plum-900);
  color: #FFFFFF;
  font-size: 0.92rem;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, 18px);
  opacity: 0;
  transition: opacity 220ms ease, transform 220ms ease;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast-error { border-color: rgba(248, 113, 113, 0.55); }

@media (max-width: 720px) {
  .tr {
    grid-template-columns: 1fr auto;
    gap: var(--space-2);
  }
  .tr span:nth-child(3), .tr span:nth-child(4) { display: none; }
  .th { display: none; }
}

@media (min-width: 1024px) {
  .sidebar { transform: translateX(0); }
  .sidebar-close, .topbar-menu { display: none; }
  .scrim { display: none; }
  .main { margin-left: var(--sidebar-w); }
  .content { padding: var(--space-5); }
  .columns { grid-template-columns: 1fr 1fr; }
  .topbar { padding-inline: var(--space-5); }
}

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