:root {
  font-family: system-ui, -apple-system, sans-serif;
  color: #202b26;
  background: #f4f7f5;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body { margin: 0; }

.topbar {
  background: #173f32;
  color: white;
  padding: 18px max(20px, calc((100% - 1050px) / 2));
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand { font-size: 21px; font-weight: 800; }
.muted { color: #718078; font-size: 14px; }
.topbar .muted { color: #d0e1d8; }

.pill {
  background: #d8f4df;
  color: #20563a;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
}

main { max-width: 1050px; margin: auto; padding: 28px 20px; }
.welcome { margin-bottom: 24px; }
.eyebrow { color: #287454; font-weight: 700; font-size: 12px; letter-spacing: 1.5px; }
h1 { font-size: clamp(26px, 5vw, 38px); margin: 8px 0; }
h2 { font-size: 19px; margin-top: 0; }

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.card, .panel {
  background: white;
  border: 1px solid #e1e9e4;
  border-radius: 14px;
  padding: 20px;
}

.metric { font-size: clamp(20px, 3vw, 28px); font-weight: 750; margin-top: 10px; overflow-wrap: anywhere; }
#totalProfit { color: #187447; }

.panel { margin-bottom: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

label { display: grid; gap: 7px; font-size: 13px; font-weight: 650; }

input, select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #cdd9d1;
  border-radius: 8px;
  padding: 11px;
  font: inherit;
  background: white;
}

input:focus, select:focus, textarea:focus { outline: 2px solid #65a987; outline-offset: 1px; }

.actions, .section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}

button {
  background: #176344;
  color: white;
  border: 0;
  border-radius: 8px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:disabled { opacity: 0.6; cursor: wait; }
button.secondary { background: #e6efe9; color: #204d39; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 13px 10px; border-bottom: 1px solid #e8eee9; white-space: nowrap; }
th { color: #66766c; font-size: 12px; }
td:last-child { font-weight: 750; }
.footer { text-align: center; color: #718078; font-size: 12px; padding: 10px; }

@media (max-width: 600px) {
  main { padding: 20px 12px; }
  .cards { grid-template-columns: 1fr; gap: 10px; }
  .card { padding: 15px; }
  .panel { padding: 15px; }
  .form-grid { grid-template-columns: 1fr; }
  .actions { align-items: flex-start; flex-direction: column; }
}

.hidden {
  display: none !important;
}

.auth-panel {
  max-width: 480px;
  margin: 40px auto;
}

.auth-panel h1 {
  font-size: 28px;
}

.auth-panel form {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.auth-tabs {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.auth-tabs button {
  flex: 1;
}

#authStatus {
  min-height: 20px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

#logoutButton {
  background: #e6efe9;
  color: #204d39;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }
#openAddStallButton { background: #2f8a5f; }

@media (max-width: 600px) {
  .auth-panel {
    margin: 20px auto;
  }
}

.report-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin: 20px 0;
}

.report-controls label {
  flex: 1;
  min-width: 160px;
}

.report-cards {
  margin-top: 20px;
}

.report-details {
  margin-top: 24px;
}

.report-details h3 {
  font-size: 16px;
  margin-bottom: 12px;
}

.report-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid #e8eee9;
  font-size: 14px;
}

.report-row strong {
  text-align: right;
}

#monthlyProfit {
  color: #187447;
}

#reportStatus {
  font-size: 14px;
  min-height: 20px;
}

@media (max-width: 600px) {
  .report-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .report-controls button {
    width: 100%;
  }
}


/* Multi-stall management and destructive actions */
.stall-list { display: grid; gap: 10px; margin-top: 18px; }
.stall-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; border: 1px solid #e1e9e4; border-radius: 10px; padding: 12px 14px; }
.stall-item strong { display: block; overflow-wrap: anywhere; }
.stall-item .muted { margin-top: 4px; }
.stall-item-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
button.danger { background: #a12b2b; color: white; padding: 8px 11px; font-size: 13px; }
button.small { padding: 8px 11px; font-size: 13px; }
#recordsBody button { padding: 7px 10px; font-size: 12px; }
@media (max-width: 600px) {
  .stall-item { align-items: flex-start; flex-direction: column; }
  .stall-item-actions { width: 100%; }
}

/* In-page delete confirmation dialog */
.confirm-dialog {
  width: min(440px, calc(100% - 32px));
  border: 0;
  border-radius: 14px;
  padding: 24px;
  color: #202b26;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.confirm-dialog::backdrop { background: rgba(23, 63, 50, 0.45); }
.confirm-dialog form { display: grid; gap: 14px; }
.confirm-dialog h2 { color: #a12b2b; margin: 0; overflow-wrap: anywhere; }
.confirm-dialog p { margin: 0; }
.dialog-error { color: #a12b2b; font-size: 14px; min-height: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.confirm-dialog button.danger { padding: 12px 18px; font-size: inherit; }
@media (max-width: 600px) {
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions button { width: 100%; }
}

/* Stall selector styled like the other form fields */
select {
  appearance: none;
  cursor: pointer;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23176344' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
}
label[for="stallSelect"] { margin-top: 4px; }
#stallSelect { margin: 8px 0 6px; }
#stallStatus { font-size: 14px; min-height: 20px; margin: 4px 0 0; overflow-wrap: anywhere; }
.add-stall-dialog h2 { color: #202b26; }
@media (max-width: 600px) {
  .topbar-actions button { padding: 10px 12px; font-size: 14px; }
}

/* Account overview (all stalls combined) */
.overview-panel .section-heading { margin-top: 0; align-items: flex-start; }
.overview-period { min-width: 150px; }
.overview-cards { margin: 18px 0; }
.overview-cards .card { background: #f4f7f5; }
#overviewProfit { color: #187447; }
.overview-panel td .muted { font-size: 12px; font-weight: 400; margin-top: 2px; }
.overview-panel tr.total-row td { font-weight: 750; border-top: 2px solid #cdd9d1; border-bottom: 0; }
#overviewStatus { font-size: 14px; margin: 8px 0 0; }
.negative, #overviewProfit.negative { color: #a12b2b; }
.selected-stall-label { margin: 0 0 10px; }
@media (max-width: 600px) {
  .overview-panel .section-heading { flex-direction: column; align-items: stretch; }
}

/* Page tabs: Account overview / My hawker stalls */
.page-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  border-bottom: 2px solid #e1e9e4;
}
.page-tabs button {
  background: transparent;
  color: #66766c;
  border-radius: 8px 8px 0 0;
  padding: 12px 18px;
  margin-bottom: -2px;
  border-bottom: 3px solid transparent;
}
.page-tabs button:hover { color: #176344; background: #eef4f0; }
.page-tabs button.active {
  color: #176344;
  border-bottom-color: #176344;
}
.overview-panel button.small { padding: 6px 12px; font-size: 13px; }
@media (max-width: 600px) {
  .page-tabs button { flex: 1; padding: 12px 8px; font-size: 14px; }
}

/* Stall roles and members */
.role-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.3px;
}
.role-owner { background: #d8f4df; color: #20563a; }
.role-partner { background: #dde9fb; color: #24467a; }
.role-staff { background: #f3ead5; color: #6b4e12; }
.stall-item .role-badge { margin-top: 6px; }
.notice {
  background: #fff8e6;
  border: 1px solid #f0dfb0;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 14px;
}
.staff-notice { margin: 0 0 22px; }
.field-hint { font-weight: 400; font-size: 12px; }
.members-dialog { width: min(560px, calc(100% - 32px)); }
.members-dialog h2 { color: #202b26; }
.members-content { display: grid; gap: 14px; }
.members-list { display: grid; gap: 8px; }
.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid #e1e9e4;
  border-radius: 10px;
  padding: 10px 12px;
}
.member-email { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 14px; font-weight: 650; }
.member-row select { width: auto; padding: 7px 34px 7px 10px; font-size: 13px; }
.add-member-form { display: grid; gap: 10px; border-top: 1px solid #e8eee9; padding-top: 14px; }
.add-member-form h3 { margin: 0; font-size: 15px; }
.add-member-row { display: grid; grid-template-columns: 1fr 140px; gap: 10px; }
.add-member-form button { justify-self: start; }
@media (max-width: 600px) {
  .member-row { flex-wrap: wrap; }
  .member-email { flex-basis: 100%; }
  .add-member-row { grid-template-columns: 1fr; }
  .add-member-form button { width: 100%; }
}

/* Password peek (eye) toggle */
.password-field { position: relative; display: block; }
.password-field input { padding-right: 46px; }
.peek {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  color: #66766c;
  border-radius: 6px;
}
.peek:hover { background: #eef4f0; color: #176344; }
.peek:focus-visible { outline: 2px solid #65a987; }
.peek svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.peek .eye-closed, .peek.showing .eye-open { display: none; }
.peek.showing .eye-closed { display: block; }

/* Daily record form groups */
textarea { resize: vertical; min-height: 60px; }
.form-group {
  border: 1px solid #e1e9e4;
  border-radius: 12px;
  padding: 14px 16px 12px;
  margin: 18px 0 0;
  display: grid;
  gap: 12px;
}
.form-group legend { padding: 0 6px; font-weight: 750; font-size: 14px; color: #287454; }
.group-total { margin: 0; font-size: 14px; color: #4a5a51; text-align: right; }
.group-total strong { color: #202b26; }
/* Menu items sold: Sold x Cost / unit = Cost */
.goods-table th, .goods-table td { padding: 8px 6px; }
.goods-table td:first-child { white-space: normal; overflow-wrap: anywhere; font-weight: 650; min-width: 110px; }
.goods-table input { padding: 8px; min-width: 70px; }
.goods-table td:last-child { text-align: right; }
.goods-table th:last-child { text-align: right; }
input[readonly] { background: #f4f7f5; color: #4a5a51; }
.icon-button {
  flex-shrink: 0;
  width: 36px;
  height: 42px;
  padding: 0;
  background: #f6e7e7;
  color: #a12b2b;
  font-size: 20px;
  line-height: 1;
}
.icon-button:hover { background: #efd3d3; }
.goods-manage { border: 1px dashed #cdd9d1; border-radius: 10px; padding: 10px 12px; }
.goods-manage summary { cursor: pointer; font-weight: 700; font-size: 14px; color: #176344; }
.goods-manage[open] summary { margin-bottom: 8px; }
.menu-items-list { display: grid; gap: 8px; margin: 10px 0; }
.menu-item-row, .menu-add-row { display: flex; align-items: center; gap: 8px; }
.menu-item-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 14px; font-weight: 650; }
.menu-item-row .menu-item-cost { width: 120px; flex-shrink: 0; padding: 8px; }
.menu-add-row input[type="text"] { flex: 1; }
.menu-add-row input[type="number"] { width: 150px; flex-shrink: 0; }
.menu-add-row button, .menu-item-row button { flex-shrink: 0; }

/* Records table: details row */
.record-actions { display: flex; gap: 6px; }
.details-row td { background: #f7faf8; white-space: normal; font-weight: 400; }
.details-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; padding: 4px 2px; }
.details-grid h4 { margin: 0 0 6px; font-size: 13px; color: #287454; }
.details-line { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 3px 0; }
.details-line strong { font-weight: 650; }
.details-note { margin: 8px 0 0; font-size: 13px; color: #4a5a51; overflow-wrap: anywhere; }

/* Monthly report: per-item goods and other-expense notes */
.report-sublist { padding-left: 14px; border-left: 2px solid #e1e9e4; margin: 4px 0 6px; }
.report-subrow { display: flex; justify-content: space-between; gap: 16px; padding: 5px 0; font-size: 13px; color: #4a5a51; }
.report-subrow span:first-child { overflow-wrap: anywhere; }
.report-subrow span:last-child { flex-shrink: 0; }

@media (max-width: 600px) {
  .menu-add-row { flex-wrap: wrap; }
  .menu-add-row input[type="text"] { flex-basis: 100%; }
  .menu-add-row input[type="number"] { flex: 1; width: auto; }
  .menu-item-row .menu-item-cost { width: 96px; }
  .details-grid { grid-template-columns: 1fr; }
  .group-total { text-align: left; }
}
