:root {
  --table-row-color-bg: #EEDED5;
  --back-link-color-bg: #EEDED5;
  --hover-color-bg: #C0AA9F;
  --hover-color-text: #0d0d0d;
  --link-copied-color-bg: #D1F358;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f5f5f5;
  color: #1a1a1a;
  line-height: 1.5;
  min-height: 100dvh;
  padding: 0;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.08);
  overflow-y: auto;
}

.container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

h1 {
  font-size: clamp(1.375rem, 5vw, 1.75rem);
  font-weight: 600;
  margin-bottom: 1.25rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.refresh-inbox-status {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: #6b7280;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #d1d5db;
  border-top-color: #6b7280;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: bottom;
  margin-right: 4px;
}

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

.table-wrapper {
  margin: 0 0 1.5rem;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th.subject {
  width: 28%;
}

th.body {
  width: 49%;
}

th.date {
  width: 23%;
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: top;
}

tr:last-child td {
  border-bottom: none;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: var(--table-row-color-bg);
}

.date-col {
  color: #6b7280;
  text-align: right;
  vertical-align: top;
  white-space: nowrap;
}

.subject-col {
  font-weight: 500;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.links-col {
  vertical-align: top;
}

.links-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.links-list li {
  margin-bottom: 0.375rem;
}

.links-list li:last-child {
  margin-bottom: 0;
}

.resolved-link-wrapper {
  display: inline-block;
  font-size: 0.8125rem;
  color: #374151;
  word-break: break-all;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, opacity 0.5s;
  border-radius: 4px;
}

.resolved-link-wrapper:hover {
  font-weight: 400;
  color: var(--hover-color-text);
  background: var(--hover-color-bg);
  box-shadow: 0 0 0 6px var(--hover-color-bg);
}

.resolved-link {
  display: inline-block;
  vertical-align: middle;
  max-width: 350px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.resolved-link-wrapper.link-copied {
  background: var(--link-copied-color-bg);
  box-shadow: 0 0 0 6px var(--link-copied-color-bg);
}

.resolved-link-wrapper.link-copied:hover {
  background: var(--link-copied-color-bg);
  box-shadow: 0 0 0 6px var(--link-copied-color-bg);
}

.no-links {
  color: #9ca3af;
  font-size: 0.8125rem;
}

.read-email-link {
  font-size: 0.8125rem;
  text-decoration: none;
  color: #374151;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  vertical-align: middle;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, opacity 0.5s;
  border-radius: 4px;
}

.read-email-link:hover {
  font-weight: 400;
  color: var(--hover-color-text);
  background: var(--hover-color-bg);
  box-shadow: 0 0 0 6px var(--hover-color-bg);
}

.read-email-icon {
  width: 14px;
  height: 14px;
  display: inline-block;
  margin-left: 4px;
  vertical-align: middle;
}

.copy-icon {
  width: 14px;
  height: 14px;
  display: inline-block;
  margin-left: 4px;
  vertical-align: middle;
}

.unread-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2563eb;
  margin-right: 0.5rem;
  vertical-align: middle;
}

.hidden {
  display: none;
}

.archive-email-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: #9ca3af;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  vertical-align: middle;
  margin-left: 0.5rem;
}

.archive-email-btn:hover {
  font-weight: 400;
  color: var(--hover-color-text);
  background: var(--hover-color-bg);
}

.archive-email-mode .archive-email-btn {
  display: inline-block;
}

.unarchive-email-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #9ca3af;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  vertical-align: middle;
  margin-left: 0.5rem;
}

.unarchive-email-btn:hover {
  font-weight: 400;
  color: var(--hover-color-text);
  background: var(--hover-color-bg);
}

.delete-email-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #9ca3af;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  vertical-align: middle;
}

.delete-email-btn:hover {
  font-weight: 400;
  color: var(--hover-color-text);
  background: var(--hover-color-bg);
}

.delete-email-btn {
  display: none;
}

.delete-email-mode .delete-email-btn {
  display: inline-block;
}

.link-copied-message {
  font-size: 0.8125rem;
  font-weight: 700;
  color: #6f9400;
  margin-left: 0.75rem;
  vertical-align: middle;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #9ca3af;
}

.email-detail {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  padding: 2rem;
}

.email-detail-header {
  margin-bottom: 2rem;
}

.back-link {
  min-height: 44px;
  color: #6b7280;
  text-decoration: none;
  font-size: 0.875rem;
  display: inline-flex;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e5e7eb;
  border-radius: 9999px;
  background: #fff;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.back-link:hover {
  font-weight: 400;
  color: var(--hover-color-text);
  background: var(--back-link-color-bg);
  border-color: transparent;
}

.email-detail-header h1 {
  margin-bottom: 0.125rem;
}

.email-date {
  color: #6b7280;
  font-size: 0.875rem;
}

.email-body-section,
.email-links-section {
  margin-bottom: 2rem;
}

.email-body-section h2,
.email-links-section h2 {
  font-size: 1rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e5e7eb;
}

.email-body {
  background: #f9fafb;
  border-radius: 6px;
  padding: 1rem;
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.email-html-body {
  width: 100%;
  min-height: 400px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
  display: block;
}

.former-link {
  text-decoration: underline;
  color: #6b7280;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  transition: opacity 0.3s ease-out;
}

.flash-fade-out {
  opacity: 0;
}

.flash-notice {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.flash-alert {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.empty-state-text {
  text-align: center;
  color: #6b7280;
  padding: 2rem 1rem;
  font-size: 0.875rem;
}

.month-year-header {
  font-weight: 600;
  font-size: 1.5rem;
  color: #9ca3af;
  padding: 0.25rem 1rem 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 .5rem;
}

.year-header {
  font-weight: 600;
  font-size: 2.25rem;
  color: #7d8590;
  padding: .25rem 0 0;
  margin: 0 0 .5rem;
}

.kbd-help {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
}

.kbd-help-button {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #6b7280;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.kbd-help-button:hover {
  font-weight: 400;
  color: var(--hover-color-text);
  background: var(--hover-color-bg);
}

.kbd-help-popup {
  position: absolute;
  bottom: 3rem;
  right: 0;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  padding: 1rem 1.25rem;
  min-width: 220px;
  font-size: 0.875rem;
}

.kbd-help-popup h3 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9ca3af;
  margin-bottom: 0.75rem;
}

.kbd-help-popup ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.kbd-help-popup li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0;
  color: #374151;
}

.kbd-help-popup li + li {
  border-top: 1px solid #f3f4f6;
}

.kbd-help-popup kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.375rem;
  font-size: 0.75rem;
  background: #f9fafb;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  color: #6b7280;
  flex-shrink: 0;
}

@media (min-width: 769px) {
  .container {
    padding: 1.5rem 1.5rem 2.5rem;
  }

  .date-col {
    vertical-align: top;
  }

  .date-col div {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
  }

  .date-col .row-date {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .date-col .archive-email-btn,
  .date-col .unarchive-email-btn {
    flex-shrink: 0;
    margin-left: 0;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 1rem 1rem max(2rem, calc(1.5rem + env(safe-area-inset-bottom)));
  }

  .month-year-header {
    font-size: 1.5rem;
    padding: 0.5rem 0.25rem 0;
    margin-bottom: 0.5rem;
  }

  .year-header {
    font-size: 1.5rem;
    padding: 0.25rem 0.25rem 0;
  }

  .table-wrapper {
    margin-bottom: 1rem;
    overflow: visible;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
  }

  .table-wrapper table,
  .table-wrapper tbody,
  .table-wrapper tr,
  .table-wrapper td {
    display: block;
    width: 100%;
  }

  .table-wrapper thead {
    display: none;
  }

  .table-wrapper tbody {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .table-wrapper .clickable-row {
    min-width: 0;
    overflow: hidden;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  }

  .table-wrapper .clickable-row:hover td {
    background: transparent;
  }

  .table-wrapper .clickable-row:active td {
    background: #f3f4f6;
  }

  .table-wrapper td {
    min-width: 0;
    padding: 0;
    border-bottom: 0;
  }

  .table-wrapper td.subject-col {
    padding: 1rem 1rem 0.5rem;
    font-size: 1rem;
    line-height: 1.4;
  }

  .table-wrapper td.links-col {
    padding: 0 1rem 0.25rem;
  }

  .table-wrapper td.date-col {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.125rem 1rem 0.5rem;
    border-top: 1px solid #f3f4f6;
    font-size: 0.8125rem;
    text-align: left;
    white-space: normal;
  }

  .row-date {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .table-wrapper .empty-state {
    overflow: hidden;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  }

  .table-wrapper .empty-state-text {
    padding: 2.5rem 1rem;
  }

  .links-list,
  .links-list li {
    width: 100%;
  }

  .links-list li {
    margin-bottom: 0.5rem;
  }

  .links-list li:last-child {
    margin-bottom: 0;
  }

  .resolved-link-wrapper,
  .read-email-link {
    width: 100%;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    color: #374151;
    background: var(--table-row-color-bg);
    border-radius: 4px;
    border-color: var(--table-row-color-bg) !important;
    border: 0 !important;
    box-shadow: none;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
    touch-action: manipulation;
  }

  .resolved-link-wrapper {
    max-width: 100%;
    cursor: pointer;
    overflow-wrap: anywhere;
  }

  .resolved-link-wrapper:hover,
  .read-email-link:hover {
    border: 0 !important;
    font-weight: 400;
    color: var(--hover-color-text);
    background: var(--hover-color-bg);
    box-shadow: 0 0 0 6px var(--hover-color-bg);
  }

  .resolved-link-wrapper.link-copied {
    background: var(--link-copied-color-bg);
    border-color: var(--link-copied-color-bg);
  }

  .resolved-link {
    min-width: 0;
    max-width: 100%;
    flex: 1 1 auto;
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: normal;
    text-overflow: ellipsis;
  }

  .copy-icon,
  .read-email-icon {
    width: 16px;
    height: 16px;
    margin-left: 0;
    flex-shrink: 0;
  }

  .link-copied-message {
    width: 100%;
    display: flex;
    margin: 0.5rem 0 0;
    font-size: 0.75rem;
  }

  .link-copied-message.hidden {
    display: none;
  }

  .archive-email-btn,
  .archive-email-mode .archive-email-btn {
    display: none;
  }

  .unarchive-email-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0.5rem;
    margin-left: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 9999px;
    color: #6b7280;
    touch-action: manipulation;
  }

  .unarchive-email-btn:hover {
    color: #111827;
    background: #f3f4f6;
  }

  .delete-email-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0.5rem;
    margin-left: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 9999px;
    color: #dc2626;
    touch-action: manipulation;
  }

  .delete-email-mode .delete-email-btn {
    display: inline-flex;
  }

  .delete-email-btn:hover {
    background: #fef2f2;
  }

  .email-detail {
    padding: 1rem;
    border-radius: 12px;
  }

  .email-detail-header {
    margin-bottom: 1.5rem;
  }

  .email-detail-header h1 {
    margin-bottom: 0.25rem;
    font-size: clamp(1.25rem, 6vw, 1.75rem);
  }

  .email-body-section,
  .email-links-section {
    margin-bottom: 1.5rem;
  }

  .email-body-section h2,
  .email-links-section h2 {
    margin-bottom: 0.75rem;
    font-size: 0.75rem;
  }

  .email-body {
    padding: 0.875rem;
    font-size: 0.9375rem;
  }

  .email-html-body {
    height: 60vh;
    min-height: 320px;
    max-height: 700px;
  }

  .back-link {
    width: fit-content;
  }

  .flash,
  .no-links {
    overflow-wrap: anywhere;
  }

  .kbd-help {
    display: none;
  }
}

@media (min-width: 769px) and (pointer: coarse) {
  .archive-email-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    margin-left: 0.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 9999px;
    background: #fff;
    touch-action: manipulation;
  }
}

@media (pointer: coarse) {
  .resolved-link-wrapper {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    touch-action: manipulation;
  }

  .read-email-link {
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    touch-action: manipulation;
  }

  .unarchive-email-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    touch-action: manipulation;
  }

  .archive-email-btn {
    display: none;
  }

  .back-link {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
  }

  .kbd-help {
    display: none;
  }

  .clickable-row:hover td,
  .resolved-link-wrapper:hover,
  .read-email-link:hover,
  .unarchive-email-btn:hover,
  .back-link:hover,
  .kbd-help-button:hover {
    background: inherit;
    color: inherit;
    box-shadow: none;
    border-color: inherit;
  }

  .clickable-row:active td,
  .resolved-link-wrapper:active,
  .read-email-link:active,
  .unarchive-email-btn:active,
  .back-link:active {
    background: #f3f4f6;
    color: #111827;
  }

  .resolved-link-wrapper.link-copied:active {
    background: var(--link-copied-color-bg);
    color: inherit;
  }
}
