:root {
  color-scheme: light;
  --ink: #0b0f14;
  --ink-soft: #26313a;
  --orange: #d53a01;
  --orange-dark: #a92e00;
  --orange-soft: #fff0ea;
  --surface: #f4f7f9;
  --card: #ffffff;
  --line: #dfe6eb;
  --muted: #667b8c;
  --danger: #a41d20;
  --success: #16713a;
  --shadow: 0 12px 36px rgba(11, 15, 20, .08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--surface);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.48;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: var(--orange-dark); }
img { max-width: 100%; }
[hidden] { display: none !important; }

.splash {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1rem;
  background: var(--surface);
}

.splash img, .brand-icon {
  border-radius: 22%;
  box-shadow: 0 18px 40px rgba(213, 58, 1, .18);
}

.splash p { margin: 0; color: var(--muted); }

.spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid #d8e0e6;
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.login-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(1.5rem + var(--safe-top)) 1.25rem calc(1.5rem + var(--safe-bottom));
}

.login-card {
  width: min(100%, 28rem);
  padding: 2rem;
  border-radius: 1.5rem;
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card h1 { margin: 1.35rem 0 .25rem; font-size: 2rem; }
.login-card > p { margin-top: 0; }

form label {
  display: block;
  margin: 1rem 0;
  text-align: left;
  font-weight: 700;
}

form label > span { display: block; margin-bottom: .4rem; }

input, textarea {
  width: 100%;
  border: 1px solid #cdd7de;
  border-radius: .9rem;
  padding: .85rem .95rem;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(213, 58, 1, .13);
}

textarea { min-height: 6.5rem; resize: vertical; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 2.85rem;
  padding: .7rem 1rem;
  border: 1px solid transparent;
  border-radius: .9rem;
  font-weight: 800;
  text-decoration: none;
}

.button.primary { background: var(--ink); color: #fff; }
.button.primary:hover { background: #242b31; }
.button.secondary { border-color: #cbd5dc; background: #fff; color: var(--ink); }
.button.danger { background: var(--danger); color: #fff; }
.button.small { min-height: 2.35rem; padding: .5rem .75rem; font-size: .85rem; }
.button.wide { width: 100%; }
.button[disabled] { opacity: .58; cursor: progress; }

.text-button {
  border: 0;
  background: transparent;
  color: var(--orange-dark);
  font-weight: 800;
  padding: .65rem;
}

.install-help { margin-top: 1rem; }
.security-note { color: var(--muted); font-size: .78rem; margin: 1rem 0 0 !important; }
.muted { color: var(--muted); }
.small-text { font-size: .82rem; }
.form-error { color: var(--danger); font-weight: 700; text-align: left; }

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(5.2rem + var(--safe-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .75rem;
  min-height: calc(4.4rem + var(--safe-top));
  padding: calc(.7rem + var(--safe-top)) 1rem .7rem;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid rgba(207, 217, 224, .85);
  backdrop-filter: blur(14px);
}

.app-header img { border-radius: .7rem; }
.app-header h1 { margin: 0; font-size: 1.25rem; line-height: 1.15; }
.eyebrow { display: block; color: var(--orange-dark); font-size: .7rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.55rem;
  height: 2.55rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 1.5rem;
}

.icon-button:hover { background: #edf2f5; }
.header-action { font-size: 1.7rem; }

.content {
  width: min(100%, 66rem);
  min-height: calc(100vh - 10rem);
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  outline: none;
}

.bottom-nav {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  min-height: calc(4.6rem + var(--safe-bottom));
  padding: .35rem .4rem var(--safe-bottom);
  background: rgba(255, 255, 255, .97);
  border-top: 1px solid #d9e1e6;
  backdrop-filter: blur(16px);
}

.bottom-nav button {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: .1rem;
  border: 0;
  border-radius: .85rem;
  background: transparent;
  color: #667684;
  font-size: .72rem;
  font-weight: 800;
}

.bottom-nav button[aria-current="page"] { background: var(--orange-soft); color: var(--orange-dark); }
.nav-icon { font-size: 1.4rem; line-height: 1; }

.card {
  margin-bottom: .9rem;
  padding: 1rem;
  border: 1px solid rgba(218, 226, 232, .88);
  border-radius: 1.2rem;
  background: var(--card);
  box-shadow: 0 7px 22px rgba(11, 15, 20, .045);
}

.hero-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.15rem;
  padding: 1.3rem;
  border-radius: 1.35rem;
  background: linear-gradient(135deg, #0b0f14, #48291e);
  color: #fff;
}

.hero-card p, .hero-card h2 { margin: 0; }
.hero-card p { color: #f8d9cc; font-size: .85rem; }
.hero-card h2 { margin-top: .2rem; font-size: 1.28rem; }
.avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 3.35rem;
  height: 3.35rem;
  overflow: hidden;
  border-radius: 50%;
  background: var(--orange);
  color: #fff;
  font-size: 1.25rem;
  font-weight: 900;
}
.avatar.large { width: 5.2rem; height: 5.2rem; font-size: 1.8rem; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.section-card details > summary {
  display: flex;
  align-items: center;
  gap: .7rem;
  cursor: pointer;
  list-style: none;
  font-weight: 850;
}
.section-card summary::-webkit-details-marker { display: none; }
.section-card summary::before { content: "✓"; display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; background: var(--orange-soft); color: var(--orange-dark); }
.section-fields { margin-top: 1rem; padding-top: .85rem; border-top: 1px solid var(--line); }
.field + .field { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.field h3 { margin: 0 0 .4rem; font-size: 1rem; }
.rich-text { overflow-wrap: anywhere; }
.rich-text img { height: auto; border-radius: .6rem; }
.rich-text p:first-child { margin-top: 0; }
.rich-text p:last-child { margin-bottom: 0; }

.composer { position: sticky; top: calc(4.4rem + var(--safe-top)); z-index: 10; margin: -.25rem -.25rem 1rem; padding: .25rem; background: var(--surface); }
.composer textarea { min-height: 4.6rem; }
.composer-actions { display: flex; justify-content: flex-end; margin-top: .55rem; }

.message-card { padding: 1rem; }
.message-head { display: grid; grid-template-columns: auto 1fr auto; gap: .7rem; align-items: start; }
.message-author { font-weight: 850; }
.message-date { color: var(--muted); font-size: .74rem; }
.message-body { margin-top: .8rem; }
.message-actions { display: flex; gap: .35rem; }
.message-actions button { border: 0; border-radius: .7rem; background: #eef3f6; padding: .5rem .65rem; font-weight: 750; }
.message-actions .delete { color: var(--danger); }
.reply { margin: .75rem 0 0 1.1rem; padding: .8rem; border-radius: .9rem; background: #f0f5f7; }
.source-label { display: inline-block; margin-top: .2rem; color: var(--orange-dark); font-size: .7rem; font-weight: 800; }

.empty-state, .error-state, .loading-state {
  display: grid;
  place-items: center;
  gap: .75rem;
  min-height: 18rem;
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}
.empty-symbol { font-size: 3rem; }
.loading-state .spinner { width: 2.6rem; height: 2.6rem; }

.file-upload { margin-bottom: 1rem; }
.file-upload input[type="file"] { padding: .65rem; }
.file-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .8rem; }
.file-icon { display: grid; place-items: center; width: 2.7rem; height: 2.7rem; border-radius: 50%; background: var(--orange-soft); color: var(--orange-dark); font-size: 1.25rem; }
.file-name { min-width: 0; font-weight: 800; overflow-wrap: anywhere; }
.file-meta { color: var(--muted); font-size: .78rem; }

.profile-card { display: grid; justify-items: center; text-align: center; }
.profile-card h2 { margin: .75rem 0 .15rem; }
.profile-card p { margin: .1rem 0; color: var(--muted); }
.menu-card { padding: 0; overflow: hidden; }
.menu-heading { padding: 1rem 1rem .65rem; color: var(--ink-soft); font-size: .8rem; font-weight: 900; text-transform: uppercase; letter-spacing: .05em; }
.menu-row { display: flex; align-items: center; gap: .75rem; width: 100%; padding: 1rem; border: 0; border-bottom: 1px solid var(--line); background: #fff; color: var(--ink); text-align: left; text-decoration: none; }
.menu-row:last-child { border-bottom: 0; }
.menu-row strong { flex: 1; }
.credits-row { background: #fff8f5; }
.credit-balance { min-width: 2.5rem; padding: .35rem .7rem; border-radius: 999px; background: var(--orange-soft); color: var(--orange-dark); font-size: 1rem; font-weight: 950; text-align: center; }

.password-panel { margin-top: 1rem; }
.password-panel h2 { margin-top: 0; }
.password-grid { display: grid; gap: .8rem; }

.admin-count { margin-left: auto; padding: .3rem .65rem; border-radius: 999px; background: var(--orange); color: #fff; font-size: .75rem; font-weight: 900; }
.status-pill { display: inline-block; padding: .25rem .6rem; border-radius: 999px; background: #ffe8df; color: var(--orange-dark); font-size: .7rem; font-weight: 900; }
.status-pill.active { background: #e3f6ea; color: var(--success); }
.admin-client-card { cursor: pointer; }
.admin-client-card:hover { border-color: #e4ae98; }
.client-meta { display: flex; align-items: center; gap: .75rem; }
.client-meta > div:nth-child(2) { flex: 1; min-width: 0; }
.client-meta h3 { margin: 0; }
.client-meta p { margin: .1rem 0; color: var(--muted); font-size: .8rem; }
.selected-comment { border-color: #efb59f; background: #fff5f0; }
.back-button { display: inline-flex; align-items: center; gap: .35rem; margin-bottom: .85rem; border: 0; background: transparent; color: var(--orange-dark); font-weight: 850; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; }
.client-credit-row { display: flex; align-items: center; gap: .75rem; margin-top: 1rem; padding: .75rem; border-radius: 14px; background: #fff8f5; }
.usage-row { display: grid; grid-template-columns: 9rem 1fr; gap: .6rem; margin-top: .5rem; font-size: .85rem; }
.usage-row strong { color: var(--ink-soft); }

.install-banner {
  position: fixed;
  z-index: 60;
  top: calc(.7rem + var(--safe-top));
  left: .7rem;
  right: .7rem;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: .6rem;
  max-width: 46rem;
  margin: 0 auto;
  padding: .8rem;
  border: 1px solid #2f3a43;
  border-radius: 1rem;
  background: #111820;
  color: #fff;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .24);
}
.install-banner strong, .install-banner span { display: block; }
.install-banner span { margin-top: .12rem; color: #d7e0e7; font-size: .78rem; }
.install-banner .icon-button:hover { background: rgba(255, 255, 255, .12); }

dialog {
  max-width: none;
  max-height: none;
  border: 0;
  padding: 0;
  background: transparent;
}
dialog::backdrop { background: rgba(7, 10, 13, .65); backdrop-filter: blur(4px); }
.install-dialog { width: min(calc(100% - 2rem), 30rem); }
.dialog-card { position: relative; margin: 0; padding: 1.6rem; border-radius: 1.4rem; background: #fff; text-align: center; box-shadow: 0 24px 70px rgba(0, 0, 0, .28); }
.dialog-card img { border-radius: 1rem; }
.dialog-card h2 { margin: .85rem 0; }
.dialog-close { position: absolute; top: .6rem; right: .6rem; width: 2.5rem; height: 2.5rem; border: 0; border-radius: 50%; background: #edf2f5; font-size: 1.5rem; }
.install-steps { padding-left: 1.4rem; text-align: left; }
.install-steps li { margin-bottom: .75rem; }
.dialog-card .button + .button { margin-top: .6rem; }

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(5.4rem + var(--safe-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 2rem);
  padding: .8rem 1rem;
  border-radius: .8rem;
  background: #17212a;
  color: #fff;
  box-shadow: var(--shadow);
  text-align: center;
  font-weight: 700;
}
.toast.error { background: var(--danger); }

@media (min-width: 760px) {
  .content { padding: 1.5rem 1.5rem 3rem; }
  .bottom-nav { left: 50%; right: auto; width: min(100%, 42rem); transform: translateX(-50%); border: 1px solid #d9e1e6; border-bottom: 0; border-radius: 1.25rem 1.25rem 0 0; }
  .dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
  .dashboard-grid .card { margin: 0; }
  .files-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
  .files-grid .card { margin: 0; }
}

@media (max-width: 430px) {
  .login-card { padding: 1.45rem; }
  .content { padding-left: .75rem; padding-right: .75rem; }
  .install-banner { grid-template-columns: 1fr auto; }
  .install-banner .icon-button { grid-column: 2; grid-row: 1; }
  .install-banner .button { grid-column: 1 / -1; }
  .usage-row { grid-template-columns: 1fr; gap: .05rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
