* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --accent: #15803d;
  --accent2: #86efac;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --yellow: #f59e0b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #2e3347;
  --radius: 12px;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(circle at top, rgba(21, 128, 61, 0.22), transparent 30%),
    linear-gradient(180deg, #11141d 0%, var(--bg) 45%, #0a0d14 100%);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  direction: rtl;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 100% 28px;
  opacity: 0.35;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: rgba(26, 29, 39, 0.92);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  gap: 8px;
  position: fixed;
  right: 0;
  top: 0;
  height: 100vh;
  backdrop-filter: blur(14px);
  z-index: 10;
}

.logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent2);
  padding: 8px 12px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.nav-btn {
  width: 100%;
  text-align: right;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; }

/* Content */
.content {
  margin-right: 220px;
  padding: 32px;
  flex: 1;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.page { display: none; }
.page.active { display: block; }

.status-strip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(21, 128, 61, 0.18);
  color: var(--accent2);
  border: 1px solid rgba(134, 239, 172, 0.25);
  font-size: 0.85rem;
}

.status-strip.offline {
  background: rgba(245, 158, 11, 0.14);
  color: #fcd34d;
  border-color: rgba(245, 158, 11, 0.3);
}

h1 {
  font-size: 1.8rem;
  margin-bottom: 24px;
  color: var(--text);
}

h3 { color: var(--text); margin-bottom: 16px; }

/* Cards */
.cards-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 4px;
  height: 100%;
}

.card.green::before { background: var(--green); }
.card.red::before { background: var(--red); }
.card.blue::before { background: var(--blue); }

.card-label { font-size: 0.85rem; color: var(--text-muted); }
.card-value { font-size: 2rem; font-weight: 700; }
.card.green .card-value { color: var(--green); }
.card.red .card-value { color: var(--red); }
.card.blue .card-value { color: var(--blue); }
.card-currency { font-size: 0.8rem; color: var(--text-muted); }

/* Dashboard bottom */
.dash-bottom {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

.chart-box, .upcoming-events {
  background: rgba(26, 29, 39, 0.88);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.section-head span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.chart-shell {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
  min-height: 280px;
  align-items: end;
}

.chart-day {
  display: grid;
  gap: 10px;
  justify-items: center;
}

.chart-columns {
  width: 100%;
  min-height: 180px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  align-items: end;
  gap: 6px;
  padding: 12px 8px 8px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(34, 38, 58, 0.9));
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.chart-column {
  display: flex;
  align-items: end;
  height: 150px;
}

.chart-bar {
  width: 100%;
  min-height: 6px;
  border-radius: 999px 999px 6px 6px;
  display: block;
}

.chart-bar.income {
  background: linear-gradient(180deg, #4ade80, #15803d);
}

.chart-bar.expense {
  background: linear-gradient(180deg, #fb7185, #b91c1c);
}

.chart-values {
  display: flex;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.chart-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.upcoming-events ul { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.upcoming-events li {
  background: var(--surface2);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
}
.upcoming-events .ev-date { font-size: 0.75rem; color: var(--accent2); display: block; margin-top: 2px; }
.empty-msg { color: var(--text-muted); text-align: center; font-size: 0.9rem; }

/* Finance */
.finance-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
}

.form-card {
  background: rgba(26, 29, 39, 0.88);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
  height: fit-content;
  backdrop-filter: blur(12px);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-group label { font-size: 0.85rem; color: var(--text-muted); }

.form-group input,
.form-group select,
.form-group textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}

.form-group textarea { resize: vertical; min-height: 80px; }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 1rem;
  cursor: pointer;
  transition: opacity 0.2s;
  font-family: inherit;
}

.btn-primary:hover { opacity: 0.85; }

/* Transactions */
.transactions-list {
  background: rgba(26, 29, 39, 0.88);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.filter-row { margin-bottom: 16px; }
.filter-row select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
}

#tx-list { list-style: none; display: flex; flex-direction: column; gap: 10px; max-height: 500px; overflow-y: auto; }

.list-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
}

.tx-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface2);
  border-radius: 10px;
  padding: 14px 16px;
  border-right: 3px solid transparent;
}

.tx-item.income { border-right-color: var(--green); }
.tx-item.expense { border-right-color: var(--red); }

.tx-info { flex: 1; }
.tx-desc { font-weight: 600; font-size: 0.95rem; }
.tx-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

.tx-amount { font-weight: 700; font-size: 1rem; }
.tx-item.income .tx-amount { color: var(--green); }
.tx-item.expense .tx-amount { color: var(--red); }

.tx-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
  margin-right: 8px;
}

.tx-delete:hover { background: var(--red); color: #fff; }

/* Calendar */
.calendar-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
}

.cal-box {
  background: rgba(26, 29, 39, 0.88);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.cal-header span { font-size: 1.2rem; font-weight: 600; }

.cal-header button {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.cal-header button:hover { background: var(--accent); }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

.cal-weekdays span {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 8px 0;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  flex-direction: column;
  gap: 2px;
  border: none;
  background: transparent;
  color: inherit;
}

.cal-day:hover { background: var(--surface2); }
.cal-day.other-month { color: var(--border); cursor: default; }
.cal-day.today { background: var(--accent); color: #fff; font-weight: 700; }
.cal-day.selected { outline: 2px solid var(--accent2); }
.cal-day.has-event::after {
  content: '';
  width: 5px;
  height: 5px;
  background: var(--accent2);
  border-radius: 50%;
  position: absolute;
  bottom: 4px;
}

.cal-day.today.has-event::after { background: #fff; }

.event-panel {
  background: rgba(26, 29, 39, 0.88);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
  height: fit-content;
  backdrop-filter: blur(12px);
}

#event-list { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

.ev-item {
  background: var(--surface2);
  border-radius: 8px;
  padding: 12px;
  border-right: 3px solid var(--accent2);
}

.ev-item-title { font-weight: 600; font-size: 0.9rem; }
.ev-item-time { font-size: 0.78rem; color: var(--accent2); margin-top: 2px; }
.ev-item-note { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

.ev-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  float: left;
  transition: color 0.2s;
}
.ev-delete:hover { color: var(--red); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@media (max-width: 900px) {
  body {
    display: block;
    padding-bottom: 84px;
  }

  .sidebar {
    inset: auto 0 0 0;
    width: 100%;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .sidebar nav {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .logo {
    font-size: 1rem;
    padding: 0;
    margin: 0;
    border-bottom: none;
    white-space: nowrap;
  }

  .nav-btn {
    padding: 10px 8px;
    text-align: center;
    font-size: 0.82rem;
  }

  .content {
    margin-right: 0;
    padding: 20px 16px 110px;
  }

  .cards-row,
  .dash-bottom,
  .finance-layout,
  .calendar-layout {
    grid-template-columns: 1fr;
  }

  .chart-shell {
    grid-template-columns: repeat(7, minmax(52px, 1fr));
    overflow-x: auto;
    padding-bottom: 8px;
  }
}

@media (max-width: 640px) {
  .logo {
    display: none;
  }

  .cards-row {
    grid-template-columns: 1fr;
  }

  .section-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .chart-columns {
    min-height: 150px;
  }
}
