:root {
  --bg: #f7fafc;
  --card-bg: #ffffff;
  --text: #1a202c;
  --muted: #718096;
  --border: #e2e8f0;
  --primary: #2b6cb0;
  --primary-dark: #2c5282;
  --green: #38a169;
  --green-bg: #f0fff4;
  --red: #e53e3e;
  --red-bg: #fff5f5;
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

/* Never let an author rule (e.g. #main-nav { display: flex }) accidentally
   override the native [hidden] attribute's display:none. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { font-weight: 700; }
h2 { font-size: 18px; margin: 0 0 14px; color: var(--text); }
h3 { font-size: 15px; margin: 0 0 14px; color: var(--text); }
p { margin: 6px 0; }

/* Form controls: reset to a single consistent look everywhere (inputs/selects
   otherwise render in the browser's default UI font/size, not the page's). */
input, select, button {
  font-family: inherit;
  font-size: 14px;
}
input, select {
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.15);
}

.app-shell {
  display: flex;
  flex-direction: row-reverse; /* sidebar on the left regardless of RTL text direction */
  align-items: stretch;
  min-height: 100vh;
}

#sidebar {
  flex: 0 0 240px;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border-inline-start: 1px solid var(--border);
  padding: 20px 14px;
}

.sidebar-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  padding: 0 10px;
  margin-bottom: 28px;
}

#main-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

#main-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: auto;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  text-align: right;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-icon { font-size: 15px; }

#main-nav button:hover { background: var(--bg); color: var(--text); }

#main-nav button.active {
  background: #ebf4ff;
  color: var(--primary-dark);
  font-weight: 700;
}

#main-nav button#sign-out-btn { margin-top: auto; color: var(--red); }
#main-nav button#sign-out-btn:hover { background: var(--red-bg); }

#app-root { flex: 1; min-width: 0; padding: 28px 32px; max-width: 1100px; }

@media (max-width: 700px) {
  .app-shell { flex-direction: column; }
  #sidebar {
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    border-inline-end: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .sidebar-brand { margin-bottom: 0; margin-inline-end: 16px; white-space: nowrap; }
  #main-nav { flex-direction: row; }
  #main-nav button#sign-out-btn { margin-top: 0; margin-inline-start: auto; }
  #app-root { padding: 20px; }
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  padding: 20px 24px;
  margin-bottom: 20px;
  overflow-x: auto;
}

.track-green { color: var(--green); font-weight: 600; }
.track-red { color: var(--red); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

@media (max-width: 700px) {
  .grid-2 { grid-template-columns: 1fr; }
  #main-nav { flex-wrap: wrap; }
}

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--bg);
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}
td { font-weight: 400; color: var(--text); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; }
tbody tr:hover { background: var(--bg); }

table button {
  height: auto;
  padding: 5px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  cursor: pointer;
  margin-inline-start: 6px;
  white-space: nowrap;
}
table button:hover { background: var(--bg); }
.delete-btn { color: var(--red); border-color: #fed7d7; }
.delete-btn:hover { background: var(--red-bg); }

/* Shared layout for every "add new item" form (fixed rules / deposits / loans /
   goals / capital adjustment / what-if) — one rule set, reused everywhere. */
.form-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  flex: 1 1 150px;
  min-width: 130px;
}
.form-grid button[type="submit"] { flex: 0 0 auto; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.dropzone.dragover { border-color: var(--primary); color: var(--primary); background: var(--green-bg); }

button.primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  height: 38px;
  padding: 0 18px;
  cursor: pointer;
  transition: background 0.15s ease;
}
button.primary:hover { background: var(--primary-dark); }
