/* CashOnCloud web admin — styling mirrors the Android app theme. */
:root {
  --blue: #004883;          /* colorPrimary */
  --light-blue: #0082c2;    /* colorPrimaryVariant */
  --light-gray: #93d4ef;    /* colorSecondary */
  --gray: #9c9e9e;
  --red: #b71c1c;
  --bg: #e6e6e6;            /* main_background */
  --white: #ffffff;
  --black: #000000;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  font-family: "Roboto", "Segoe UI", system-ui, sans-serif;
  color: var(--black);
}

#app { display: flex; flex-direction: column; min-height: 100vh; }

/* --- Top app bar --- */
.appbar {
  background: var(--blue);
  color: var(--white);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .25);
  position: sticky;
  top: 0;
  z-index: 5;
}
.appbar img { height: 32px; }
.appbar .title { font-size: 18px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar .logout {
  background: transparent; border: 1px solid rgba(255, 255, 255, .6);
  color: var(--white); border-radius: 20px; padding: 6px 14px; cursor: pointer;
}
.appbar .logout:hover { background: rgba(255, 255, 255, .12); }

/* --- Content + screens --- */
main { flex: 1; padding: 16px; max-width: 920px; width: 100%; margin: 0 auto; }
.screen { display: none; }
.screen.active { display: block; }
.subtitle { color: var(--blue); font-weight: 600; margin: 4px 0 16px; }

/* --- Site grid --- */
.sites-grid {
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: center;
}
.site-card {
  background: var(--white); border-radius: 16px; padding: 16px;
  width: 150px; min-height: 120px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; border: 2px solid transparent;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: border-color .15s, transform .1s;
}
.site-card:hover { transform: translateY(-2px); }
.site-card.selected { border-color: var(--light-blue); background: #f0faff; }
.site-card { overflow: hidden; }
.site-card img { height: 48px; max-width: 100%; object-fit: contain; }
.site-card .name { max-width: 100%; overflow-wrap: anywhere; }
.site-card .name { font-weight: 600; text-align: center; }
.site-card .idx { color: var(--gray); font-size: 13px; }

/* --- Action buttons --- */
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 20px; }
.btn {
  background: var(--light-gray); color: var(--blue);
  border: none; border-radius: 28px; padding: 14px 22px;
  font-weight: 700; font-size: 16px; cursor: pointer;
}
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--blue); color: var(--white); }
.btn.danger { background: var(--red); color: var(--white); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Cards / tables --- */
.card {
  background: var(--white); border-radius: 12px; padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .15); margin-bottom: 16px;
}
/* Diary date range */
.date-range { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.date-field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 160px; }
.date-field label { font-weight: 700; font-size: 14px; color: var(--blue); }
.date-field input {
  padding: 10px 12px; border: 1px solid #ccc; border-radius: 8px; font-size: 15px;
}
.date-field input:focus { outline: none; border-color: var(--light-blue); }
.date-range .btn { padding: 11px 22px; }

/* Horizontal scroll so 4-column tables never overflow narrow phones */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 360px; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid #eee; font-size: 14px; white-space: nowrap; }
th { color: var(--blue); }
tr:nth-child(even) td { background: #fafafa; }

/* --- Bottom navigation --- */
.bottom-nav {
  display: flex; background: var(--white);
  border-top: 1px solid #ddd; position: sticky; bottom: 0;
}
.bottom-nav button {
  flex: 1; background: none; border: none; padding: 10px; cursor: pointer;
  color: var(--gray); font-size: 13px; display: flex; flex-direction: column;
  align-items: center; gap: 4px;
}
.bottom-nav button.active { color: var(--blue); font-weight: 700; }
.bottom-nav .dot { width: 6px; height: 6px; border-radius: 50%; background: transparent; }
.bottom-nav button.active .dot { background: var(--blue); }

/* --- Login modal --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .5);
  display: none; align-items: center; justify-content: center; z-index: 20;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--white); border-radius: 16px; padding: 24px;
  width: 340px; max-width: 92vw; box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
}
.modal .brand { text-align: center; margin-bottom: 16px; }
.modal .brand img { height: 56px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; margin-bottom: 4px; font-size: 14px; }
.field input {
  width: 100%; padding: 10px 12px; border: 1px solid #ccc; border-radius: 8px; font-size: 15px;
}
.field input:focus { outline: none; border-color: var(--light-blue); }
.modal .error { color: var(--red); font-size: 13px; min-height: 18px; white-space: pre-line; }
.modal .row { display: flex; gap: 10px; margin-top: 8px; }
.modal .row .btn { flex: 1; padding: 12px; font-size: 15px; }
#captcha-container { margin: 10px 0 16px; min-height: 82px; display: flex; justify-content: center; max-width: 100%; overflow-x: auto; }
/* Give the standard (non-mobile) reCAPTCHA checkbox room inside the dialog */
#login-modal .modal { width: 384px; padding: 26px; }

.collect-title { text-align: center; font-size: 20px; font-weight: 700; margin-bottom: 18px; color: var(--black); }
.collect-modes .btn { flex: 1; }

/* Manual collection table */
.modal-wide { width: min(420px, 94vw); }
#manual-body .manual-qty {
  width: 64px; padding: 6px 4px; border: 1px solid #ccc; border-radius: 6px;
  font-size: 15px; text-align: center; box-sizing: border-box;
}
#manual-body .manual-qty:focus { outline: none; border-color: var(--light-blue); }
/* Span the full modal width: denomination column takes the slack (left),
   Level centered, "To collect" pinned to the right edge. */
#manual-modal table { width: 100%; table-layout: auto; }
#manual-modal th, #manual-modal td { white-space: nowrap; padding: 6px 8px; }
#manual-modal th:nth-child(1), #manual-modal td:nth-child(1) { text-align: start; width: auto; }
#manual-modal th:nth-child(2), #manual-modal td:nth-child(2) { text-align: center; width: 1%; }
#manual-modal th:nth-child(3), #manual-modal td:nth-child(3) { text-align: end; width: 1%; }

/* Clickable diary rows + transaction detail popup */
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #eaf6fd; }
.txn-body { margin-bottom: 16px; }
.txn-row {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 8px 2px; border-bottom: 1px solid #eee;
}
.txn-label { color: var(--blue); font-weight: 600; }
.txn-value { text-align: end; }

/* Task screen: stacked, full-width action buttons like the app */
.actions-stacked { flex-direction: column; align-items: stretch; max-width: 420px; margin: 0 auto; }
.actions-stacked .btn { width: 100%; padding: 18px; font-size: 18px; }
.task-code {
  display: none; max-width: 420px; margin: 18px auto 0; text-align: center;
  font-weight: 700; color: var(--blue); background: var(--white);
  border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}

/* Language / flag selector on the Main screen */
.lang-selector { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 8px; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--white); border: 1px solid #ccc; border-radius: 20px;
  padding: 6px 12px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--blue);
}
.lang-btn .flag { font-size: 18px; line-height: 1; }
.lang-btn.active { border-color: var(--light-blue); background: #f0faff; }
.lang-btn:hover { filter: brightness(.97); }

.version { text-align: center; color: var(--gray); font-size: 12px; margin-top: 24px; }
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: #333; color: #fff; padding: 10px 18px; border-radius: 20px;
  opacity: 0; transition: opacity .2s; z-index: 30; pointer-events: none;
}
.toast.show { opacity: 1; }
.empty { color: var(--gray); text-align: center; padding: 24px; }

/* --- Small-screen (phone) tuning --- */
@media (max-width: 480px) {
  main { padding: 12px; }
  .appbar { padding: 10px 12px; gap: 8px; }
  .appbar .title { font-size: 16px; }
  .appbar img { height: 28px; }
  .site-card { width: calc(50% - 12px); min-height: 110px; }
  .card { padding: 12px; }
  /* Fit tables to the screen instead of forcing horizontal scroll */
  table { min-width: 0; table-layout: fixed; }
  th, td { padding: 6px 4px; font-size: 12px; white-space: normal; overflow-wrap: anywhere; }
  .btn { padding: 12px 16px; font-size: 15px; }
  .actions-stacked .btn { padding: 16px; }
  .bottom-nav button { font-size: 12px; padding: 8px 4px; }
  .toast { bottom: 76px; max-width: 90vw; text-align: center; }
  /* Stack the collection-mode buttons top-to-bottom when too narrow */
  .collect-modes { flex-direction: column; }
  /* Make the manual-collection table fit narrow screens */
  .modal { padding: 16px; }
  #manual-modal th, #manual-modal td { padding: 6px 3px; font-size: 12px; }
  #manual-body .manual-qty { width: 44px; padding: 5px 2px; }
}
