/* ==========================================================================
   AIVA Dashboard — page-level styles.
   Tokens & base components live in design-system.css (loaded first).
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. LAYOUT — moved to design-system.css (sidebar shell). Legacy aliases kept
   for backwards compatibility with one-off pages.
   -------------------------------------------------------------------------- */
.topbar-right { display: flex; gap: var(--s-2); align-items: center; margin-left: auto; }

/* legacy layout class (no longer used by base.html but referenced by some
   admin templates) */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  max-width: 1600px;
  margin: 0 auto;
}

/* full-screen chat route */
.chat-full {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  height: calc(100vh - var(--topbar-h) - 100px);
  min-height: 500px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chat-full > * { flex: 1; min-height: 0; }
.chat-full .chat-widget { height: 100%; }

/* Page hero (today/home) */
.page-hero {
  margin-bottom: var(--s-5);
}
.page-hero h1 { margin: 0; }
.page-hero .sub { color: var(--color-muted); font-size: var(--fs-sm); margin-top: 4px; }

/* --------------------------------------------------------------------------
   2. CARDS GRID (KPI etc.)
   -------------------------------------------------------------------------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}
.kpi-cards .kpi { min-height: 110px; }

/* --------------------------------------------------------------------------
   3. QUICK ACTIONS
   -------------------------------------------------------------------------- */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: var(--s-5);
}
.quick-actions .btn { padding: 9px 16px; }

/* --------------------------------------------------------------------------
   4. BRIEFING BANNER
   -------------------------------------------------------------------------- */
.briefing-banner {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-5);
  position: relative;
  overflow: hidden;
}
.briefing-banner::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--grad-accent);
}
.briefing-banner summary {
  cursor: pointer;
  color: var(--color-accent-hi);
  font-weight: 600;
  list-style: none;
  display: flex; align-items: center; gap: var(--s-2);
}
.briefing-banner summary::-webkit-details-marker { display: none; }
.briefing-banner summary::after {
  content: '⌄';
  margin-left: auto;
  color: var(--color-muted);
  transition: transform var(--t-fast);
  font-size: var(--fs-md);
}
.briefing-banner[open] summary::after { transform: rotate(180deg); }
.briefing-text {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--r-sm);
  padding: var(--s-3);
  margin-top: var(--s-3);
  white-space: pre-wrap;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  color: var(--color-text-soft);
}

/* --------------------------------------------------------------------------
   5. ACTIVITY FEED
   -------------------------------------------------------------------------- */
.activity-feed { list-style: none; padding: 0; margin: 0; }
.activity-feed li {
  padding: var(--s-2) 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  display: grid;
  grid-template-columns: 32px 140px 1fr auto;
  gap: var(--s-3);
  align-items: center;
  font-size: var(--fs-base);
}
.activity-feed li:last-child { border-bottom: none; }
.activity-icon {
  width: 28px; height: 28px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--r-sm);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--color-accent);
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
}
.activity-when { font-size: var(--fs-xs); color: var(--color-muted); }
.activity-action { color: var(--color-text-soft); }
.activity-target { color: var(--color-muted); font-family: var(--font-mono); font-size: var(--fs-sm); }

/* --------------------------------------------------------------------------
   6. DETAIL PANEL (slide-in)
   -------------------------------------------------------------------------- */
.detail-panel {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: 520px; max-width: 90vw;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  padding: 0;
  overflow: hidden;
  box-shadow: var(--sh-lg);
  z-index: 60;
  display: flex; flex-direction: column;
  animation: fadeIn var(--t-base);
}
.detail-panel-head {
  position: sticky; top: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--s-4) var(--s-5);
  display: flex; justify-content: space-between; align-items: center;
}
.detail-panel-head h2 { margin: 0; text-transform: none; font-size: var(--fs-lg); color: var(--color-text); letter-spacing: -0.01em; }
.detail-panel-body { flex: 1; overflow-y: auto; padding: var(--s-5); }
.detail-panel .close {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--r-sm);
  width: 30px; height: 30px;
  color: var(--color-muted);
  font-size: 16px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.detail-panel .close:hover { color: var(--color-text); border-color: var(--color-border-hi); }

.detail-row { padding: var(--s-2) 0; border-bottom: 1px solid rgba(255,255,255,0.04); display: flex; gap: var(--s-3); }
.detail-row:last-child { border-bottom: none; }
.detail-row .k { color: var(--color-muted); width: 130px; flex-shrink: 0; font-size: var(--fs-sm); }
.detail-row .v { color: var(--color-text); }

.detail-actions { display: flex; gap: var(--s-2); margin: var(--s-3) 0; flex-wrap: wrap; }
.quick-note {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--r-sm);
  padding: var(--s-3);
  margin-bottom: var(--s-3);
}

/* Timeline (interactions) */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  padding: var(--s-3) 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: var(--s-3);
}
.timeline li:last-child { border-bottom: none; }
.timeline .when { color: var(--color-muted); font-size: var(--fs-xs); font-family: var(--font-mono); }
.timeline .what { color: var(--color-text-soft); font-size: var(--fs-base); line-height: 1.5; }

/* --------------------------------------------------------------------------
   7. FILTER BAR
   -------------------------------------------------------------------------- */
.filter-bar {
  display: flex; gap: var(--s-2); flex-wrap: wrap;
  margin-bottom: var(--s-3);
  align-items: center;
}
.filter-bar input, .filter-bar select {
  width: auto;
  padding: 6px 10px;
  font-size: var(--fs-sm);
}
.view-toggle { display: inline-flex; gap: 2px; margin-left: auto; }

/* --------------------------------------------------------------------------
   8. PROPERTIES GRID VIEW
   -------------------------------------------------------------------------- */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--s-3);
}
.grid-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  cursor: pointer;
  transition: transform var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
}
.grid-card:hover {
  transform: translateY(-1px);
  border-color: var(--color-border-hi);
  box-shadow: var(--sh-md);
}
.grid-card-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: var(--s-2);
}
.grid-id { color: var(--color-faint); font-family: var(--font-mono); font-size: var(--fs-xs); }
.grid-card-title { font-weight: 600; font-size: var(--fs-md); margin-bottom: var(--s-1); color: var(--color-text); }
.grid-card-meta { font-size: var(--fs-sm); color: var(--color-muted); }
.grid-card-foot { font-size: var(--fs-xs); color: var(--color-faint); margin-top: var(--s-3); padding-top: var(--s-2); border-top: 1px solid var(--color-border); }

/* --------------------------------------------------------------------------
   9. CHAT PANEL (glassmorphism)
   -------------------------------------------------------------------------- */
.chat-panel {
  position: sticky; top: 60px; right: 0;
  height: calc(100vh - 60px);
  background: rgba(17, 21, 29, 0.7);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-left: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.chat-loading { padding: var(--s-4); color: var(--color-muted); font-size: var(--fs-sm); }
.chat-widget { display: flex; flex-direction: column; height: 100%; }
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--color-border);
  background: rgba(0,0,0,0.2);
  position: sticky; top: 0; z-index: 1;
}
.chat-title {
  display: flex; align-items: center; gap: var(--s-2);
  font-weight: 600; font-size: var(--fs-base);
}
.chat-title .brand-logo { width: 22px; height: 22px; font-size: 12px; }
.chat-actions { display: flex; gap: 4px; }
.chat-iconbtn {
  background: transparent; color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--r-sm);
  width: 30px; height: 30px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all var(--t-fast);
}
.chat-iconbtn:hover { background: var(--color-surface-2); color: var(--color-text); }

.chat-messages {
  flex: 1; overflow-y: auto;
  padding: var(--s-3);
  display: flex; flex-direction: column;
  gap: var(--s-3);
}
.chat-empty { padding: var(--s-3); font-size: var(--fs-sm); }
.chat-msg { display: flex; max-width: 100%; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.assistant { justify-content: flex-start; }
.chat-bubble {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  line-height: 1.5;
  word-wrap: break-word;
  animation: fadeIn var(--t-base);
}
.chat-msg.user .chat-bubble {
  background: var(--grad-accent);
  color: #0a0c11;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}
.chat-msg.assistant .chat-bubble {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}
.chat-bubble p { margin: 0 0 var(--s-2); }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble code {
  background: rgba(0,0,0,.3); padding: 1px 5px; border-radius: var(--r-xs);
  font-family: var(--font-mono); font-size: 0.92em;
}
.chat-bubble pre {
  background: rgba(0,0,0,.3); padding: var(--s-2); border-radius: var(--r-sm); overflow-x: auto;
}
.chat-bubble ul, .chat-bubble ol { padding-left: 18px; margin: 4px 0; }
.chat-meta { font-size: 10px; margin-top: 4px; opacity: 0.6; }
.chat-options { margin-top: var(--s-2); display: flex; flex-wrap: wrap; gap: 6px; }
.chat-options .chat-opt { font-size: var(--fs-xs); padding: 4px 10px; }

/* Typing dots */
.typing-dots { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--color-muted); animation: typing-dot 1.4s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

.chat-form {
  border-top: 1px solid var(--color-border);
  padding: var(--s-3);
  background: rgba(0,0,0,0.2);
  display: flex; flex-direction: column; gap: var(--s-2);
}
.chat-form textarea {
  resize: none;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--r-sm);
  padding: var(--s-2);
  font-size: var(--fs-base);
  font-family: inherit;
  min-height: 60px;
}
.chat-form-row { display: flex; justify-content: space-between; align-items: center; }
.chat-form .chat-loading { padding: 0; font-size: var(--fs-xs); }

/* --------------------------------------------------------------------------
   10. MODAL
   -------------------------------------------------------------------------- */
.modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(6px);
  z-index: 100;
  align-items: flex-start; justify-content: center;
  padding-top: 80px;
  animation: fadeIn var(--t-fast);
}
.modal.open { display: flex; }
.modal-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-hi);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  padding: var(--s-6);
  min-width: 400px; max-width: 90vw;
  position: relative;
}
.modal-card .close {
  position: absolute; top: 12px; right: 16px;
  background: transparent; border: none;
  cursor: pointer;
  color: var(--color-muted);
  font-size: 22px;
  line-height: 1;
}
.modal-card .close:hover { color: var(--color-text); }

/* --------------------------------------------------------------------------
   11. CALENDAR
   -------------------------------------------------------------------------- */
.day-group { margin-bottom: var(--s-5); }
.day-group .day-head {
  font-weight: 600;
  font-size: var(--fs-md);
  color: var(--color-accent-hi);
  margin-bottom: var(--s-2);
  display: flex; align-items: center; gap: var(--s-2);
}
.day-group .day-count { color: var(--color-muted); font-weight: 400; font-size: var(--fs-xs); }
.day-group .conflict { color: var(--color-hot); font-size: var(--fs-xs); margin-left: var(--s-2); }

.week-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--s-2);
  margin-top: var(--s-3);
}
.week-day {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  padding: var(--s-3);
  min-height: 220px;
  transition: border-color var(--t-fast);
}
.week-day:hover { border-color: var(--color-border-hi); }
.week-day.today { border-color: var(--color-accent); background: var(--color-accent-soft); }
.week-day-head { font-weight: 600; margin-bottom: var(--s-2); font-size: var(--fs-sm); }
.week-item {
  background: var(--color-surface-2);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--r-xs);
  padding: 6px 8px;
  margin-bottom: 4px;
  font-size: var(--fs-xs);
  transition: background var(--t-fast);
}
.week-item:hover { background: var(--color-surface-hi); }
.week-item.conflict { border-left-color: var(--color-hot); }
.week-item-time { font-family: var(--font-mono); color: var(--color-accent-hi); }
.conflict-tag { color: var(--color-hot); font-size: 10px; font-weight: 600; }
.row-conflict { background: rgba(248, 113, 113, 0.06); }

/* --------------------------------------------------------------------------
   12. LOGS
   -------------------------------------------------------------------------- */
pre.log {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--r-sm);
  padding: var(--s-3);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  white-space: pre-wrap;
  word-break: break-word;
}
.log-entry {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  padding: var(--s-3);
  margin-bottom: var(--s-2);
  transition: border-color var(--t-fast);
}
.log-entry:hover { border-color: var(--color-border-hi); }
.log-entry .ts { color: var(--color-muted); font-size: var(--fs-xs); font-family: var(--font-mono); }

/* --------------------------------------------------------------------------
   13. ANALYTICS
   -------------------------------------------------------------------------- */
.charts-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: var(--s-3);
}
.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  transition: border-color var(--t-fast);
}
.chart-card:hover { border-color: var(--color-border-hi); }
.chart-title { font-weight: 600; font-size: var(--fs-md); margin-bottom: var(--s-1); }
.chart-subtitle { color: var(--color-muted); font-size: var(--fs-xs); margin-bottom: var(--s-3); }
.chart-card canvas { max-height: 280px; }
.stat-big {
  font-size: 42px; font-weight: 700; letter-spacing: -0.02em;
  background: var(--grad-accent);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: var(--s-2) 0;
  line-height: 1;
}
.stat-unit { font-size: var(--fs-md); font-weight: 400; color: var(--color-muted); margin-left: 6px; }
.heatmap { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.heatmap th, .heatmap td { padding: 8px 10px; border: 1px solid var(--color-border); text-align: center; border-radius: 4px; }
.heatmap th { background: var(--color-surface-2); color: var(--color-muted); font-weight: 600; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; }
.heatmap tbody th { text-align: left; font-weight: 500; }

/* --------------------------------------------------------------------------
   14. LOGIN
   -------------------------------------------------------------------------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at top, rgba(122,169,255,0.07) 0%, transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(167,139,250,0.06) 0%, transparent 60%),
    var(--color-bg);
  padding: var(--s-5);
}
.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  padding: var(--s-7);
  min-width: 380px;
  max-width: 440px;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--grad-accent);
}
.login-brand {
  display: flex; align-items: center; gap: var(--s-3);
  margin-bottom: var(--s-2);
}
.login-brand .brand-logo { width: 36px; height: 36px; font-size: 18px; }
.login-brand .brand-name { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.02em; }
.login-tagline { color: var(--color-muted); font-size: var(--fs-sm); margin-bottom: var(--s-6); }
.login-card h1 { font-size: var(--fs-lg); margin-bottom: var(--s-5); font-weight: 600; }
.login-help {
  margin-top: var(--s-5);
  padding-top: var(--s-4);
  border-top: 1px solid var(--color-border);
  font-size: var(--fs-sm);
  color: var(--color-muted);
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   15. EXPORT BAR
   -------------------------------------------------------------------------- */
.export-bar { display: flex; justify-content: flex-end; margin-bottom: var(--s-3); gap: var(--s-2); }

/* --------------------------------------------------------------------------
   16. ONLINE DOT
   -------------------------------------------------------------------------- */
.online-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--color-muted);
  margin-right: 6px;
  vertical-align: 0;
}
.online-dot.on {
  background: var(--color-ok);
  box-shadow: 0 0 0 3px rgba(74,222,128,.18);
}

/* --------------------------------------------------------------------------
   17. INLINE TEMPERATURE DROPDOWN
   -------------------------------------------------------------------------- */
.temp-inline {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--r-xs);
  padding: 2px 6px;
  font-size: var(--fs-xs);
  width: auto;
}

/* --------------------------------------------------------------------------
   18. RESPONSIVE
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
  .chat-panel {
    position: fixed;
    inset: 0;
    height: 100vh;
    z-index: 90;
    transform: translateX(100%);
    transition: transform var(--t-base);
    border-left: none;
  }
  body.chat-open .chat-panel { transform: translateX(0); }
  .btn-chat-toggle { display: inline-flex; }
}

@media (max-width: 768px) {
  .nav {
    display: none;
    position: absolute;
    top: 56px; left: 0; right: 0;
    background: var(--color-surface);
    flex-direction: column;
    padding: var(--s-3);
    border-bottom: 1px solid var(--color-border);
  }
  body.nav-open .nav { display: flex; }
  .hamburger { display: inline-flex; }
  .topbar { gap: var(--s-2); }
  .activity-feed li { grid-template-columns: 28px 1fr; }
  .activity-when, .activity-target { display: none; }
  .week-grid { grid-template-columns: 1fr; }
  .detail-panel { width: 100vw; }
  .charts-grid { grid-template-columns: 1fr; }
  .main { padding: var(--s-4); }
  table { font-size: var(--fs-sm); }
  th, td { padding: 7px 8px; }
  .login-card { min-width: auto; padding: var(--s-5); }
}
