/* ── RESET & BASE ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: 'Segoe UI', system-ui, sans-serif; font-size: 12px; background: #e8eaf0; color: #222; }

/* ── LOGIN ────────────────────────────────────────────────────── */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(135deg,#1a3a5c,#2d6a9f);
}
.login-card {
  background: #fff; border-radius: 10px; padding: 36px; width: 340px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.login-card h1 { color: #1a3a5c; font-size: 20px; margin-bottom: 4px; }
.login-card p  { color: #666; font-size: 12px; margin-bottom: 22px; }
.login-card label { display: block; font-weight: 600; font-size: 11px; color: #555; margin-bottom: 4px; }
.login-card input {
  width: 100%; padding: 9px 10px; border: 1px solid #ccc;
  border-radius: 5px; font-size: 13px; margin-bottom: 14px;
}
.login-card input:focus { outline: none; border-color: #2d6a9f; box-shadow: 0 0 0 2px rgba(45,106,159,.2); }
.btn-login {
  width: 100%; padding: 10px; background: #1a3a5c; color: #fff;
  border: none; border-radius: 5px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-login:hover { background: #2d6a9f; }
.login-err { color: #c0392b; font-size: 11px; margin: -8px 0 10px; display: none; }

/* ── APP SHELL ────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── HEADER ───────────────────────────────────────────────────── */
.app-header {
  background: #1a3a5c; color: #fff;
  padding: 6px 12px; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-shrink: 0;
}
.app-header h1 { font-size: 14px; font-weight: 700; white-space: nowrap; }
.header-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.header-controls select, .header-controls input[type=text] {
  padding: 3px 6px; font-size: 11px; border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.1); color: #fff; border-radius: 4px; height: 26px;
}
.header-controls select option { color: #222; background: #fff; }
.header-controls input[type=text]::placeholder { color: rgba(255,255,255,.6); }
.header-controls input[type=text]:focus, .header-controls select:focus { outline: none; background: rgba(255,255,255,.2); }
.chk-label { display: flex; align-items: center; gap: 4px; font-size: 11px; color: rgba(255,255,255,.9); cursor: pointer; white-space: nowrap; }
.chk-label input { cursor: pointer; }
.hdr-btn {
  padding: 3px 10px; border: none; border-radius: 4px; cursor: pointer;
  font-size: 11px; font-weight: 600; height: 26px; white-space: nowrap;
}
.btn-add    { background: #27ae60; color: #fff; }
.btn-add:hover { background: #219a52; }
.btn-print  { background: rgba(255,255,255,.15); color: #fff; }
.btn-print:hover { background: rgba(255,255,255,.3); }
.btn-logout { background: rgba(255,255,255,.1); color: rgba(255,255,255,.8); }
.btn-logout:hover { background: rgba(255,255,255,.2); }
.hdr-user { font-size: 11px; color: rgba(255,255,255,.7); white-space: nowrap; }

/* ── LEGEND BAR ───────────────────────────────────────────────── */
.legend-bar {
  background: #fff; border-bottom: 1px solid #ddd;
  padding: 3px 12px; display: flex; align-items: center; gap: 14px; flex-shrink: 0;
  font-size: 10px; color: #555;
}
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.dot-green  { background: #a8d5b5; }
.dot-yellow { background: #ffe082; }
.dot-white  { background: #f0f0f0; border: 1px solid #ccc; }
.dot-red    { background: #f4a0a0; }
.dot-gray   { background: #ccc; }
.legend-bar .sep { color: #ccc; }
.stat-counts { margin-left: auto; display: flex; gap: 12px; font-size: 10px; }
.stat-item { color: #555; }
.stat-item strong { color: #1a3a5c; }

/* ── CHART GRID ───────────────────────────────────────────────── */
.chart-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  grid-template-areas:
    "ym      ym-adv   yw        yw-adv"
    "rs      rs-act   eq        bishop"
    "primary pri-tchr noCall    ss"
    "mission ward     stake     members";
  gap: 4px;
  padding: 4px;
  overflow: hidden;
  min-height: 0;
}

/* ── PANEL ────────────────────────────────────────────────────── */
.panel {
  display: flex; flex-direction: column;
  background: #fff; border: 1px solid #c8cdd6;
  border-radius: 4px; overflow: hidden; min-height: 0;
}
.panel-ym      { grid-area: ym; }
.panel-ym-adv  { grid-area: ym-adv; }
.panel-yw      { grid-area: yw; }
.panel-yw-adv  { grid-area: yw-adv; }
.panel-rs       { grid-area: rs; }
.panel-rs-act   { grid-area: rs-act; }
.panel-eq       { grid-area: eq; }
.panel-bishop   { grid-area: bishop; }
.panel-primary  { grid-area: primary; }
.panel-pri-tchr { grid-area: pri-tchr; }
.panel-noCall   { grid-area: noCall; display: none; }
.panel-ss       { grid-area: ss; }
.panel-mission { grid-area: mission; }
.panel-ward    { grid-area: ward; }
.panel-stake   { grid-area: stake; }
.panel-members { grid-area: members; }

.panel-hdr {
  background: #1a3a5c; color: #fff;
  padding: 3px 7px;
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
.panel-hdr span { opacity: .7; font-weight: 400; font-size: 9px; }
.panel-body { flex: 1; overflow-y: auto; overflow-x: hidden; }
.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-thumb { background: #c0c0c0; border-radius: 2px; }

/* ── CALLING ROW ──────────────────────────────────────────────── */
.c-row {
  display: flex; align-items: baseline; gap: 3px;
  padding: 2px 6px; border-bottom: 1px solid #f0f0f0;
  cursor: pointer; transition: filter .1s; line-height: 1.35;
  font-size: 11px;
}
.c-row:last-child { border-bottom: none; }
.c-row:hover { filter: brightness(.93); }

/* status row colors */
.c-row.s-proposed, .c-row.s-prayed, .c-row.s-accepted { background: #c8ecd1; }
.c-row.s-sustained { background: #fff0b3; }
.c-row.s-set-apart, .c-row.s-entered-in-lcr { background: #fff; }
.c-row.r-proposed  { background: #fcd5d5 !important; }
.c-row.r-released  { background: #e0e0e0 !important; color: #999; text-decoration: line-through; }

.c-abbrev { font-weight: 700; color: #1a3a5c; flex-shrink: 0; white-space: nowrap; font-size: 10px; }
.c-name   { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-code   { font-size: 9px; font-weight: 700; color: #555; flex-shrink: 0;
            background: rgba(0,0,0,.07); border-radius: 2px; padding: 0 3px; }
.c-row.s-proposed .c-code, .c-row.s-prayed .c-code, .c-row.s-accepted .c-code { color: #1a7a35; background: rgba(0,100,40,.12); }
.c-row.s-sustained .c-code { color: #8a6000; background: rgba(180,120,0,.15); }
.c-row.s-set-apart .c-code { color: #1a5a8a; background: rgba(40,100,180,.12); }
.c-row.s-entered-in-lcr .c-code { color: #5a2080; background: rgba(100,40,180,.12); }
.c-row.r-proposed .c-code  { color: #8a1010; background: rgba(200,0,0,.12); }

.c-note { font-size: 9px; color: #888; flex-shrink: 0; font-style: italic; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* members no-calling panel */
.nc-item {
  padding: 2px 6px; border-bottom: 1px solid #f0f0f0;
  font-size: 11px; display: flex; align-items: center;
  cursor: pointer;
}
.nc-item:hover { background: #fdecea; }
.nc-item::after { content: '✕'; margin-left: auto; color: #ddd; font-size: 10px; }
.nc-item:hover::after { color: #e74c3c; }
.nc-add-row { padding: 3px 6px; display: flex; gap: 4px; }
.nc-add-row input { flex: 1; font-size: 11px; padding: 2px 5px; border: 1px solid #ddd; border-radius: 3px; }
.nc-add-row button { font-size: 11px; padding: 2px 7px; background: #1a3a5c; color: #fff; border: none; border-radius: 3px; cursor: pointer; }

/* ── POPUP ────────────────────────────────────────────────────── */
#popup {
  position: fixed; z-index: 500; display: none;
  background: #fff; border: 1px solid #c0c8d8; border-radius: 7px;
  box-shadow: 0 6px 24px rgba(0,0,0,.22); width: 260px;
  font-size: 12px;
}
#popup.open { display: block; }
.popup-name  { font-weight: 700; font-size: 12px; color: #1a3a5c; padding: 8px 10px 2px; }
.popup-call  { font-size: 11px; color: #555; padding: 0 10px 6px; border-bottom: 1px solid #eee; }
.popup-status-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px; gap: 4px;
}
.popup-step-btn {
  background: #e8eaf0; border: none; border-radius: 4px;
  cursor: pointer; font-size: 14px; width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.popup-step-btn:hover { background: #c8cdd6; }
.popup-step-btn:disabled { opacity: .3; cursor: default; }
.popup-badge {
  flex: 1; text-align: center; font-size: 11px; font-weight: 700;
  padding: 3px 6px; border-radius: 4px;
}
.pb-proposed, .pb-prayed, .pb-accepted { background: #c8ecd1; color: #1a5a2a; }
.pb-sustained { background: #fff0b3; color: #7a5500; }
.pb-set-apart { background: #d0e8f8; color: #1a3a6a; }
.pb-entered-in-lcr { background: #e8d8f8; color: #5a1a8a; }
.pb-release { background: #fcd5d5; color: #8a1010; }
.pb-released { background: #e0e0e0; color: #666; }
.popup-actions {
  display: flex; gap: 4px; padding: 4px 8px 8px; flex-wrap: wrap;
}
.pa-btn {
  flex: 1; padding: 5px 4px; border: none; border-radius: 4px;
  cursor: pointer; font-size: 11px; font-weight: 600; min-width: 52px;
}
.pa-rel    { background: #e67e22; color: #fff; }
.pa-rel:hover { background: #d35400; }
.pa-rel.active { background: #c0392b; }
.pa-edit   { background: #2980b9; color: #fff; }
.pa-edit:hover { background: #1a6a99; }
.pa-del    { background: #e74c3c; color: #fff; }
.pa-del:hover { background: #c0392b; }
.popup-notes { padding: 0 8px 6px; }
.popup-notes textarea {
  width: 100%; font-size: 10px; padding: 4px; border: 1px solid #ddd;
  border-radius: 3px; resize: none; height: 40px; color: #555;
}
.popup-assignee { padding: 2px 8px 6px; font-size: 10px; color: #888; display: flex; align-items: center; gap: 4px; }
.popup-assignee input { flex: 1; font-size: 10px; padding: 2px 5px; border: 1px solid #ddd; border-radius: 3px; }

/* ── FULL EDIT MODAL ──────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 600;
  align-items: flex-start; justify-content: center; padding: 20px; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: 8px; width: 100%; max-width: 520px; margin: auto; box-shadow: 0 8px 32px rgba(0,0,0,.22); }
.modal-hdr { background: #1a3a5c; color: #fff; padding: 11px 16px; border-radius: 8px 8px 0 0; display: flex; justify-content: space-between; align-items: center; }
.modal-hdr h3 { font-size: 14px; }
.modal-x { background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; line-height: 1; padding: 0 2px; }
.modal-body { padding: 16px; }
.modal-body label { display: block; font-size: 11px; font-weight: 600; color: #555; margin-bottom: 3px; margin-top: 10px; }
.modal-body label:first-child { margin-top: 0; }
.modal-body input, .modal-body select, .modal-body textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #ccc; border-radius: 4px; font-size: 12px;
}
.modal-body textarea { resize: vertical; min-height: 50px; }
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus { outline: none; border-color: #2d6a9f; }
.step-grid { display: grid; grid-template-columns: 120px 1fr; gap: 4px 8px; margin-top: 8px; background: #f7f8fa; padding: 10px; border-radius: 5px; align-items: center; }
.step-lbl { font-size: 11px; font-weight: 600; color: #444; }
.step-lbl.current { color: #1a3a5c; background: #d0e8f8; border-radius: 3px; padding: 1px 5px; }
.step-grid input { padding: 4px 7px; font-size: 11px; }
.modal-ftr { padding: 10px 16px; border-top: 1px solid #eee; display: flex; justify-content: flex-end; gap: 8px; }
.btn-save   { background: #27ae60; color: #fff; border: none; padding: 7px 18px; border-radius: 4px; font-weight: 600; cursor: pointer; font-size: 13px; }
.btn-cancel { background: #95a5a6; color: #fff; border: none; padding: 7px 14px; border-radius: 4px; font-weight: 600; cursor: pointer; font-size: 13px; }
.btn-save:hover { background: #219a52; }
.btn-cancel:hover { background: #7f8c8d; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.two-col > * { min-width: 0; }

/* ── CONFIRM ──────────────────────────────────────────────────── */
.confirm-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 700; align-items: center; justify-content: center; }
.confirm-overlay.open { display: flex; }
.confirm-box { background: #fff; border-radius: 7px; padding: 22px; max-width: 320px; width: 90%; box-shadow: 0 4px 20px rgba(0,0,0,.2); }
.confirm-box h4 { font-size: 14px; margin-bottom: 8px; }
.confirm-box p { font-size: 12px; color: #555; margin-bottom: 18px; }
.confirm-btns { display: flex; gap: 8px; justify-content: flex-end; }

/* ── USER MANAGEMENT ─────────────────────────────────────────── */
.btn-users    { background: rgba(255,255,255,.15); color: #fff; }
.btn-users:hover    { background: rgba(255,255,255,.28); }
.btn-calldefs { background: rgba(255,255,255,.15); color: #fff; }
.btn-calldefs:hover { background: rgba(255,255,255,.28); }

.user-table { width: 100%; border-collapse: collapse; }
.user-table thead tr { background: #f5f6f8; }
.user-table th { padding: 7px 10px; text-align: left; font-size: 11px; color: #555; font-weight: 600; border-bottom: 2px solid #e8eaf0; }
.user-table td { padding: 7px 10px; font-size: 12px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
.user-table tr:last-child td { border-bottom: none; }
.u-username { color: #666; font-family: monospace; }

.role-badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 10px; font-weight: 700; }
.role-admin  { background: #1a3a5c; color: #fff; }
.role-viewer { background: #7f8c8d; color: #fff; }

.u-actions { display: flex; gap: 4px; justify-content: flex-end; }
.u-btn { padding: 3px 9px; border: none; border-radius: 3px; cursor: pointer; font-size: 11px; font-weight: 600; }
.u-edit { background: #2980b9; color: #fff; }
.u-edit:hover { background: #1a6a99; }
.u-pw   { background: #e67e22; color: #fff; }
.u-pw:hover { background: #d35400; }
.u-del  { background: #e74c3c; color: #fff; }
.u-del:hover { background: #c0392b; }
.u-del:disabled { background: #ccc; cursor: default; }

.urow-form { display: none; background: #f8f9fa; }
.urow-form td { padding: 0; }
.urow-form-inner { padding: 10px 12px; }
.urow-form-inner label { display: block; font-size: 11px; font-weight: 600; color: #555; margin-bottom: 3px; }
.urow-form-inner input, .urow-form-inner select { width: 100%; padding: 6px 8px; border: 1px solid #ccc; border-radius: 4px; font-size: 12px; }
.urow-form-btns { display: flex; gap: 6px; margin-top: 8px; }
.urow-form-btns .btn-save, .urow-form-btns .btn-cancel { padding: 5px 14px; font-size: 12px; }

.user-add-section { padding: 14px 16px; border-top: 2px solid #e8eaf0; }
.user-add-title { display: block; font-size: 12px; font-weight: 700; color: #1a3a5c; margin-bottom: 10px; }
.user-add-section label { display: block; font-size: 11px; font-weight: 600; color: #555; margin-bottom: 3px; }
.user-add-section input, .user-add-section select { width: 100%; padding: 7px 9px; border: 1px solid #ccc; border-radius: 4px; font-size: 12px; }

/* ── MOBILE (stacked single column) ──────────────────────────────── */
@media (max-width: 720px) {
  html, body { overflow: auto; }
  #app { height: auto; min-height: 100vh; }

  .app-header {
    position: sticky; top: 0; z-index: 50;
    flex-direction: column; align-items: stretch; justify-content: flex-start;
  }
  .app-header h1 { text-align: center; }
  .legend-bar { flex-wrap: wrap; }

  .chart-grid {
    display: block;
    height: auto;
    overflow: visible;
  }
  .panel { margin-bottom: 8px; }
  .panel-body { overflow: visible; }
}

/* ── PRINT ────────────────────────────────────────────────────── */
@media print {
  html, body { overflow: visible; height: auto; }
  .app-header, .legend-bar { padding: 4px 8px; }
  .header-controls, .btn-logout, .hdr-user { display: none !important; }
  #popup, .modal-overlay, .confirm-overlay { display: none !important; }
  #app { height: auto; }
  .chart-grid { height: auto; overflow: visible; gap: 3px; padding: 3px; }
  .panel { overflow: visible; page-break-inside: avoid; }
  .panel-body { overflow: visible; max-height: none; }
  .panel-hdr { background: #1a3a5c !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .c-row.s-proposed, .c-row.s-prayed, .c-row.s-accepted { background: #c8ecd1 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .c-row.s-sustained { background: #fff0b3 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .c-row.r-proposed  { background: #fcd5d5 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .nc-del, .nc-add-row { display: none; }
}
