/* Meisharim portal — flat, modern, Google Drive-inspired UI.
   Everything lives in this external sheet because the app's CSP forbids inline styles. */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-hover: #f0f4f9;
  --ink: #1f1f1f;
  --ink-2: #444746;
  --muted: #5f6368;
  --faint: #80868b;
  --accent: #0b57d0;
  --accent-soft: #e8f0fe;
  --border: #e1e3e6;
  --border-strong: #c4c7c5;
  --danger: #b3261e;
  --warn-bg: #fef7e0;
  --warn-border: #fde293;
  --warn-ink: #7c5800;

  /* Type accents */
  --c-folder: #5f6368;
  --c-image: #00897b;
  --c-pdf: #ea4335;
  --c-video: #d93025;
  --c-audio: #9334e6;
  --c-sheet: #188038;
  --c-slide: #e8710a;
  --c-doc: #1a73e8;
  --c-archive: #795548;
  --c-text: #3c4043;
  --c-file: #5f6368;

  --radius: 12px;
  --radius-lg: 16px;
  --shadow-1: 0 1px 2px rgba(60, 64, 67, 0.12), 0 1px 3px rgba(60, 64, 67, 0.08);
  --shadow-2: 0 1px 3px rgba(60, 64, 67, 0.16), 0 4px 8px rgba(60, 64, 67, 0.12);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 15px/1.55 "Google Sans", "Product Sans", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--surface-2);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ───────────────────────── App bar ───────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.2px;
  color: var(--ink-2);
  text-decoration: none;
}
.brand .logo {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #1a73e8, #0b57d0);
  color: #fff;
}
.brand .logo svg { width: 20px; height: 20px; fill: currentColor; }

.user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}
.user .who {
  color: var(--ink-2);
  font-size: 14px;
  max-width: 30vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  flex: none;
}
.user button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 999px;
}
.user button:hover { background: var(--surface-hover); color: var(--ink); }
.user form { margin: 0; display: inline-flex; }
.nav-admin {
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--accent);
  border: 1px solid var(--border);
}
.nav-admin:hover { background: var(--accent-soft); }

/* ───────────────────────── Layout ───────────────────────── */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 20px;
}

h1 {
  font-size: 24px;
  font-weight: 500;
  letter-spacing: -0.3px;
  margin: 0;
}

.muted { color: var(--muted); }
.error {
  color: var(--danger);
  background: #fce8e6;
  border: 1px solid #f5c2bd;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
}
.dev-note {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-ink);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13.5px;
}
.dev-note code { background: rgba(0, 0, 0, 0.06); padding: 1px 5px; border-radius: 5px; }

.empty {
  display: grid;
  place-items: center;
  gap: 14px;
  text-align: center;
  padding: 64px 24px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.empty .ic { width: 56px; height: 56px; opacity: 0.7; }
.empty p { margin: 0; }

/* ───────────────────────── Breadcrumb ───────────────────────── */
.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  font-size: 14px;
  margin-bottom: 16px;
}
.crumbs a,
.crumbs .here {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
}
.crumbs a:hover { background: var(--surface-hover); color: var(--ink); }
.crumbs .here { color: var(--ink); font-weight: 600; }
.crumbs .sep { color: var(--border-strong); margin: 0 1px; }

/* ───────────────────────── View toggle ───────────────────────── */
.view-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.view-toggle button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
}
.view-toggle button svg { width: 18px; height: 18px; fill: currentColor; }
.view-toggle button:hover { color: var(--ink); }
.view-toggle button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

/* ───────────────────────── Listing (grid + list) ───────────────────────── */
.listing { list-style: none; margin: 0; padding: 0; }

/* Grid view (default) */
.listing.view-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.view-grid .item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.view-grid .item:hover { background: var(--surface-hover); box-shadow: var(--shadow-1); }
.view-grid .item-meta { display: block; }

/* List view */
.listing.view-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.view-list .item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s ease;
}
.view-list .item:last-child { border-bottom: none; }
.view-list .item:hover { background: var(--surface-hover); }
.view-list .item-icon .ic { width: 24px; height: 24px; }
.view-list .item-meta { color: var(--faint); }

/* Stretched link makes the whole card/row clickable while keeping the
   download button independently clickable above it. */
.item-link {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  z-index: 1;
}
.item-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.item-icon { flex: none; display: grid; place-items: center; }
.item-icon .ic { width: 36px; height: 36px; }

/* Inline thumbnail for image files (served via the authed /preview route). */
.item-thumb {
  display: block;
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-hover);
}
.view-list .item-thumb { width: 28px; height: 28px; }

.item-body { min-width: 0; flex: 1; }
.item-name {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-meta {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-dl {
  position: relative;
  z-index: 2;
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--muted);
  text-decoration: none;
}
.item-dl svg { width: 18px; height: 18px; fill: currentColor; }
.item-dl:hover { background: rgba(11, 87, 208, 0.1); color: var(--accent); }

/* ───────────────────────── Type icon colors ───────────────────────── */
.ic { display: block; fill: currentColor; }
.ic path { fill: currentColor; }
.ic-folder { color: var(--c-folder); }
.ic-image { color: var(--c-image); }
.ic-pdf { color: var(--c-pdf); }
.ic-video { color: var(--c-video); }
.ic-audio { color: var(--c-audio); }
.ic-sheet { color: var(--c-sheet); }
.ic-slide { color: var(--c-slide); }
.ic-doc { color: var(--c-doc); }
.ic-archive { color: var(--c-archive); }
.ic-text { color: var(--c-text); }
.ic-file { color: var(--c-file); }

/* ───────────────────────── File detail ───────────────────────── */
.file-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
}
.file-head .item-icon .ic { width: 48px; height: 48px; }
.file-head .file-title { flex: 1; min-width: 0; }
.file-head h1 {
  font-size: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font-size: 12.5px;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 999px;
}

.preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.preview img { max-width: 100%; border-radius: 10px; display: block; margin: 0 auto; }
.frame { width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.frame.pdf { height: 78vh; }
.frame.doc { height: 60vh; }
.preview .none {
  display: grid;
  place-items: center;
  gap: 10px;
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}

/* ───────────────────────── Buttons / forms ───────────────────────── */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: box-shadow 0.12s ease, background 0.12s ease;
}
button:hover, .button:hover { background: #0a4ec0; box-shadow: var(--shadow-1); }
.button svg { width: 18px; height: 18px; fill: currentColor; }
.button.ghost { background: var(--surface); color: var(--accent); border: 1px solid var(--border-strong); }
.button.ghost:hover { background: var(--accent-soft); }

.actions { margin: 16px 0; }

/* ───────────────────────── Auth cards ───────────────────────── */
.auth-wrap {
  display: grid;
  place-items: center;
  padding: 6vh 16px;
}
.card.auth {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: 32px 30px;
}
.card.auth .auth-logo {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #1a73e8, #0b57d0);
  color: #fff;
  margin-bottom: 18px;
}
.card.auth .auth-logo svg { width: 28px; height: 28px; fill: currentColor; }
.card.auth h1 { font-size: 22px; margin-bottom: 6px; }
.card.auth > p { margin-top: 0; color: var(--muted); font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
}

.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.stack label { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: -8px; }
input {
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.stack button { margin-top: 4px; padding: 12px; font-size: 15px; }
.alt-link { margin-top: 18px; font-size: 14px; text-align: center; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ───────────────────────── Responsive ───────────────────────── */
@media (max-width: 600px) {
  .topbar { padding: 10px 16px; }
  .container { padding: 18px 16px 48px; }
  .user .who { display: none; }
  .listing.view-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  h1 { font-size: 21px; }
}

/* ───────────────────────── Admin ───────────────────────── */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 12px;
  padding: 12px 16px;
  margin: 0 0 20px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-1);
}
.banner svg { width: 18px; height: 18px; flex: none; fill: currentColor; }
.banner.ok    { background: #e6f4ea; border: 1px solid #b7dfc1; color: #12652b; }
.banner.error { background: #fce8e6; border: 1px solid #f3b7b2; color: var(--danger); }

.admin-section { padding: 22px 24px; margin-bottom: 18px; }

/* Section header: tinted icon tile + title (+ trailing count pill or action). */
.section-head { display: flex; align-items: center; gap: 14px; }
.section-ic {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  flex: none;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
}
.section-ic svg { width: 22px; height: 22px; fill: currentColor; }
.section-title { min-width: 0; }
.section-title h2 { margin: 0; font-size: 17px; font-weight: 500; }
.section-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.head-end { margin-inline-start: auto; flex: none; }
.count-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 3px 11px;
  border-radius: 999px;
  min-width: 26px;
  text-align: center;
}
.section-empty { margin: 16px 0 0; }

/* Rows (members / groups / admins) — Drive-listing feel. */
.admin-rows { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.admin-rows.compact { gap: 6px; }
.admin-row {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.admin-row:hover { box-shadow: var(--shadow-1); }
.admin-row details > summary { list-style: none; }
.admin-row summary::-webkit-details-marker { display: none; }
.row-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
}
details > .row-head:hover { background: var(--surface-hover); }
.admin-row.static .row-head { cursor: default; }
.row-badge {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  flex: none;
  border-radius: 10px;
  background: var(--surface-2);
}
.row-badge .ic { width: 22px; height: 22px; }
.avatar.admin { background: var(--warn-bg); color: var(--warn-ink); }
.row-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.row-name { font-size: 14.5px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 12.5px; color: var(--muted); }
.row-sub .phone { direction: ltr; }
.row-caret { flex: none; color: var(--faint); transition: transform 0.15s ease; }
.row-caret svg { width: 20px; height: 20px; fill: currentColor; display: block; }
details[open] .row-caret { transform: rotate(180deg); }

.badge.off {
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-ink);
}
.chip.lock { display: inline-flex; align-items: center; gap: 5px; }
.chip.lock svg { width: 14px; height: 14px; fill: currentColor; }

/* Expanded edit/create form. */
.row-body { padding: 4px 16px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }
.admin-form { display: grid; gap: 16px; padding-top: 16px; }
.field { display: grid; gap: 8px; }
.field-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.field-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.admin-form input[type="text"], .admin-form input[type="tel"] { width: 100%; font-size: 15px; }
.field .hint { font-size: 12.5px; }

/* Active toggle switch. */
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.switch input {
  appearance: none; -webkit-appearance: none;
  width: 40px; height: 23px; flex: none;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.15s ease;
}
.switch input::after {
  content: "";
  position: absolute; top: 2px; inset-inline-start: 2px;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-1);
  transition: inset-inline-start 0.15s ease;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { inset-inline-start: 19px; }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Toggle-chip pickers (groups / folders). */
.chipset { display: flex; flex-wrap: wrap; gap: 8px; }
.folderset { max-height: 216px; overflow: auto; padding: 3px; }
.chipbox {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13.5px;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.chipbox:hover { background: var(--surface-hover); }
.chipbox input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.chipbox .ic { width: 16px; height: 16px; flex: none; }
.chipbox-tick { width: 15px; height: 15px; fill: currentColor; opacity: 0; transform: scale(0.6); transition: opacity 0.12s ease, transform 0.12s ease; flex: none; }
.chipbox:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 500; }
.chipbox:has(input:checked) .ic { color: var(--accent); }
.chipbox:has(input:checked) .chipbox-tick { opacity: 1; transform: scale(1); }
.chipbox:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.picker-empty { font-size: 13px; }

/* Form action row: primary on the start, destructive pushed to the end. */
.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.form-actions .spacer { flex: 1; }
button.danger {
  background: var(--surface);
  color: var(--danger);
  border: 1px solid var(--border-strong);
  padding: 9px 18px;
}
button.danger:hover { background: #fce8e6; border-color: #f3b7b2; box-shadow: none; }

/* "Add member / add group" reveal. */
.add-card { margin-top: 16px; }
.add-card > summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  list-style: none;
}
.add-card > summary::-webkit-details-marker { display: none; }
.add-card > summary:hover { background: var(--accent-soft); border-color: var(--accent); }
.add-card > summary .add-plus { width: 18px; height: 18px; fill: currentColor; }
.add-card[open] > summary { margin-bottom: 16px; }
.add-card .admin-form {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  background: var(--surface-2);
  margin: 0;
}

@media (max-width: 600px) {
  .field-grid { grid-template-columns: 1fr; }
}
