:root {
  --app-bg: #f1f3f2;
  --app-surface: #ffffff;
  --app-ink: #202823;
  --app-muted: #66736c;
  --app-primary: #0f6a56;
  --app-primary-dark: #0b5444;
  --app-primary-soft: #d8efe8;
  --app-star: #d39b22;
  --app-header-height: 64px;
  --app-bottom-bar-height: 72px;
  --bs-primary: var(--app-primary);
  --bs-primary-rgb: 15, 106, 86;
  --bs-primary-bg-subtle: var(--app-primary-soft);
  --bs-body-color: var(--app-ink);
  --bs-body-font-family: "Inter", "Segoe UI", sans-serif;
}

html,
body {
  min-height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--app-bg);
  color: var(--app-ink);
  font-family: var(--bs-body-font-family);
  font-size: 18px;
  line-height: 1.5;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
}

.has-nav-footer,
.has-message-footer {
  overflow: hidden;
}

.has-nav-footer .app-shell,
.has-message-footer .app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  row-gap: 0.75rem;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.app-container {
  width: 100%;
  max-width: 720px;
  margin-right: auto;
  margin-left: auto;
}

.app-header {
  z-index: 1020;
  width: 100%;
  min-height: calc(var(--app-header-height) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  border-bottom: 1px solid #d9dfdc;
  background: var(--app-surface);
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--app-header-height);
}

.app-header-title {
  overflow: hidden;
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-header-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
}

.app-header-menu {
  display: inline-flex;
  flex: 0 0 48px;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--app-muted);
  font-size: 1.35rem;
  text-decoration: none;
}

.app-header-menu:focus-visible {
  outline: 2px solid var(--bs-primary);
  outline-offset: 2px;
}

.app-header-refresh-form {
  display: flex;
  margin: 0;
}

.app-header-refresh-label {
  display: none;
  margin-left: 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.app-header-refresh.is-loading {
  width: auto;
  padding: 0 0.65rem;
}

.app-header-refresh.is-loading i {
  animation: app-refresh-spin 0.8s linear infinite;
}

.app-header-refresh.is-loading .app-header-refresh-label {
  display: inline;
}

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

@media (prefers-reduced-motion: reduce) {
  .app-header-refresh.is-loading i {
    animation: none;
  }
}

.app-header .dropdown-menu {
  min-width: 12rem;
  margin-top: 0.25rem;
  border-color: #d9dfdc;
}

.app-main {
  min-width: 0;
}

.has-nav-footer .app-main,
.has-message-footer .app-main {
  min-height: 0;
  padding: 0 0.5rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

.app-panel {
  min-height: 100%;
}

.btn,
a,
button {
  touch-action: manipulation;
}

.btn {
  min-height: 44px;
  font-weight: 600;
}

.btn-primary {
  --bs-btn-bg: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: var(--app-primary-dark);
  --bs-btn-hover-border-color: var(--app-primary-dark);
  --bs-btn-active-bg: var(--app-primary-dark);
  --bs-btn-active-border-color: var(--app-primary-dark);
}

.form-control:focus {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 0.25rem rgba(15, 106, 86, 0.18);
}

.min-width-0 {
  min-width: 0;
}

.mail-list {
  gap: 0.65rem;
}

.mail-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(32, 40, 35, 0.1);
  border-radius: 0.75rem;
  background: var(--app-surface);
  box-shadow: 0 0.15rem 0.5rem rgba(32, 40, 35, 0.06);
}

.mail-card.is-unread {
  border-left: 4px solid var(--app-primary);
  background: #f4fbf8;
}

.mail-card-top {
  display: grid;
  grid-template-columns: 44px 32px 32px minmax(0, 1fr);
  align-items: center;
  min-width: 0;
  min-height: 44px;
  margin: 0 0.75rem;
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(32, 40, 35, 0.1);
}

.mail-item {
  display: block;
  min-width: 0;
  padding: 0.55rem 0.9rem 0.85rem;
}

.mail-item:hover,
.mail-item:focus-visible {
  background: var(--app-primary-soft);
  outline: none;
}

.mail-from,
.mail-subject {
  display: block;
  font-size: 0.875rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.mail-from {
  font-weight: 600;
}

.mail-subject {
  margin-top: 0.25rem;
}

.mail-card.is-unread .mail-from,
.mail-card.is-unread .mail-subject {
  font-weight: 700;
}

.mail-date {
  min-width: 0;
  justify-self: end;
  font-size: clamp(0.68rem, 2.8vw, 0.78rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: right;
  white-space: nowrap;
}

.mail-read-status,
.mail-attachment {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--app-muted);
  font-size: 1rem;
}

.mail-card.is-unread .mail-read-status {
  color: var(--app-primary);
}

.mail-attachment.is-hidden {
  visibility: hidden;
}

.star-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  color: #a9b0ac;
  font-size: 1.3rem;
}

.star-btn:hover,
.star-btn:focus-visible {
  color: var(--app-star);
  background: #fff7df;
}

.star-btn.is-starred,
.bottom-bar-item.is-starred {
  color: var(--app-star);
}

.message-subject,
.message-body {
  overflow-wrap: anywhere;
}

.message-body {
  white-space: pre-wrap;
  font-size: 1.02rem;
  line-height: 1.65;
}

.message-meta dt {
  font-weight: 600;
}

.attachments .btn {
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: normal;
}

.bottom-bar {
  z-index: 1030;
  width: 100%;
  min-height: calc(var(--app-bottom-bar-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  border-top: 1px solid #d9dfdc;
  background: var(--app-surface);
}

.bottom-bar-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  min-height: var(--app-bottom-bar-height);
}

.bottom-bar-form {
  display: contents;
}

.bottom-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  min-width: 0;
  min-height: var(--app-bottom-bar-height);
  padding: 0.45rem 0.2rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--app-muted);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
}

.bottom-bar-item:hover,
.bottom-bar-item:focus-visible {
  background: transparent;
  color: var(--app-primary);
  outline: none;
}

.bottom-bar-item.active {
  color: var(--app-primary);
}

.bottom-bar-item:disabled {
  opacity: 0.4;
}

.bottom-bar-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.bottom-bar-label {
  overflow: hidden;
  max-width: 100%;
  font-size: 0.7rem;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-icon,
.contact-icon,
.auth-icon {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
}

.profile-icon,
.contact-icon {
  width: 48px;
  height: 48px;
}

.auth-wrapper {
  display: flex;
  align-items: center;
  min-height: 100vh;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
}

.auth-icon {
  width: 64px;
  height: 64px;
  font-size: 1.6rem;
}

.empty-state-icon {
  font-size: 3rem;
  opacity: 0.35;
}

@media (min-width: 576px) {
  .app-panel {
    min-height: auto;
    border: 1px solid rgba(32, 40, 35, 0.08);
    border-radius: 1rem;
    box-shadow: 0 0.5rem 1.5rem rgba(32, 40, 35, 0.07);
  }

  .bottom-bar-label {
    font-size: 0.76rem;
  }
}
