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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
}

header {
  background: #2f5597;
  color: white;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

header h1 { font-size: 1.4rem; font-weight: 600; }

.header-actions { display: flex; gap: 0.75rem; align-items: center; }

.nav-links { display: flex; gap: 0.25rem; }
.nav-links a {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
}
.nav-links a:hover { color: white; background: rgba(255,255,255,0.15); }
.nav-links a.nav-active { color: white; background: rgba(255,255,255,0.25); }

.unit-label {
  color: white;
  background: rgba(255,255,255,0.18);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 500;
}

.tip-section {
  background: #e8f0fe;
  border-left: 4px solid #4472c4;
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  color: #1a3d80;
  font-size: 0.9rem;
  line-height: 1.55;
}

.tenant-link-row {
  padding: 0.85rem 0;
  border-bottom: 1px solid #eee;
}
.tenant-link-row:last-child { border-bottom: none; }
.tenant-link-label { font-weight: 600; color: #2f5597; margin-bottom: 0.4rem; font-size: 0.95rem; }
.tenant-link-url {
  background: #f5f5f5;
  padding: 0.45rem 0.7rem;
  border-radius: 4px;
  margin-bottom: 0.55rem;
  word-break: break-all;
}
.tenant-link-url code { background: transparent; padding: 0; font-size: 0.8rem; color: #333; }
.tenant-link-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.tenant-link-actions a.btn-secondary,
.tenant-link-actions button {
  display: inline-block;
  width: auto;
  margin-top: 0;
  text-decoration: none;
  line-height: 1.2;
}

.manager-landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 200px);
  padding: 2rem 1rem;
}
.manager-landing-content {
  background: white;
  border-radius: 12px;
  padding: 2.5rem 2rem;
  max-width: 480px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.manager-landing-content h2 { color: #2f5597; margin-bottom: 1rem; font-size: 1.3rem; }
.manager-landing-content p { color: #555; margin-bottom: 1rem; line-height: 1.5; font-size: 0.95rem; }
.manager-landing-content button { margin-top: 1rem; }

.btn-primary {
  background: #4472c4;
  color: white;
  border: none;
  padding: 0.5rem 1.2rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: #3461b3; }

.btn-secondary {
  background: #e0e0e0;
  color: #333;
  border: none;
  padding: 0.5rem 1.2rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn-secondary:hover { background: #d0d0d0; }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary:disabled:hover { background: #e0e0e0; }

.btn-small { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

.btn-icon {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  opacity: 0.8;
}
.btn-icon:hover { opacity: 1; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

.month-picker {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.month-picker label { font-weight: 600; color: #2f5597; font-size: 0.95rem; }
.month-picker select {
  padding: 0.4rem 0.8rem;
  border: 2px solid #4472c4;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #2f5597;
  background: white;
  cursor: pointer;
}

/* Summary Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: white;
  border-radius: 10px;
  padding: 1.2rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.card .label { font-size: 0.8rem; color: #666; margin-bottom: 0.3rem; }
.card .value { font-size: 1.6rem; font-weight: 700; color: #2f5597; }
.card .sub { font-size: 0.75rem; color: #999; margin-top: 0.2rem; }

/* Charts */
.chart-section {
  background: white;
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.chart-section h2 { font-size: 1.1rem; color: #2f5597; margin-bottom: 1rem; }
.chart-container { position: relative; width: 100%; overflow-x: auto; }
.chart-container canvas { min-height: 400px; }
.chart-container-tall canvas { min-height: 500px; }

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.chart-header h2 { margin-bottom: 0; }

select#room-select {
  padding: 0.4rem 0.8rem;
  border: 2px solid #4472c4;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #2f5597;
  background: white;
  cursor: pointer;
}

/* Tables */
.table-section {
  background: white;
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.table-section h2 { font-size: 1.1rem; color: #2f5597; margin-bottom: 1rem; }
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
th {
  background: #2f5597;
  color: white;
  padding: 0.6rem 0.8rem;
  text-align: center;
  font-weight: 500;
  white-space: nowrap;
}
td {
  padding: 0.5rem 0.8rem;
  text-align: center;
  border-bottom: 1px solid #eee;
}
tr:hover td { background: #f5f8ff; }
td:first-child, th:first-child { text-align: left; }
td:nth-child(2), th:nth-child(2) { text-align: center; }

td.high { background: #fde8e8; color: #c00000; font-weight: 600; }
td.low { background: #e8f5e9; color: #2e7d32; }

tr.totals-row td { background: #f0f4fa; border-top: 2px solid #4472c4; color: #2f5597; }

.table-wrapper.edit-mode td.editable,
.table-wrapper.edit-mode td.editable-name {
  cursor: pointer;
  background: #fffbea;
  outline: 1px dashed #b38600;
  outline-offset: -2px;
}
.table-wrapper.edit-mode td.editable:hover,
.table-wrapper.edit-mode td.editable-name:hover { background: #e8f0fe; outline: 2px solid #4472c4; outline-offset: -2px; }
.edit-hint { font-size: 0.8rem; color: #b38600; font-weight: 500; margin-bottom: 0.75rem; }
.chart-hint { font-size: 0.8rem; color: #666; margin-bottom: 0.75rem; }
td.editing { padding: 0; }
td.editing input {
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 0.5rem 0.8rem;
  border: 2px solid #4472c4;
  border-radius: 0;
  font-size: 0.85rem;
  font-family: inherit;
  text-align: center;
  background: white;
}
td.changed { background: #fff3cd; }

.hidden { display: none; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
#setup-modal { z-index: 110; }

.modal-content {
  background: white;
  border-radius: 12px;
  padding: 2rem;
  width: 90%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-content.modal-wide { max-width: 560px; }

.modal-content h2 { color: #2f5597; margin-bottom: 1rem; font-size: 1.2rem; }
.modal-content p { color: #555; font-size: 0.85rem; margin-bottom: 1rem; line-height: 1.5; }
.modal-content code { background: #f0f0f0; padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.8rem; }

.modal-content input[type="password"],
.modal-content input[type="text"],
.modal-content input[type="date"],
.modal-content input[type="number"] {
  width: 100%;
  padding: 0.6rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}
.modal-content input:focus { outline: none; border-color: #4472c4; }
.modal-content input[readonly] { background: #f0f0f0; color: #666; cursor: not-allowed; }

.modal-row { display: flex; gap: 0.5rem; align-items: stretch; }
.modal-row input { flex: 1; }

.modal-content button { width: 100%; margin-top: 0.5rem; }

.modal-actions { display: flex; gap: 0.75rem; margin-top: 1rem; }
.modal-actions button { flex: 1; }

.form-row { margin-bottom: 1rem; }
.form-row label { display: block; font-weight: 500; margin-bottom: 0.3rem; color: #333; }

.reading-entry {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.reading-entry label { flex: 1; font-size: 0.85rem; color: #333; min-width: 120px; }
.reading-entry input { width: 140px; }

.error {
  color: #8a0000;
  background: #fdecea;
  border-left: 4px solid #c00000;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 0.8rem;
  margin-top: 0.75rem;
  line-height: 1.4;
}
.error.hidden { display: none; }

.form-hint { color: #666; font-size: 0.75rem; margin-top: 0.3rem; line-height: 1.4; }

.alert-banner {
  background: #fff8e1;
  border-left: 4px solid #f4a261;
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}
.alert-banner h3 {
  color: #8a4500;
  font-size: 1rem;
  margin: 0 0 0.5rem;
}
.alert-banner ul {
  margin: 0;
  padding-left: 1.25rem;
  color: #4a2900;
  font-size: 0.9rem;
  line-height: 1.6;
}
.alert-banner li + li { margin-top: 0.4rem; }

footer {
  text-align: center;
  padding: 1.5rem;
  color: #999;
  font-size: 0.8rem;
}

/* Responsive */
@media (max-width: 600px) {
  header { padding: 0.8rem 1rem; }
  header h1 { font-size: 1.1rem; }
  main { padding: 1rem; }
  .chart-header { flex-direction: column; gap: 0.5rem; align-items: flex-start; }
  .chart-header .header-actions { flex-wrap: wrap; row-gap: 0.5rem; }
  .chart-header .header-actions button { padding: 0.4rem 0.8rem; font-size: 0.85rem; }
  .modal-row { flex-wrap: wrap; }
  .card { padding: 0.9rem; }
  .card .value { font-size: 1.4rem; }
}
