:root {
  --brand: #2FA044;
  --brand-dark: #1E6E3A;
  --brand-soft: #E6F4EA;
  --background: #F5F8F6;
  --card: #FFFFFF;
  --text: #1D2B22;
  --muted: #6B7A70;
  --border: #E3EBE5;
  --error: #C0392B;
  --on-brand: #FFFFFF;
  --radius: 12px;
  --field: 44px;
  --topbar: 56px;
  --menu: 260px;
  --footer: 60px;
}

* { box-sizing: border-box; }

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

[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; min-height: 100%; }
#login, #shell { flex: 1 0 auto; }

button, input { font: inherit; color: inherit; }

.btn {
  display: block; width: 100%; min-height: var(--field); padding: 0 16px;
  border: 0; border-radius: var(--radius);
  background: var(--brand); color: var(--on-brand); font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-plain { background: transparent; color: var(--brand-dark); }
.btn-outline { background: var(--card); color: var(--text); border: 1px solid var(--border); text-align: left; }
.btn-outline.is-active { border-color: var(--brand); color: var(--brand-dark); }
.btn-inline { display: inline-block; width: auto; min-height: 32px; padding: 0 8px; }

.field {
  display: block; width: 100%; height: var(--field); padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--card);
}
.field:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

.label { display: block; margin: 16px 0 6px; color: var(--muted); font-size: 14px; }
.message { min-height: 22px; margin: 12px 0; color: var(--error); font-size: 14px; }
.message:empty { min-height: 0; margin: 0; }
.muted, .message.muted { color: var(--muted); }
.small { font-size: 13px; }

.brand-mark {
  width: 48px; height: 48px; border-radius: 14px;
  background: var(--brand); color: var(--on-brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 20px;
}
.brand-small { width: 32px; height: 32px; border-radius: 9px; font-size: 14px; }

/* Sign-in: a centred card. */
#login { display: flex; align-items: center; justify-content: center; padding: 48px 16px 16px; }
.login-card {
  width: 100%; max-width: 400px; padding: 32px;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
}
#login h1 { margin: 20px 0 6px; font-size: 24px; }
#login .btn { margin-top: 20px; }
#login-code { letter-spacing: 6px; font-size: 20px; text-align: center; }

/* Shell: top bar, menu on the left, content. */
#shell { display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar); padding: 0 16px;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.topbar-menu {
  display: none; width: 40px; height: 40px; border: 0; border-radius: 8px;
  background: transparent; font-size: 20px; cursor: pointer;
}
.topbar-name { font-weight: 700; }
.topbar-company {
  margin-left: auto; min-width: 0; max-width: 40%; height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 18px; background: var(--card);
  font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-company:not(:disabled) { cursor: pointer; }
.topbar-account {
  flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; cursor: pointer;
}

.frame { flex: 1; display: flex; min-height: 0; }
.menu {
  flex: none; width: var(--menu); padding: 12px 8px 24px;
  background: var(--card); border-right: 1px solid var(--border);
  overflow-y: auto; position: sticky; top: var(--topbar);
  height: calc(100vh - var(--topbar) - var(--footer));
}
.menu-loading { padding: 8px 12px; }
.menu-section-head {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; margin-top: 8px; padding: 8px 12px;
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
}
.menu-section-head::after { content: "\25BE"; }
.menu-section-head[aria-expanded="false"]::after { content: "\25B8"; }
.menu-group { margin: 10px 12px 4px; color: var(--muted); font-size: 13px; font-weight: 600; }
.menu-item {
  display: block; width: 100%; padding: 7px 12px 7px 20px;
  border: 0; border-radius: 8px; background: transparent;
  text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--background); }
.menu-item.is-active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.menu-item:focus-visible, .menu-section-head:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.menu-scrim { position: fixed; inset: var(--topbar) 0 0 0; z-index: 3; background: rgba(29, 43, 34, 0.35); }

.content { flex: 1; min-width: 0; padding: 24px 32px; }
.page-title { margin: 4px 0 16px; font-size: 22px; }
.card { padding: 16px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.card p { margin: 0; }
.perm-line {
  display: flex; align-items: center; gap: 8px; margin: 0 0 16px; padding: 10px 14px;
  border: 1px solid #F0D58A; border-radius: var(--radius); background: #FFF8E1; color: #6B4E00; font-size: 14px;
}

/* Below 900 px the menu is a drawer over the content. */
@media (max-width: 899px) {
  .topbar-menu { display: block; }
  .topbar-name { display: none; }
  .topbar-company { max-width: 55%; }
  .menu {
    position: fixed; top: var(--topbar); left: 0; bottom: 0; z-index: 4; height: auto;
    transform: translateX(-100%); visibility: hidden;
    transition: transform 0.15s ease, visibility 0s linear 0.15s;
  }
  #shell.menu-open .menu { transform: none; visibility: visible; transition-delay: 0s; }
  .content { padding: 16px; }
}

@media (min-width: 900px) { .menu-scrim { display: none !important; } }

/* Language flags */
.lang-footer { height: var(--footer); display: flex; justify-content: center; gap: 8px; padding: 8px 16px 16px; }
.lang-flag {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 36px; padding: 0;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; opacity: 0.55; cursor: pointer;
}
.lang-flag:hover { opacity: 0.85; }
.lang-flag[aria-pressed="true"] { opacity: 1; border-color: var(--border); background: var(--card); }
.lang-flag:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.flag { display: block; width: 24px; height: 17px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08); }

/* Sheet (Pwa.Sheet.View): a centred dialog on a wide screen, a bottom sheet on a narrow one. */
#sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(29, 43, 34, 0.45); }
.sheet-card {
  position: absolute; left: 50%; top: 20%; transform: translateX(-50%);
  width: calc(100% - 32px); max-width: 420px; max-height: 70%; overflow-y: auto;
  padding: 20px; background: var(--card); border-radius: 16px;
}
.sheet-card h3 { margin: 0 0 12px; font-size: 18px; }
.sheet-card .btn { margin-top: 10px; }
@media (max-width: 599px) {
  .sheet-card {
    left: 0; right: 0; top: auto; bottom: 0; transform: none; width: auto; max-width: none;
    border-radius: 16px 16px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}
