/* ============================================
   Digital Anima — Base Styles
   ============================================ */

/* --- Reset & Base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--aw-color-bg-secondary);
  color: var(--aw-color-text-primary);
  height: var(--vh-fallback, 100vh);
  height: 100svh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* --- Login Screen --- */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--aw-color-bg-secondary);
}

.login-screen.hidden {
  display: none;
}

.login-card {
  background: var(--aw-color-bg-primary);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  padding: 40px 36px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}

.login-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--aw-color-accent);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 0.9rem;
  color: var(--aw-color-text-secondary);
  margin-bottom: 24px;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.user-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: var(--aw-color-accent);
  color: var(--aw-color-bg-primary);
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.user-btn:hover,
.user-btn:active {
  background: var(--aw-color-accent-hover);
}

.user-btn:focus-visible {
  outline: 2px solid var(--aw-color-accent-light);
  outline-offset: 2px;
}

.login-guest {
  border-top: 1px solid var(--aw-color-border);
  padding-top: 16px;
}

.btn-guest {
  background: none;
  border: none;
  color: var(--aw-color-text-muted);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: underline;
  transition: color 0.15s;
}

.btn-guest:hover,
.btn-guest:active {
  color: var(--aw-color-text-secondary);
}

.btn-guest:focus-visible {
  outline: 2px solid var(--aw-color-accent);
  outline-offset: 2px;
}

/* --- User Info (header) --- */
.header-spacer {
  flex: 1;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.user-label {
  font-size: 0.85rem;
  color: var(--aw-color-text-secondary);
}

.btn-logout {
  padding: 4px 10px;
  border: 1px solid var(--aw-color-border-medium);
  border-radius: 6px;
  background: var(--aw-color-bg-primary);
  font-size: 0.78rem;
  font-family: inherit;
  color: var(--aw-color-text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-logout:hover,
.btn-logout:active {
  border-color: var(--aw-color-error);
  color: var(--aw-color-error);
}

.btn-logout:focus-visible {
  outline: 2px solid var(--aw-color-error);
  outline-offset: 2px;
}

/* --- Header --- */
.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 44px;
  background: var(--aw-color-bg-primary);
  border-bottom: 1px solid var(--aw-color-border);
  flex-shrink: 0;
}

.app-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--aw-color-accent);
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.anima-selector {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.anima-dropdown {
  min-width: 220px;
  max-width: 360px;
  width: 100%;
  padding: 6px 12px;
  border: 1px solid var(--aw-color-border-medium);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--aw-color-text-primary);
  background: var(--aw-color-bg-primary);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

.anima-dropdown:focus,
.anima-dropdown:focus-visible {
  border-color: var(--aw-color-accent);
  outline: 2px solid var(--aw-color-accent);
  outline-offset: 2px;
}

.system-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--aw-color-text-secondary);
  flex-shrink: 0;
}

/* --- Status Dots --- */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-idle {
  background: var(--aw-color-success);
}

.status-thinking {
  background: var(--aw-color-warning);
  animation: pulse-amber 1.2s ease-in-out infinite;
  animation-play-state: var(--aw-animation-play-state);
  box-shadow: 0 0 6px 2px color-mix(in srgb, var(--aw-color-warning) 50%, transparent 50%);
}

.status-error {
  background: var(--aw-color-error);
}

.status-offline {
  background: var(--aw-color-text-placeholder);
}

@keyframes pulse-amber {
  0%, 100% { opacity: 1; transform: scale(1); box-shadow: 0 0 6px 2px color-mix(in srgb, var(--aw-color-warning) 50%, transparent 50%); }
  50% { opacity: 0.5; transform: scale(1.3); box-shadow: 0 0 10px 4px color-mix(in srgb, var(--aw-color-warning) 70%, transparent 30%); }
}

/* ── Anima Visual States ──────────────────── */

/* Sleeping State (stopped / not_found) */
.anima-item--sleeping {
    opacity: 0.45;
    filter: grayscale(0.85) brightness(0.8);
}

.anima-item--sleeping .anima-avatar-img {
    animation: breathe 4s ease-in-out infinite;
    animation-play-state: var(--aw-animation-play-state);
}

@keyframes breathe {
    0%, 100% { opacity: 0.5; }
    50%      { opacity: 0.7; }
}

.anima-item--sleeping .anima-avatar-initial {
    animation: breathe 4s ease-in-out infinite;
    animation-play-state: var(--aw-animation-play-state);
    filter: grayscale(1);
}

.anima-item--sleeping .anima-avatar-placeholder {
    filter: grayscale(1);
    opacity: 0.4;
}

.anima-item--sleeping .anima-status {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.4);
}

/* Bootstrapping State (loading) */
.anima-item--loading {
    opacity: 0.75;
    pointer-events: none;
}

.anima-avatar-wrapper {
    position: relative;
}

.anima-avatar-spinner {
    display: none;
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 3px solid rgba(245, 158, 11, 0.2);
    border-top-color: var(--aw-color-warning);
    animation: anima-spin 1.2s linear infinite;
    animation-play-state: var(--aw-animation-play-state);
}

.anima-item--loading .anima-avatar-spinner {
    display: block;
}

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

.anima-progress {
    display: none;
    height: 3px;
    border-radius: 2px;
    background: rgba(245, 158, 11, 0.15);
    overflow: hidden;
    margin-top: 4px;
}

.anima-item--loading .anima-progress {
    display: block;
}

.anima-progress-bar {
    width: 40%;
    height: 100%;
    background: var(--aw-color-warning);
    border-radius: 2px;
    animation: indeterminate 1.5s ease-in-out infinite;
    animation-play-state: var(--aw-animation-play-state);
}

@keyframes indeterminate {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

.anima-item--loading .anima-status {
    background: rgba(245, 158, 11, 0.12);
    color: var(--aw-color-warning);
}

/* State Transitions */
.anima-item {
    transition: opacity 0.4s ease, filter 0.4s ease, transform 0.3s ease;
}

.anima-item--just-activated {
    animation: activate-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    animation-play-state: var(--aw-animation-play-state);
}

@keyframes activate-pop {
    0%   { transform: scale(0.97); opacity: 0.75; }
    50%  { transform: scale(1.02); }
    100% { transform: scale(1);    opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .anima-item--sleeping .anima-avatar-img,
    .anima-item--sleeping .anima-avatar-initial {
        animation: none;
    }
    .anima-avatar-spinner,
    .anima-progress-bar {
        animation: none;
    }
    .anima-item--just-activated {
        animation: none;
    }
}

/* --- Main Layout --- */
.app-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 1px;
  background: var(--aw-color-bg-tertiary);
}

/* --- Panels (shared) --- */
.panel {
  background: var(--aw-color-bg-primary);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* --- Utility / Loading --- */
.loading-placeholder {
  color: var(--aw-color-text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 20px 0;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--aw-color-border-dark);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--aw-color-text-muted);
}

/* ── Login Form ───────────────────────────── */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}
.login-form input {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--aw-color-border-subtle);
  border-radius: 0.5rem;
  font-size: 0.95rem;
  background: var(--aw-color-bg-panel);
  color: var(--aw-color-text-primary);
}
.login-form input:focus {
  outline: none;
  border-color: var(--aw-color-info);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}
.btn-login {
  padding: 0.6rem;
  border: none;
  border-radius: 0.5rem;
  background: var(--aw-color-info);
  color: var(--aw-color-bg-primary);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-login:hover {
  background: var(--aw-color-info-hover);
}
.login-error {
  color: var(--aw-color-error);
  font-size: 0.85rem;
  padding: 0.4rem;
  text-align: center;
}
.login-error.hidden {
  display: none;
}
/* ── Auth Banner ──────────────────────────── */
.auth-banner {
  background: var(--aw-color-warning-bg);
  border: 1px solid var(--aw-color-warning);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}
.auth-banner a {
  color: var(--aw-color-warning-text-dark);
  font-weight: 500;
  text-decoration: underline;
}
.auth-banner-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--aw-color-warning-text);
  padding: 0 0.25rem;
}

/* ── Process Control Buttons ─────────────────── */
.btn-danger {
  padding: 0.25rem 0.5rem;
  border: none;
  border-radius: 0.375rem;
  background: var(--aw-color-error, #ef4444);
  color: #fff;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn-danger:hover,
.btn-danger:active {
  background: #dc2626;
}
.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-warning {
  padding: 0.25rem 0.5rem;
  border: none;
  border-radius: 0.375rem;
  background: var(--aw-color-warning, #f59e0b);
  color: #fff;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn-warning:hover,
.btn-warning:active {
  background: #d97706;
}
.btn-warning:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-success {
  padding: 0.25rem 0.5rem;
  border: none;
  border-radius: 0.375rem;
  background: var(--aw-color-success, #22c55e);
  color: #fff;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn-success:hover,
.btn-success:active {
  background: #16a34a;
}
.btn-success:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.process-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}

/* ── Demo Splash ─────────────────────────── */

.demo-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--aw-color-bg-primary);
  color: var(--aw-color-text-primary);
  overflow-y: auto;
  padding: 2rem;
}

.demo-splash-inner {
  max-width: 720px;
  width: 100%;
  text-align: center;
  animation: demoFadeIn 0.5s ease-out;
}

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

.demo-splash-title {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, var(--aw-color-accent), var(--aw-color-info, #6366f1));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.demo-splash-subtitle {
  font-size: 1.05rem;
  color: var(--aw-color-text-secondary);
  line-height: 1.7;
  margin-bottom: 2rem;
}

.demo-splash-achievements {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.demo-splash-card {
  background: var(--aw-color-bg-secondary);
  border: 1px solid var(--aw-color-border);
  border-radius: 12px;
  padding: 1.25rem 1rem;
  text-align: left;
}

.demo-splash-card-icon {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.demo-splash-card-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.demo-splash-card-role {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--aw-color-text-muted);
}

.demo-splash-card-text {
  font-size: 0.85rem;
  color: var(--aw-color-text-secondary);
  line-height: 1.5;
  margin: 0;
}

.demo-splash-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.demo-splash-btn {
  padding: 0.75rem 1.75rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: transform 0.15s, box-shadow 0.15s;
}

.demo-splash-btn:hover,
.demo-splash-btn:active {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

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

.demo-splash-btn-secondary {
  background: var(--aw-color-bg-secondary);
  color: var(--aw-color-text-primary);
  border: 1px solid var(--aw-color-border);
}

@media (max-width: 640px) {
  .demo-splash-achievements {
    grid-template-columns: 1fr;
  }
  .demo-splash-title {
    font-size: 1.75rem;
  }
}
