/* dashboards.css — reusable dashboard cards & layout */

:root{
  --safe-top-raw: env(safe-area-inset-top);
  --safe-top: max(0px, calc(var(--safe-top-raw) - 14px)); /* reduced safe top */
  --safe-bottom: env(safe-area-inset-bottom);

  --dash-card-bg:#ffffff;
  --dash-card-border:#e5e7eb;
  --dash-muted:#9aa1ad;
}

/* Dashboard header with org pill */
.dashboard-header {
  padding: 12px 16px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Org pill styling (matches categories) */
.dash-org-pill {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: #f3f4f6;
  border: 1px solid var(--dash-card-border);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
}

.dash-org-pill:hover {
  background: #e9ecef;
}

/* Grid layout for dashboard; can be re-used in other screens */
.dashboard-grid{
  padding-bottom: calc(64px + var(--safe-bottom));
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: start;
}

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

/* Card shell — reusable widget */
.dash-card{
  background:var(--dash-card-bg);
  border:1px solid var(--dash-card-border);
  border-radius:12px;
  padding:10px 10px 12px;
  box-shadow:0 1px 2px rgba(15,23,42,.04);
  display:flex;
  flex-direction:column;
  min-height:0;
}

.dash-card-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  margin-bottom:6px;
}

.dash-card-title{
  font-size:16px;
  font-weight:600;
}

.dash-card-subtitle{
  font-size:12px;
  color:var(--dash-muted);
}

.dash-card-body{
  font-size:13px;
}

/* Wider card that can stretch more horizontally */
/* Wider card that spans full row */
.dash-wide{
  grid-column: 1 / -1;
}

/* Key indicators strip — also can be copied into other screens */
/* Key indicators strip */
.dash-key{
  grid-column: 1 / -1;
}

.dash-card-body.kpi-grid{
  display:grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap:8px;
}

@media (max-width: 340px){
  .dash-card-body.kpi-grid{
    grid-template-columns: 1fr !important;
  }
}

.kpi-item{
  padding:2px;
  border-radius:10px;
  background:#f3f4f6;
}

.kpi-label{
  font-size:12px;
  color:var(--dash-muted);
  margin-bottom:4px;
}

.kpi-value{
  font-size:18px;
  font-weight:600;
}

.kpi-sub{
  margin-top:2px;
  font-size:11px;
  color:var(--dash-muted);
}

/* Compact link in card headers */
.mini-link{
  border:none;
  background:transparent;
  color:#2563eb;
  font-size:12px;
  display:inline-flex;
  align-items:center;
  gap:2px;
  cursor:pointer;
  padding:2px 4px;
}

.mini-link .material-icons{
  font-size:14px;
}

/* Simple chart box wrapper */
.chart-box{
  width:100%;
  min-height:140px;
}

/* Compact list styling used by accounts + transactions mini-panels */
.list-compact{
  list-style:none;
  margin:0;
  padding:0;
}

.list-compact li{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:6px 0;
  border-bottom:1px solid rgba(148,163,184,.3);
}

.list-compact li:last-child{
  border-bottom:none;
}

.list-compact .label{
  font-size:13px;
}

.list-compact .meta{
  font-size:11px;
  color:var(--dash-muted);
}

.list-compact .value{
  font-weight:500;
  font-size:13px;
}

/* Cashflow bar */
.cashflow-body{
  display:flex;
  flex-direction:column;
  gap:4px;
}

.cashflow-row{
  display:flex;
  justify-content:space-between;
  font-size:13px;
}

.cf-label{
  color:var(--dash-muted);
}

.cf-value{
  font-weight:600;
}

.cf-value.negative{
  color:#dc2626;
}

.cf-bar-wrap{
  margin-top:6px;
}

.cf-bar-bg{
  position:relative;
  height:10px;
  border-radius:999px;
  background:#e5e7eb;
  overflow:hidden;
  display:flex;
}

.cf-bar-in,
.cf-bar-out{
  height:100%;
}

.cf-bar-in{
  background:#22c55e;
}

.cf-bar-out{
  background:#ef4444;
}

.cf-legend{
  margin-top:4px;
  font-size:11px;
  color:var(--dash-muted);
  display:flex;
  align-items:center;
  gap:8px;
}

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

.dot-in{
  background:#22c55e;
}

.dot-out{
  background:#ef4444;
}

/* Last transactions card */
.dash-last .list-compact li{
  font-size:13px;
}

.dash-last .list-compact .amount-negative{
  color:#dc2626;
}

.dash-last .list-compact .amount-positive{
  color:#16a34a;
}

/* Responsive tweak: on very small screens allow cards to be full width */
@media (max-width:480px){
  .dash-wide,
  .dash-key{
    grid-column:1 / -1;
  }
}
/* Add to accounts.css or ensure it exists */
.hdr-org-dot {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
  border-radius: 6px;
  background: #f3f4f6;
  border: 1px solid var(--bd);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
}

.hdr-org-dot:hover {
  background: #e9ecef;
}

/* === TOOLBAR LAYOUT FOR CENTERED TITLE === */
/* Ensure toolbar uses flexbox */
header.appbar .toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  height: var(--appbar-h, 56px);
  white-space: nowrap;
  gap: 8px;
  width: 100%;
}

/* Left section (home + org) - FIXED WIDTH */
header.appbar .toolbar .left-section {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  min-width: 64px; /* Fixed width to match right section */
  justify-content: flex-start;
}

/* Center section (title) - TRULY CENTERED */
header.appbar .toolbar .center-section {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0; /* Allow shrinking */
  overflow: hidden;
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none; /* Allow clicks to pass through to buttons */
}

/* Make the title clickable */
header.appbar .toolbar .center-section h1 {
  pointer-events: auto;
}

/* Right section (actions) - FIXED WIDTH */
header.appbar .toolbar .right-section {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  min-width: 64px; /* Fixed width to match left section */
  justify-content: flex-end;
}

/* Title styling */
header.appbar .toolbar .center-section h1,
header.appbar .toolbar .center-section #title {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-sub, #374151);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  line-height: 1.3;
  padding-bottom: 1px;
  max-width: calc(100vw - 140px); /* Prevent overflow */
}

/* Alternative simpler solution without absolute positioning */
/* If you don't want to use absolute positioning, use this instead: */


header.appbar .toolbar .left-section {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  justify-content: flex-start;
  min-width: 0;
}

header.appbar .toolbar .center-section {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  min-width: 0;
}

header.appbar .toolbar .right-section {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

header.appbar .toolbar .center-section h1 {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-sub, #374151);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}



/* === TOOLBAR LAYOUT FOR CENTERED TITLE === */
/* Ensure toolbar uses flexbox */
header.appbar .toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  height: var(--appbar-h, 56px);
  white-space: nowrap;
  gap: 8px;
  width: 100%;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Left section (home + org) - FIXED WIDTH */
header.appbar .toolbar .left-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 88px; /* Fixed width for two icons */
  justify-content: flex-start;
}

/* Home button with glassy border */
header.appbar .toolbar #homeBtn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(209, 213, 219, 0.6);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

header.appbar .toolbar #homeBtn:hover {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(156, 163, 175, 0.8);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

header.appbar .toolbar #homeBtn:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Org pill with glassy border */
header.appbar .toolbar .hdr-org-dot {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(209, 213, 219, 0.6);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink, #374151);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

header.appbar .toolbar .hdr-org-dot:hover {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(156, 163, 175, 0.8);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

header.appbar .toolbar .hdr-org-dot:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Period button with glassy border */
header.appbar .toolbar #periodBtn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(209, 213, 219, 0.6);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #374151;
}

header.appbar .toolbar #periodBtn:hover {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(156, 163, 175, 0.8);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

header.appbar .toolbar #periodBtn:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Icon styling */
header.appbar .toolbar .icon {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

header.appbar .toolbar .icon .material-icons {
  font-size: 20px;
  color: #4B5563;
}

/* Center section (title) - TRULY CENTERED */
header.appbar .toolbar .center-section {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
}

/* Make the title clickable */
header.appbar .toolbar .center-section h1 {
  pointer-events: auto;
}

/* Right section (actions) - FIXED WIDTH */
header.appbar .toolbar .right-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 48px; /* Fixed width for period button */
  justify-content: flex-end;
}

/* Title styling */
header.appbar .toolbar .center-section h1,
header.appbar .toolbar .center-section #title {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-sub, #374151);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  line-height: 1.3;
  padding-bottom: 1px;
  max-width: calc(100vw - 160px);
}

/* Ensure the toolbar has a subtle bottom border */
header.appbar {
  border-bottom: 1px solid rgba(229, 231, 235, 0.6);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Native month picker input (kept in DOM so mobile browsers can open it) */
/* Native month picker input (kept in DOM so mobile browsers can open it) */
.period-native-input{
  position:absolute !important;
  opacity:0 !important;
  width:1px !important;
  height:1px !important;
  pointer-events:none !important;
  border:0 !important;
  padding:0 !important;
  margin:0 !important;
}
/* --- DASHBOARD: KEY INDICATORS GRID (restore 2-per-row) --- */
.dash-card-body:has(.kpi) {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* Mobile: stack KPIs */
@media (max-width: 520px) {
  .dash-card-body:has(.kpi) {
    grid-template-columns: 1fr;
  }
}
