* { box-sizing: border-box; }

:root {
  --navy: #0d1b2e;
  --navy-2: #16273f;
  --navy-3: #1e3350;
  --border: #2a4266;
  --blue: #1a4d9e;
  --blue-light: #2f6fd6;
  --orange: #e8792d;
  --text: #eef2f7;
  --text-light: #9fb1c9;
  --success: #2fbf71;
  --danger: #e0524d;
}

html, body {
  width: 100%;
  min-height: 100%;
  background: var(--navy);
  color: var(--text);
}

button, input, textarea, select {
  font-family: inherit;
}

/* ---------- PIN screen ---------- */

.pin-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.pin-card {
  background: var(--navy-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pin-logo-img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 16px;
  margin: 0 auto 8px;
}

.pin-card h1 {
  font-size: 20px;
  margin: 0;
}

.pin-card .sub {
  color: var(--text-light);
  margin: 0 0 8px;
  font-size: 14px;
}

.pin-card input {
  background: var(--navy);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 14px;
  font-size: 22px;
  letter-spacing: 6px;
  text-align: center;
}

.pin-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
  margin: 0;
}

/* ---------- Header ---------- */

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--navy-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.header-logo {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 8px;
}

header h1 {
  font-size: 18px;
  margin: 0;
}

.tagline {
  color: var(--text-light);
  font-size: 13px;
  flex: 1;
}

.add-btn {
  margin-left: auto;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.secondary-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.secondary-btn:hover {
  border-color: var(--blue-light);
  color: var(--blue-light);
}

/* ---------- Layout: sidebar + main ---------- */

main {
  padding: 0;
}

.app-body {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - 65px);
}

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--navy-2);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 65px;
  height: calc(100vh - 65px);
  overflow-y: auto;
}

.sidebar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px;
  border-radius: 8px;
  border-left: 3px solid transparent;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-light);
}

.sidebar-item:hover {
  background: var(--navy-3);
}

.sidebar-item.active {
  background: var(--navy-3);
  border-left-color: var(--stage-color, var(--blue));
  color: var(--stage-color, var(--text));
}

.sidebar-item .badge {
  background: var(--navy);
  color: var(--text-light);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
}

.sidebar-item.active .badge {
  background: var(--stage-color, var(--blue));
  color: #fff;
}

.sidebar-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 4px;
}

.main-content {
  flex: 1;
  padding: 18px 20px;
  min-width: 0;
}

.stage-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.stage-heading h2 {
  margin: 0;
  font-size: 20px;
}

.column-count {
  background: var(--navy-3);
  color: var(--text-light);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
}

.job-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  align-items: start;
}

.job-list.view-block {
  display: block;
}

.column-empty {
  color: var(--text-light);
  font-size: 13px;
  padding: 20px 6px;
  text-align: center;
  grid-column: 1 / -1;
}

@media (max-width: 700px) {
  .app-body {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-item {
    flex: 1 1 auto;
  }
}

/* ---------- KPI cards / stat grid (Overview, Cash Flow, Customers) ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--navy-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover { border-color: var(--blue-light); }

.stat-card .label {
  color: var(--text-light);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 22px;
  font-weight: 700;
}

.stat-card .sub {
  color: var(--text-light);
  font-size: 11px;
  margin-top: 4px;
}

.stat-card .value.positive { color: var(--success); }
.stat-card .value.negative { color: var(--danger); }

.section-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-light);
  margin: 24px 0 10px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  color: var(--text-light);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.data-table .amt-positive { color: var(--success); font-weight: 600; }
.data-table .amt-negative { color: var(--danger); font-weight: 600; }
.data-table .muted { color: var(--text-light); }
.data-table tr.overdue { background: rgba(224, 82, 77, 0.08); }

.data-table-wrap {
  background: var(--navy-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 12px;
  overflow-x: auto;
}

/* ---------- Chart + period toggle ---------- */

.chart-card {
  background: var(--navy-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}

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

.chart-card-header h3 {
  margin: 0;
  font-size: 15px;
}

.period-toggle {
  display: flex;
  gap: 4px;
  background: var(--navy);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}

.period-toggle button {
  background: transparent;
  border: none;
  color: var(--text-light);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
}

.period-toggle button.active {
  background: var(--blue);
  color: #fff;
}

.chart-wrap {
  position: relative;
  height: 260px;
}

/* ---------- Cash flow list ---------- */

.cash-row-actions {
  text-align: right;
}

.owner-draw-tag {
  background: var(--orange);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 6px;
}

/* ---------- Customers ---------- */

.customer-card {
  background: var(--navy-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
}

.customer-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.customer-card-header .name {
  font-weight: 700;
  font-size: 15px;
}

.customer-card .contact-line {
  color: var(--text-light);
  font-size: 12px;
  margin-top: 2px;
}

.customer-card .balance-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--navy);
}

.customer-card .balance-badge.owes {
  color: var(--danger);
  border: 1px solid var(--danger);
}

.customer-card .balance-badge.clear {
  color: var(--success);
  border: 1px solid var(--success);
}

.customer-jobs {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.customer-job-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-light);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.customer-job-row:hover {
  background: var(--navy);
}

/* ---------- Profit summary (job modal) ---------- */

.profit-summary {
  background: var(--navy);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 16px;
  color: var(--text-light);
}

.profit-summary strong.positive { color: var(--success); }
.profit-summary strong.negative { color: var(--danger); }

/* ---------- Job card ---------- */

.job-card {
  background: var(--navy-3);
  border: 1px solid var(--border);
  border-left: 4px solid var(--stage-color, var(--blue));
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.1s ease, background 0.15s ease;
}

.job-card:active {
  transform: scale(0.98);
}

.job-card:hover {
  background: #223a5c;
}

.job-card .name {
  font-weight: 700;
  font-size: 14px;
}

.job-card .desc {
  color: var(--text-light);
  font-size: 12px;
}

.job-card .meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-light);
  margin-top: 2px;
}

.job-card .amount {
  color: var(--orange);
  font-weight: 700;
}

.job-card .move-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.move-btn {
  flex: 1;
  background: var(--navy);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 4px;
  font-size: 11px;
  cursor: pointer;
}

.move-btn:hover {
  border-color: var(--blue-light);
  color: var(--blue-light);
}

/* ---------- Buttons ---------- */

.primary-btn {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.primary-btn:hover { background: var(--blue-light); }

.danger-btn {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.danger-btn:hover { background: rgba(224, 82, 77, 0.12); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-light);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

.icon-btn:hover { color: var(--text); }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
  z-index: 100;
}

.modal-card {
  background: var(--navy-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  padding: 20px;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

#job-form, #call-form, #bank-form, #cash-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#job-form label, #call-form label, #bank-form label, #cash-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-light);
  flex: 1;
  min-width: 0;
}

.hint {
  color: var(--text-light);
  font-weight: 400;
}

#job-form input, #job-form textarea, #job-form select,
#call-form input,
#bank-form input,
#cash-form input, #cash-form select {
  background: var(--navy);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  width: 100%;
  min-width: 0;
}

#job-form textarea {
  resize: vertical;
}

.field-row {
  display: flex;
  gap: 10px;
}

@media (max-width: 480px) {
  .field-row { flex-direction: column; }
}

.stage-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stage-chip {
  border: 1px solid var(--border);
  background: var(--navy);
  color: var(--text-light);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
}

.stage-chip.active {
  background: var(--stage-color, var(--blue));
  border-color: var(--stage-color, var(--blue));
  color: #fff;
  font-weight: 700;
}

.job-timestamps {
  font-size: 11px;
  color: var(--text-light);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}
