:root {
  color-scheme: light;
  --bg: #f0f2f5;
  --card: #ffffff;
  --hover: #f2f2f2;
  --text: #050505;
  --muted: #65676b;
  --divider: #ced0d4;
  --btn: #e4e6eb;
  --btn-hover: #d8dadf;
  --blue: #1877f2;
  --blue-hover: #166fe5;
  --blue-soft: #e7f3ff;
  --green: #31a24c;
  --purple: #7b5cfa;
  --red: #f0402f;
  --danger: #d6291f;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 15px/1.35 "Segoe UI Historic", "Segoe UI", Helvetica, Arial, sans-serif;
}

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.topbar-in { max-width: 760px; margin: 0 auto; height: 56px; padding: 0 16px; display: flex; align-items: center; gap: 8px; }
.logo { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--blue); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 26px; }
.brand { flex: 1; min-width: 0; margin-left: 4px; font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.feed { max-width: 760px; margin: 0 auto; padding: 16px 12px 96px; }
.card { background: var(--card); border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.2); margin-bottom: 16px; }

/* profile card */
.profile { padding: 16px; }
h1 { margin: 0 0 12px; font-size: 24px; font-weight: 700; line-height: 1.2; }
.saldo { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 12px 14px; background: var(--blue-soft); border-radius: 8px; color: var(--muted); font-weight: 600; }
.saldo strong { color: var(--blue); font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* post cards */
.post { padding-bottom: 12px; }
.post-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
.post-head > div { min-width: 0; }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 17px; background: var(--blue); }
.avatar.green { background: var(--green); }
.avatar.purple { background: var(--purple); }
.avatar.red { background: var(--red); }
h2 { margin: 0; font-size: 17px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.sub, .summary { margin: 2px 0 0; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.bar { height: 8px; margin: 0 16px 12px; background: var(--btn); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--blue); border-radius: 4px; }

.table-wrap { overflow-x: auto; margin: 0 12px; border: 1px solid var(--divider); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--divider); vertical-align: middle; }
thead th { background: var(--bg); color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--hover); }
tfoot td { background: var(--bg); font-weight: 600; }
tr:last-child > td { border-bottom: 0; }
.no { width: 2.8em; text-align: center; color: var(--muted); }
.num { text-align: right; white-space: nowrap; }
.pic { min-width: 72px; }
.empty { text-align: center; color: var(--muted); padding: 18px; }

/* images */
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; }
.thumb { padding: 0; width: 48px; height: 48px; overflow: hidden; cursor: pointer; background: var(--bg);
  border: 1px solid var(--divider); border-radius: 8px; }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb:hover { border-color: var(--blue); }
.thumb-wrap { position: relative; display: inline-block; }
.thumb-wrap .x { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; padding: 0; line-height: 18px; text-align: center;
  border: 1px solid var(--divider); border-radius: 50%; background: var(--card); color: var(--text); font-size: 14px; cursor: pointer; }
.thumb-wrap .x:hover { background: var(--btn); }

.lightbox { width: min(94vw, 760px); padding: 12px; background: var(--card); color: var(--text); border: 0; border-radius: 8px; }
.lightbox::backdrop { background: rgba(0,0,0,.75); }
.lightbox img { display: block; max-width: 100%; max-height: 72vh; margin: 0 auto 12px; border-radius: 6px; }
.lb-bar { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
.lb-count { color: var(--muted); font-weight: 600; padding: 0 6px; }

/* buttons & fields */
.btn { display: inline-block; font-family: inherit; font-weight: 600; font-size: 15px; line-height: 1.2; padding: 8px 12px; cursor: pointer; text-decoration: none;
  color: var(--text); background: var(--btn); border: 0; border-radius: 6px; }
.btn:hover { background: var(--btn-hover); }
.btn.primary { color: #fff; background: var(--blue); }
.btn.primary:hover { background: var(--blue-hover); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
a, .link { color: var(--blue); }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=number], input[type=date], input[type=password] {
  display: block; width: 100%; margin-top: 4px; padding: 9px 12px; font-family: inherit; font-weight: 400; font-size: 15px;
  color: var(--text); background: var(--bg); border: 1px solid transparent; border-radius: 6px;
}
input:focus { outline: none; background: var(--card); border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-soft); }
.btn:focus-visible, a:focus-visible, .thumb:focus-visible, .x:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
td input { margin: 0; padding: 7px 10px; min-width: 7.5em; }
td input[type=number] { min-width: 8.5em; text-align: right; }

.note { color: var(--muted); text-align: center; padding: 24px 0; }
.error { color: var(--danger); margin: 0; }

/* admin */
.login { max-width: 380px; margin: 32px auto; padding: 20px; display: grid; gap: 10px; }
.login h1 { font-size: 20px; margin-bottom: 4px; }
.title-field { margin-bottom: 12px; }
.section-head { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; padding: 0 16px 12px; }
@media (max-width: 560px) { .section-head { grid-template-columns: 1fr; } }
.post-actions { padding: 12px 16px 0; }
.photo-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 120px; }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; }
.savebar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center; align-items: center; gap: 16px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--card); box-shadow: 0 -1px 2px rgba(0,0,0,.2); font-weight: 600; }
[hidden] { display: none !important; }
