/* =========================================================
   Daily Manager — Frontend CSS (Mobile First)
   ========================================================= */

/* ── Design Tokens ──────────────────────────────────────── */
:root {
  --dm-primary:    #6366f1;
  --dm-primary-dk: #4f46e5;
  --dm-success:    #22c55e;
  --dm-danger:     #ef4444;
  --dm-warning:    #f59e0b;
  --dm-bg:         #f8fafc;
  --dm-surface:    #ffffff;
  --dm-border:     #e2e8f0;
  --dm-text:       #1e293b;
  --dm-muted:      #64748b;
  --dm-radius:     12px;
  --dm-shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --dm-font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Reset / Base ───────────────────────────────────────── */
.dm-wrap { all: initial; }
.dm-wrap *, .dm-wrap *::before, .dm-wrap *::after {
  box-sizing: border-box;
  font-family: var(--dm-font);
}

/* ── Layout ─────────────────────────────────────────────── */
.dm-wrap {
  display: block;
  background: var(--dm-bg);
  color: var(--dm-text);
  min-height: 100vh;
  padding: 0 0 80px;
}

.dm-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Top bar ────────────────────────────────────────────── */
.dm-topbar {
  background: var(--dm-primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}
.dm-topbar h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -.3px;
}
.dm-topbar-date { font-size: 13px; opacity: .85; }

/* ── Nav tabs ────────────────────────────────────────────── */
.dm-tabs {
  display: flex;
  background: var(--dm-surface);
  border-bottom: 2px solid var(--dm-border);
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: 57px;
  z-index: 99;
}
.dm-tabs::-webkit-scrollbar { display: none; }
.dm-tab {
  flex: 1;
  min-width: 80px;
  padding: 12px 8px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--dm-muted);
  text-align: center;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color .2s, border-color .2s;
}
.dm-tab.active {
  color: var(--dm-primary);
  border-bottom-color: var(--dm-primary);
}

/* ── Panels ─────────────────────────────────────────────── */
.dm-panel { display: none; padding-top: 16px; }
.dm-panel.active { display: block; }

/* ── Cards ──────────────────────────────────────────────── */
.dm-card {
  background: var(--dm-surface);
  border-radius: var(--dm-radius);
  box-shadow: var(--dm-shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.dm-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--dm-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 0 0 12px;
}

/* ── Stats grid ─────────────────────────────────────────── */
.dm-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.dm-stat {
  background: var(--dm-surface);
  border-radius: var(--dm-radius);
  padding: 14px;
  box-shadow: var(--dm-shadow);
  text-align: center;
}
.dm-stat-label { font-size: 11px; color: var(--dm-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.dm-stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.dm-stat-value.income   { color: var(--dm-success); }
.dm-stat-value.expense  { color: var(--dm-danger);  }
.dm-stat-value.balance  { color: var(--dm-primary); }
.dm-stat-value.cost     { color: var(--dm-warning); }

/* ── Activity list ──────────────────────────────────────── */
.dm-activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--dm-border);
}
.dm-activity-item:last-child { border-bottom: none; }
.dm-activity-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--dm-border);
  flex-shrink: 0;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.dm-activity-check.completed { background: var(--dm-success); border-color: var(--dm-success); }
.dm-activity-check.completed::after { content: '✓'; color: #fff; font-size: 12px; font-weight: 700; }
.dm-activity-check.in_progress { border-color: var(--dm-warning); }
.dm-activity-body { flex: 1; min-width: 0; }
.dm-activity-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dm-activity-title.completed { text-decoration: line-through; color: var(--dm-muted); }
.dm-activity-meta { font-size: 12px; color: var(--dm-muted); display: flex; gap: 8px; flex-wrap: wrap; }
.dm-activity-actions { display: flex; gap: 6px; }
.dm-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.dm-badge-low      { background: #f0fdf4; color: #15803d; }
.dm-badge-medium   { background: #fffbeb; color: #92400e; }
.dm-badge-high     { background: #fef2f2; color: #991b1b; }
.dm-badge-pending     { background: #f1f5f9; color: #475569; }
.dm-badge-in_progress { background: #fffbeb; color: #92400e; }
.dm-badge-completed   { background: #f0fdf4; color: #15803d; }

/* ── Finance list ───────────────────────────────────────── */
.dm-finance-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--dm-border);
}
.dm-finance-item:last-child { border-bottom: none; }
.dm-finance-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.dm-finance-icon.income     { background: #f0fdf4; }
.dm-finance-icon.expense    { background: #fef2f2; }
.dm-finance-icon.cost       { background: #fffbeb; }
.dm-finance-icon.investment { background: #f5f3ff; }
.dm-finance-body { flex: 1; min-width: 0; }
.dm-finance-desc { font-size: 14px; font-weight: 600; margin: 0 0 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-finance-cat  { font-size: 12px; color: var(--dm-muted); }
.dm-finance-amount { font-weight: 700; font-size: 15px; white-space: nowrap; }
.dm-finance-amount.income     { color: var(--dm-success); }
.dm-finance-amount.expense,
.dm-finance-amount.cost       { color: var(--dm-danger);  }
.dm-finance-amount.investment { color: var(--dm-primary); }

/* ── Forms ──────────────────────────────────────────────── */
.dm-form { display: grid; gap: 12px; }
.dm-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--dm-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 5px;
}
.dm-field input,
.dm-field select,
.dm-field textarea {
  width: 100%;
  border: 1.5px solid var(--dm-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--dm-text);
  background: var(--dm-surface);
  transition: border-color .2s;
  appearance: none;
  -webkit-appearance: none;
}
.dm-field input:focus,
.dm-field select:focus,
.dm-field textarea:focus {
  outline: none;
  border-color: var(--dm-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.dm-field textarea { resize: vertical; min-height: 80px; }

.dm-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Buttons ────────────────────────────────────────────── */
.dm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
  white-space: nowrap;
  text-decoration: none;
}
.dm-btn:active { transform: scale(.97); }
.dm-btn-primary  { background: var(--dm-primary); color: #fff; }
.dm-btn-primary:hover  { background: var(--dm-primary-dk); }
.dm-btn-success  { background: var(--dm-success); color: #fff; }
.dm-btn-danger   { background: var(--dm-danger);  color: #fff; }
.dm-btn-ghost    { background: transparent; color: var(--dm-muted); border: 1.5px solid var(--dm-border); }
.dm-btn-ghost:hover { background: var(--dm-bg); }
.dm-btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 6px; }
.dm-btn-icon { width: 32px; height: 32px; padding: 0; border-radius: 8px; }
.dm-btn-full { width: 100%; }

/* ── Modal ──────────────────────────────────────────────── */
.dm-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.dm-modal-backdrop.open { opacity: 1; pointer-events: auto; }
.dm-modal {
  background: var(--dm-surface);
  border-radius: var(--dm-radius) var(--dm-radius) 0 0;
  padding: 20px 16px 32px;
  width: 100%;
  max-width: 520px;
  transform: translateY(40px);
  transition: transform .25s;
}
.dm-modal-backdrop.open .dm-modal { transform: translateY(0); }
.dm-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.dm-modal-title { font-size: 16px; font-weight: 700; margin: 0; }
.dm-modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--dm-muted); line-height: 1; padding: 0; }

/* ── Date filter bar ────────────────────────────────────── */
.dm-filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.dm-filter-bar input[type="date"] {
  border: 1.5px solid var(--dm-border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--dm-text);
  background: var(--dm-surface);
  flex: 1;
  min-width: 130px;
}

/* ── FAB ────────────────────────────────────────────────── */
.dm-fab {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--dm-primary);
  color: #fff;
  font-size: 26px;
  border: none;
  box-shadow: 0 4px 16px rgba(99,102,241,.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: transform .2s, background .2s;
}
.dm-fab:hover { background: var(--dm-primary-dk); transform: scale(1.08); }

/* ── Empty state ────────────────────────────────────────── */
.dm-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--dm-muted);
}
.dm-empty-icon { font-size: 36px; margin-bottom: 8px; }
.dm-empty-msg  { font-size: 14px; }

/* ── Toast ──────────────────────────────────────────────── */
.dm-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: opacity .3s, transform .3s;
  pointer-events: none;
  white-space: nowrap;
}
.dm-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.dm-toast.success { background: var(--dm-success); }
.dm-toast.error   { background: var(--dm-danger);  }

/* ── Chart wrapper ──────────────────────────────────────── */
.dm-chart-wrap { position: relative; height: 200px; margin-top: 8px; }

/* ── Loading ────────────────────────────────────────────── */
.dm-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--dm-muted);
  font-size: 14px;
  gap: 8px;
}
.dm-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--dm-border);
  border-top-color: var(--dm-primary);
  border-radius: 50%;
  animation: dm-spin .7s linear infinite;
}
@keyframes dm-spin { to { transform: rotate(360deg); } }

/* ── Notice ─────────────────────────────────────────────── */
.dm-notice {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
  color: #92400e;
}

/* ── Desktop breakpoint ─────────────────────────────────── */
@media (min-width: 640px) {
  .dm-stats { grid-template-columns: repeat(4, 1fr); }
  .dm-modal { align-self: center; border-radius: var(--dm-radius); }
  .dm-modal-backdrop { align-items: center; }
  .dm-chart-wrap { height: 240px; }
  .dm-container { padding: 0 24px; }
}
