/* ==========================================================================
   Group Treasury — stylesheet

   Two constraints shape everything here (spec 8):
   1. RTL and LTR must both look right. Every directional rule uses CSS logical
      properties (inline-start/end, not left/right), so switching dir="rtl" on
      <html> is all that Arabic needs — there is no separate RTL stylesheet.
   2. Members may be older and unfamiliar with apps. So: large base font, high
      contrast, generous tap targets, and no interaction that depends on hover.
   ========================================================================== */

:root {
  --bg:          #f4f6f8;
  --surface:     #ffffff;
  --border:      #dfe4ea;
  --text:        #1b2733;
  --text-muted:  #6b7a8c;

  --brand:       #1f6f5c;
  --brand-dark:  #185547;
  --brand-soft:  #e8f3f0;

  --danger:      #b3261e;
  --danger-soft: #fdecea;
  --warn-soft:   #fff8e6;
  --warn-border: #f0d48a;

  --negative:    #b3261e;  /* owes money */
  --positive:    #1f6f5c;  /* in credit  */

  --radius:      10px;
  --shadow:      0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}

* { box-sizing: border-box; }

html { font-size: 17px; }          /* deliberately larger than the 16px default */

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Sans Hebrew", Arial, sans-serif;
  line-height: 1.6;
}

/* Arabic and Hebrew glyphs need a touch more room to stay legible. */
html[dir="rtl"] body { font-size: 1.02rem; line-height: 1.75; }

h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

code { font-family: ui-monospace, Consolas, monospace; font-size: .85em; }

/* --- Top bar --------------------------------------------------------------- */
.topbar {
  background: var(--surface);
  border-block-end: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: .6rem 1rem;
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
}
.brand {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 700; color: var(--text); font-size: 1.05rem;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center;
  inline-size: 2rem; block-size: 2rem;
  background: var(--brand); color: #fff; border-radius: 8px; font-weight: 700;
}
.brand-mark.big { inline-size: 3rem; block-size: 3rem; font-size: 1.5rem; }

.mainnav { display: flex; gap: .35rem; flex-wrap: wrap; flex: 1; }
.mainnav a {
  padding: .45rem .7rem; border-radius: 8px; color: var(--text);
  font-weight: 500; white-space: nowrap;
}
.mainnav a:hover { background: var(--brand-soft); text-decoration: none; }

.topbar-right { display: flex; align-items: center; gap: .75rem; }
.whoami { color: var(--text-muted); font-size: .9rem; }

.badge {
  display: inline-grid; place-items: center;
  min-inline-size: 1.4rem; block-size: 1.4rem; padding: 0 .35rem;
  margin-inline-start: .3rem;
  background: var(--danger); color: #fff;
  border-radius: 999px; font-size: .78rem; font-weight: 700;
}

.langswitch { display: flex; gap: .3rem; font-size: .85rem; }
.langswitch a { padding: .2rem .45rem; border-radius: 6px; color: var(--text-muted); }
.langswitch a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.langswitch.center { justify-content: center; margin-block-start: 1rem; }

/* --- Layout ---------------------------------------------------------------- */
.container { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-block-end: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  margin-block-end: 1.1rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.card-attention { border-color: var(--warn-border); background: var(--warn-soft); }
.center-card { max-width: 480px; margin: 3rem auto; text-align: center; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }

/* --- Stats ----------------------------------------------------------------- */
.stat-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem; margin-block-end: 1.1rem;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem;
}
.stat-lead { border-color: var(--brand); }
.stat-label { color: var(--text-muted); font-size: .9rem; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.25; }
.stat-help  { color: var(--text-muted); font-size: .82rem; margin-block-start: .2rem; }

.hero { text-align: center; padding: 2rem 1.25rem; }
.hero-label { color: var(--text-muted); font-size: 1rem; }
.hero-value { font-size: 3rem; font-weight: 700; line-height: 1.2; margin: .25rem 0; }
.hero-sub { color: var(--text-muted); margin-block-end: 1rem; }

.is-negative { color: var(--negative); }
.is-positive { color: var(--positive); }
.is-neutral  { color: var(--text-muted); }

/* --- Tables ---------------------------------------------------------------- */
.table { inline-size: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: .6rem .55rem;
  border-block-end: 1px solid var(--border);
  text-align: start;                /* flips automatically in RTL */
  vertical-align: top;
}
.table th {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .02em;
  color: var(--text-muted); font-weight: 600; white-space: nowrap;
}
.table tbody tr:hover { background: #fafbfc; }
.table-plain td { border: 0; padding: .35rem .5rem; }
.table .num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.total-row td { font-weight: 700; border-block-start: 2px solid var(--border); }
.row-muted { opacity: .55; }

.nowrap { white-space: nowrap; }
.muted  { color: var(--text-muted); }
.small  { font-size: .84rem; }

/* --- Buttons --------------------------------------------------------------- */
.btn {
  display: inline-block; padding: .5rem .9rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  text-align: center; white-space: nowrap;
}
.btn:hover { background: #f7f9fa; text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: #eef1f4; }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn-lg { padding: .7rem 1.4rem; font-size: 1.05rem; }
.btn-block { inline-size: 100%; }

.quickbar { display: flex; gap: .6rem; flex-wrap: wrap; margin-block-end: 1.1rem; }
.toolbar  { margin-block-end: .75rem; }
form.inline { display: inline; }
.inline-details { display: inline-block; }
.inline-details[open] > summary { margin-block-end: .4rem; }
.inline-details summary { list-style: none; }
.inline-details summary::-webkit-details-marker { display: none; }
.stack { display: flex; flex-direction: column; gap: .4rem; max-inline-size: 320px; }

/* --- Forms ----------------------------------------------------------------- */
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: .9rem; align-items: end;
}
.form-grid.indent { padding-inline-start: 1.5rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span { font-size: .9rem; font-weight: 600; }
.field-wide { grid-column: 1 / -1; }
.field-actions { display: flex; align-items: end; gap: .5rem; }
.form-actions { margin-block: 1rem; }

.checkfield { flex-direction: row; align-items: center; gap: .5rem; }
.checkfield input { inline-size: 1.15rem; block-size: 1.15rem; }
.checkfield > span { font-weight: 500; }

input[type="text"], input[type="password"], input[type="email"],
input[type="date"], select, textarea {
  font: inherit; padding: .5rem .6rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  inline-size: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand);
}
.req { color: var(--danger); }

.toolbar-form { display: flex; gap: .8rem; flex-wrap: wrap; align-items: end; padding: .9rem 1.1rem; }
.toolbar-form .field { flex: 0 1 190px; }

/* --- Flashes and notes ------------------------------------------------------ */
.flash {
  padding: .7rem 1rem; border-radius: 8px; margin-block-end: .9rem;
  border: 1px solid transparent; font-weight: 500;
}
.flash-success { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); }
.flash-error   { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.flash-info    { background: #eaf2fb; border-color: #9fc3e8; color: #1c4e80; }

.note-box {
  background: var(--brand-soft); border: 1px solid #cfe4de;
  border-radius: 8px; padding: .75rem 1rem; margin-block-start: .8rem;
}
.note-box p { margin: .3rem 0 0; font-size: .88rem; color: var(--text-muted); }

/* --- Tags ------------------------------------------------------------------ */
.tag {
  display: inline-block; padding: .12rem .5rem; border-radius: 999px;
  background: #eef1f4; color: var(--text-muted);
  font-size: .78rem; font-weight: 600; white-space: nowrap;
}
.tag-payment, .tag-confirmed, .tag-self_paid_credit { background: var(--brand-soft); color: var(--brand-dark); }
.tag-monthly_charge, .tag-pending { background: var(--warn-soft); color: #8a6d1f; }
.tag-opening_balance { background: #eaf2fb; color: #1c4e80; }
.tag-rejected, .tag-reversal { background: var(--danger-soft); color: var(--danger); }
.tag-selfpaid { background: #f3ecfb; color: #6b3fa0; }

/* --- Feed ------------------------------------------------------------------ */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: .6rem 0; border-block-end: 1px solid var(--border); }
.feed li:last-child { border-block-end: 0; }
.feed-top { display: flex; justify-content: space-between; gap: 1rem; font-weight: 600; }
.feed-reason { font-size: .9rem; }
.feed-meta { color: var(--text-muted); font-size: .8rem; }

/* --- Address book ----------------------------------------------------------- */
.contact-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem;
}
.contact-card { margin: 0; display: flex; flex-direction: column; gap: .3rem; }
.contact-role { color: var(--text-muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .02em; }
.contact-name { font-size: 1.15rem; font-weight: 700; }
.contact-phone { font-size: 1.25rem; font-weight: 600; }
.contact-actions { margin-block-start: .5rem; display: flex; gap: .4rem; }

/* --- Login ------------------------------------------------------------------ */
.loginpage { display: grid; place-items: center; min-block-size: 100vh; }
.loginbox {
  inline-size: min(400px, 92vw);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 2rem;
}
.loginbox-head { text-align: center; margin-block-end: 1.25rem; }
.loginbox-head .brand-mark { margin: 0 auto .6rem; }
.loginbox-head h1 { font-size: 1.25rem; }
.loginbox .field { margin-block-end: .9rem; }

.errcode { font-size: 3rem; color: var(--text-muted); }

/* --- Footer ----------------------------------------------------------------- */
.footer {
  text-align: center; color: var(--text-muted);
  font-size: .85rem; padding: 1.5rem 1rem 2.5rem;
}

/* --- Small screens ---------------------------------------------------------- */
@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar-inner { gap: .6rem; }
  .mainnav { order: 3; inline-size: 100%; }
  .hero-value { font-size: 2.4rem; }

  /* Wide tables scroll inside their card rather than the page. */
  .card { overflow-x: auto; }
}

@media print {
  .topbar, .footer, .quickbar, .btn, .form-actions { display: none; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}
