/* Box sizing rules */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Remove default padding */
ul[class],
ol[class] {
  padding: 0;
}

/* Remove default margin */
body,
h1,
h2,
h3,
h4,
p,
ul[class],
ol[class],
li,
figure,
figcaption,
blockquote,
dl,
dd {
  margin: 0;
}

/* Set core body defaults */
body {
  min-height: 100vh;
  scroll-behavior: smooth;
  text-rendering: optimizeSpeed;
  line-height: 1.5;
}

/* Remove list styles on ul, ol elements with a class attribute */
ul[class],
ol[class] {
  list-style: none;
}

/* A elements that don't have a class get default styles */
a:not([class]) {
  text-decoration-skip-ink: auto;
}

/* Make images easier to work with */
img {
  max-width: 100%;
  display: block;
}

/* Natural flow and rhythm in articles by default */
article > * + * {
  margin-top: 1em;
}

/* Inherit fonts for inputs and buttons */
input,
button,
textarea,
select {
  font: inherit;
}

/* Remove all animations and transitions for people that prefer not to see them */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
:root {
  color-scheme: light dark;

  --fg: #000;
  --fg-dim: #555;
  --fg-muted: #666;
  --fg-faint: #999;

  --bg: #fff;          /* chrome and raised surfaces */
  --bg-well: #f6f6f6;  /* content area behind surfaces */
  --bg-inset: #eee;
  --bg-button: #f5f5f5;
  --bg-active: #f8f8f8;

  --border: #e0e0e0;
  --border-light: #eee;
  --border-faint: #f2f2f2;
  --border-strong: #ccc;

  --link: #15c;
  --link-read: #77c;
  --link-unread: #00c;

  --green: #4a4;
  --green-dark: #008d47;
  --bg-green: #f6fff6;
  --border-green: #afa;
  --flag: #bfa300;

  --notice-fg: #0c5460;
  --notice-bg: #d1ecf1;
  --notice-border: #bee5eb;
  --alert-fg: #721c24;
  --alert-bg: #f8d7da;
  --alert-border: #f5c6cb;
}

/* The dark palette applies with the system preference unless the user
   forced light in the settings, and always when they forced dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fg: #ddd;
    --fg-dim: #a8a8a8;
    --fg-muted: #909090;
    --fg-faint: #6e6e6e;

    --bg: #1f1f1f;
    --bg-well: #141414;
    --bg-inset: #2a2a2a;
    --bg-button: #2c2c2c;
    --bg-active: #363636;

    --border: #3c3c3c;
    --border-light: #333;
    --border-faint: #2a2a2a;
    --border-strong: #555;

    --link: #7aa2f7;
    --link-read: #8d9cd8;
    --link-unread: #a8c7fa;

    --green-dark: #3fb968;
    --bg-green: #17211a;
    --border-green: #2c4a33;
    --flag: #d9b62a;

    --notice-fg: #9ed6e0;
    --notice-bg: #12343b;
    --notice-border: #1c4a54;
    --alert-fg: #f1aeb5;
    --alert-bg: #35181c;
    --alert-border: #58232b;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --fg: #ddd;
  --fg-dim: #a8a8a8;
  --fg-muted: #909090;
  --fg-faint: #6e6e6e;

  --bg: #1f1f1f;
  --bg-well: #141414;
  --bg-inset: #2a2a2a;
  --bg-button: #2c2c2c;
  --bg-active: #363636;

  --border: #3c3c3c;
  --border-light: #333;
  --border-faint: #2a2a2a;
  --border-strong: #555;

  --link: #7aa2f7;
  --link-read: #8d9cd8;
  --link-unread: #a8c7fa;

  --green-dark: #3fb968;
  --bg-green: #17211a;
  --border-green: #2c4a33;
  --flag: #d9b62a;

  --notice-fg: #9ed6e0;
  --notice-bg: #12343b;
  --notice-border: #1c4a54;
  --alert-fg: #f1aeb5;
  --alert-bg: #35181c;
  --alert-border: #58232b;
}

body { font-family: arial,sans-serif; font-size: 13px; padding: 0; margin: 0;
  min-height: 100vh; display: flex; flex-direction: column;
  background-color: var(--bg); color: var(--fg);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
input[type="number"],
input[type="date"],
input[type="time"],
textarea,
select {
  margin: 0;
  border: none;
  border: 1px solid var(--border);
  box-shadow: inset 1px 1px 0 var(--bg-active);
  border-radius: 2px;
  font-size: 13px;
  padding: 0.3rem 0.5rem 0.3rem 0.5rem;
  background-color: var(--bg);
}

.page-wrap {
  display: flex;
  flex: 1 100%;
  flex-direction: row;
}

a { color: var(--link); }
hr { border: 0; border-top: 1px solid var(--border); }
button { font-size: 1rem; }
header { border-bottom: 1px solid var(--border);}
header nav,
footer { padding-block: 0.5rem; padding-inline: 0.5rem 1rem; }
header nav { min-height: 1rem; }
/*header nav strong { color: var(--fg-dim); }*/
header nav > a { margin-inline-end: 1rem; }
header nav span { color: var(--fg-muted); }
header nav div { float: inline-end; }
header nav div > a{  margin-inline-start: 1rem; }

header nav .accounts { display: inline-block; position: relative; }
header nav .accounts summary { cursor: pointer; color: var(--fg-muted); }
header nav .accounts-menu {
  position: absolute;
  inset-inline-end: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  min-width: max-content;
  padding: 0.5rem;
  background-color: var(--bg);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
header nav .accounts-menu .active { font-weight: 500; }
header nav .accounts-menu button {
  padding: 0;
  border: none;
  background: none;
  color: var(--link);
  text-align: start;
  cursor: pointer;
}
header a.active { font-weight: bold; color: var(--fg); text-decoration: none; }

header .notice {
    color: var(--notice-fg);
    background-color: var(--notice-bg);
    border: 1px solid var(--notice-border);
    padding: 0.5rem;
    text-align: center;
}

footer { text-align: end; }

.actions { padding: 0.5rem; }

.container {
  flex: 1 auto;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  min-width: 0;
}

.container.error {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem 0;
}

aside { flex: 0 0 180px; }

aside img { display: block; }

aside ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

aside li {
  width: 100%;
  display: flex;
  padding: 0.4rem 0.5rem;
}

aside li a {
  flex-grow: 1;
}

aside .active {
  font-weight: bold;
  color: var(--fg);
  text-decoration: none;
}

aside .active,
aside .new.active {
  background-color: var(--bg-well);
}

aside .new.active {
  color: var(--green-dark);
}

aside button {
  margin: 0;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  display: inline-block;
  padding: 0 0.3rem;
  margin-inline-end: 0.3rem;
  border: none;
  background: transparent;
}

aside .active button:hover {
  background: var(--bg);
}

aside button:hover {
  background: var(--bg-well);
}

main {
  flex: 1 100%;
  display: flex;
  flex-direction: column;
  padding-block: 0.5rem; padding-inline: 0.5rem 1rem;
  min-width: 0;
  background-color: var(--bg-well);
}

main.login {
  justify-content: center;
}

main.login > section {
  align-self: center;
  background: var(--bg);
  width: min(26rem, 100%);
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

main.login button {
  width: 100%;
  padding-block: 0.6rem;
  font-weight: bold;
}

main.login .version {
  margin-top: 1rem;
  text-align: center;
  color: var(--fg-faint);
  font-size: 0.8rem;
}

aside a.new.active,
main.create-update {
  background-color: var(--bg-green);
}

main.create-update {
  padding: 1rem;
}

/* Compose email form - needs flex to fill space */
main.create-update:has(.headers) {
  flex: 1 auto;
}

main.create-update:has(.headers) form {
  flex: 1 auto;
  display: flex;
  flex-direction: column;
}

/* Sieve filter editor - the script pane fills the remaining space */
main.create-update form.filter {
  flex: 1 auto;
  display: flex;
  flex-direction: column;
}

main.create-update form.filter > label.script {
  flex: 1 auto;
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
}

main.create-update form.filter > label.script > textarea {
  flex: 1 auto;
  font-family: monospace;
  resize: none;
}

/* Simple create forms (event, task, contact) */
main.create-update > form > label {
  display: block;
  margin-bottom: 0.75rem;
}

main.create-update > form > label > span {
  display: block;
}

main.create-update > form > label > input,
main.create-update > form > label > select,
main.create-update > form > label > textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
}

main.create-update > form > label > textarea {
  min-height: 8rem;
}

/* Compose form headers grid */
main.create-update .headers {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto auto auto;
  grid-gap: 0.5rem;
  align-items: center;
}

main.create-update .headers.no-js {
  grid-template-columns: auto 1fr;
}

main.create-update .headers label {
  grid-column-start: 1;
}

main.create-update .headers input {
  grid-column-start: 2;
  grid-column-end: 3;
}

main.create-update #attachment-list {
  grid-column-start: 3;
  grid-row-start: 1;
  grid-row-end: 7;

  width: 25rem;
  height: 100%;
  background: var(--bg-inset);
  overflow-y: scroll;
  border: 1px solid var(--border-light);

  display: flex;
  flex-direction: column;
}

main.create-update #attachment-list .help {
  text-align: center;
  color: var(--fg-dim);
  margin-top: 1rem;
}

main.create-update #attachment-list .upload {
  width: calc(100% - 1rem);
  position: relative;
  display: flex;
  margin: 0.5rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg);
  align-items: center;
}

main.create-update #attachment-list *:not(:last-child) {
  margin-inline-end: 0.25rem;
}

main.create-update #attachment-list .upload .filename {
  flex-grow: 1;
}

main.create-update #attachment-list .upload button {
  padding: inherit;
  min-width: inherit;
}

main.create-update #attachment-list .upload .progress {
  position: absolute;
  height: 5px;
  background: var(--green);
  bottom: 0;
  inset-inline-start: 0;
}

main.create-update #attachment-list .upload .error {
  display: none;
}

main.create-update #attachment-list .upload.error .error {
  display: block;
  color: var(--alert-fg);
}

main.create-update .text {
  flex: 1 auto;
  resize: none;
  margin-top: 1rem;
  position: relative;
}

main.create-update .text textarea {
  width: 100%;
  height: 100%;
}

#send-progress {
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  width: 100%;
  height: 100%;
  font-size: 1.2rem;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

#send-progress svg {
  height: 1.2rem;
  margin-inline-end: 0.3rem;
  animation: fa-spin 2s infinite linear;
}

#send-progress svg path {
  fill: currentColor;
}

@keyframes fa-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(1turn);
  }
}

main table { border-collapse: collapse; width: 100%; border: 1px solid var(--border-light); }
main table td {
  white-space: nowrap;
  padding: 0.3rem;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
main table tbody tr { border-bottom: 1px solid var(--border-light); }
main table td a { text-decoration: none; }


main table td a:hover { text-decoration: underline; }

main.message table,
main.event table { background-color: var(--bg); }
main.message th,
main.event th { width: 5%;}
main.message h1,
main.event h1 { font-size: 1.2rem; padding: 0.5rem;}
main.message .remote-content {
  background: var(--bg-green);
}

main.message .remote-content td {
  color: var(--fg);
}

main.message .tabs {
  margin: 0.3rem 0 0 0;
  padding: 0;
  border-bottom: 1px solid var(--border-light);
  overflow: visible;
}

main.message .tabs a {
  padding: 0.2rem 0.5rem;
  margin: 0;
  display: inline-block;
  height: calc(100% + 1px);
  margin-bottom: -1px;
  border-style: solid;
  border-color: transparent;
  border-width: 1px;
  text-decoration: none;
  color: var(--fg-dim);
}

main.message .tabs a.active,
main.message .tabs a:hover {
  background-color: var(--bg);
  border-color: var(--border-light) var(--border-light) var(--bg) var(--border-light);
  color: var(--fg);
}

main.message pre,
main.message iframe,
main.event pre {
  flex: 1 auto;
  padding: 1rem;
  margin: 0;
  background-color: var(--bg);
  border-style: solid;
  border-color: var(--border-light);
  border-width: 0 1px 1px 1px;
  max-width: 100%;
}

/* E-mail documents assume a light canvas, whatever the UI theme. */
main.message iframe {
  background-color: white;
}

main.message pre,
main.event pre {
  white-space: pre-wrap;
  word-break: break-all;
}

main.message .message-header {
  display: flex;
  flex-direction: row;
}

main.message .message-header .parts {
  width: 30%;
  margin-inline-start: 0.3rem;
  padding: 0.3rem 0.5rem;
  background: var(--bg);
  border-top: 1px solid var(--border-faint);
}

main.message .message-header .parts ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

main.message .message-header .parts li {
  margin-inline-start: 0;
}

/* View pages (contact, task, event) */
main.contact .details,
main.task .details,
main.event .details {
  padding: 1rem;
}

main.contact .details h1,
main.task .details h1,
main.event .details h1 {
  margin: 0 0 1rem 0;
}

main.contact dl,
main.task dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}

main.contact dl dt,
main.task dl dt {
  font-weight: 500;
  color: var(--fg-muted);
}

main.contact dl dd,
main.task dl dd {
  margin: 0;
}

main.contact dl dd.contact-address {
  white-space: pre-line;
}

main.event .details table {
  border-collapse: collapse;
}

main.event .details th,
main.event .details td {
  padding: 0.3rem 0.5rem;
  text-align: start;
}

main.event .details th {
  color: var(--fg-muted);
  font-weight: 500;
}

.contact-photo {
  float: inline-end;
  max-width: 120px;
  max-height: 120px;
  border-radius: 8px;
  margin-inline-start: 1rem;
}

main.create-update .actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  background: transparent;
  padding-inline-start: 0;
  margin-top: 1rem;
}

main.create-update .actions button,
main.create-update .actions .button-link {
  padding: 0.4rem 1rem 0.35rem;
  font-weight: bold;
}

main.create-update .actions > *:not(:last-child) {
  margin-inline-end: 1rem;
}

.actions h3 {
  align-self: center;
  margin-block: 0; margin-inline: 1rem 1.3rem;
}

.message-list-flags {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.message-list-flags .flag-button {
  margin: 0;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  display: inline-block;
  padding: 0;
  border: none;
  color: var(--flag);
  font-size: 13pt;
  background: transparent;
}

.message-list-unread.message-list-flags .flag-button:hover {
  background: var(--bg-active);
}

.message-list-subject a { color: var(--link-read); }

.message-list-unread.message-list-sender,
.message-list-unread.message-list-subject,
.message-list-unread.message-list-date { font-weight: bold; }

.message-list-unread.message-list-sender,
.message-list-unread.message-list-date { color: var(--fg);}

.message-list-unread.message-list-subject {
  font-weight: normal;
  color: var(--fg-dim);
}

.message-list-date {
  text-align: end;
}

.message-list-unread.message-list-subject a { color: var(--link-unread); }

.message-list-unread {
  background-color: var(--bg);
  opacity: 1;
}

.message-row {
  display: contents;
}

.message-list-unread:first-child {
  border-inline-start: 1px solid var(--border-faint);
}

.message-list-unread:last-child {
  border-inline-end: 1px solid var(--border-faint);
}

aside .new {
  color: var(--green-dark);
  font-weight: bold;
  /*background-color: #f5fcf2;*/
  text-decoration: none;
}

main table th {
  text-align: start;
  padding: 0.3rem; font-weight: normal;
}

main table thead {
  border-bottom: 1px solid var(--border);
  background-color: var(--bg);
}
main table tfoot {
  border-top: 1px solid var(--border);
  background-color: var(--bg);
}

.message-list,
.contact-list {
  display: flex;
}

/* Rows stay scannable on wide monitors: the cap bounds the eye travel
   from subject to date, as the reading view's 800px cap already does. */
.message-list section,
.contact-list section,
.task-list section {
  width: 100%;
  max-width: 90rem;
}

.actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  background-color: var(--bg);
  padding: 0.3rem;
}

.message-list .actions:first-child,
.contact-list .actions:first-child {
  border-bottom: 1px solid var(--border);
}

.message-list .actions:last-child,
.contact-list .actions:last-child {
  border-top: 1px solid var(--border);
}

.actions input[type="text"] {
  flex: 1;
  min-width: 6rem;
  margin: 0;
}

.actions input[type="text"] + button {
  border-start-start-radius: 0;
  border-end-start-radius: 0;
}

.actions input[type="text"] {
  border-start-end-radius: 0;
  border-end-end-radius: 0;
}

.actions-wrap {
  display: flex;
  flex-grow: 1;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.actions-search {
  display: flex;
  flex-direction: row;
  flex-grow: 1;
}

.actions-pagination {
  margin-inline-start: 1rem;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.actions-wrap > .actions-pagination:first-child {
  margin-inline-start: 0;
}

.actions-wrap > .actions-pagination:last-child {
  margin-inline-start: auto;
}

.actions-pagination h3 {
  margin: 0;
  font-weight: 500;
}

.pagination-range {
  color: var(--fg-muted);
  white-space: nowrap;
}

.action-group:not(:last-child) {
  margin-bottom: 1rem;
}

/* Conditional action groups render empty; keep them out of the gaps. */
.action-group:not(:has(*)) {
  display: none;
}

.actions-wrap .action-group {
  margin-inline-start: 0.3rem;
  margin-bottom: 0;
}

.action-group.grow {
  flex-grow: 1;
}

.action-group label,
.action-group input,
.action-group textarea,
.action-group select[multiple] {
  display: block;
  width: 100%;
}

.action-group .checkbox input {
  display: inline;
  width: 1rem;
  float: inline-start;
}

.action-group select[multiple] {
  height: 10rem;
}

.actions-message,
.actions-contacts {
  display: flex;
  flex-direction: row;
  flex-grow: 1;
  align-items: center;
}

.actions-left,
.actions-right {
  display: flex;
  align-items: center;
}

.actions-left a,
.actions-right a {
  padding: 0.3rem 0.5rem;
  text-decoration: none;
  color: inherit;
}

.actions-message h2 {
  margin: 0;
  flex-grow: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.1rem;
}

.message-list-checkbox,
.contact-list-checkbox {
  align-self: center;
}

.message-list .messages,
.contact-list .contacts {
  flex-grow: 1;
}

.message-grid {
  display: grid;
  /* Sender column tracks the longest name up to a cap instead of a fixed
     share, so names are rarely truncated. */
  grid-template-columns: auto fit-content(18rem) auto 1fr auto;
  grid-template-rows: auto;
}

.contact-grid {
  display: grid;
  grid-template-columns: auto 2rem 1fr 2fr 1fr;
  grid-template-rows: auto;
}

.contact-list-photo {
  display: flex;
  align-items: center;
  justify-content: center;
}

.contact-list-photo img {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  object-fit: cover;
}

.contact-list-header {
  font-weight: bold;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border-strong);
}

/* Rows are not hyperlink soup: links show their nature on hover, as
   the tables these grids replaced did. */
.message-grid a,
.contact-grid a {
  text-decoration: none;
}

.message-grid a:hover,
.contact-grid a:hover {
  text-decoration: underline;
}

/* Every list shares the same row rhythm: a hairline between rows, as
   the task and filter lists already do. */
.message-list .messages .message-list-item,
.contact-list .contacts .contact-grid > * {
  border-bottom: 1px solid var(--border-light);
}

.contact-list .contacts .contact-grid > .contact-list-header {
  border-bottom-color: var(--border-strong);
}

.message-list .messages .message-list-item,
.contact-list .contacts .contact-grid > * {
  white-space: nowrap;
  padding: 0.3rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
}

.followups a:not(:first-child) {
  margin-inline-start: 0.3rem;
}

.empty-list {
  text-align: center;
  grid-column-start: 1;
  grid-column-end: 10;
  font-size: 1.1rem;
  color: var(--fg-dim);
  margin-top: 1rem;
}

main.calendar .dates {
  flex-grow: 1;
  padding: 0.3rem;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: min-content;
  grid-auto-rows: 1fr;
  grid-gap: 0.3rem;
}

main.calendar .dates .weekday {
  text-align: center;
  font-size: 1.1rem;
  font-weight: normal;
}

main.calendar .date {
  border: 1px solid var(--border-light);
  padding: 0.3rem;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
}

main.calendar .date.active {
  background-color: var(--bg-green);
  border: 1px solid var(--border-green);
}

main.calendar .date .date-link {
  position: absolute;
  inset: 0;
}

main.calendar .date.extra {
  background: var(--bg-well);
  border: 1px solid var(--border-faint);
  opacity: 0.5;
}

main.calendar .date ul {
  list-style: none;
  margin: 0;
  padding-inline-start: 0.3rem;
}

main.calendar .date.extra .events {
  visibility: hidden;
}

main.calendar .events .start-time {
  color: var(--fg-dim);
}

main.calendar .events .overflow {
  color: var(--fg-dim);
  text-align: end;
}

main.calendar .date h4 {
  font-weight: normal;
  text-align: end;
  color: var(--fg-muted);
}

main.calendar .date h4 .da { font-size: 1.2rem; }

main.calendar-date .events-list ul {
  list-style: none;
  padding: 0;
}

#calendar-filter, #addressbook-filter, #task-filter {display: flex; flex-direction: column;}

.color-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-inline-end: 4px;
  vertical-align: middle;
}

/* In the unified view the checkbox cell carries the account color as
   a K-9 style stripe; a full-height bar reads at a glance where a dot
   would not. */
.message-list-checkbox .color-dot {
  width: 4px;
  height: 1.4rem;
  margin-inline-end: 0;
}

main.settings form {
  max-width: 600px;
}

main.settings button {
  background-color: var(--bg);
}

main.settings button:hover {
  background-color: var(--bg-active);
}

input[type="submit"],
.button,
button,
.button-link {
  margin: 0;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  display: inline-block;
  /*padding: 0.4rem 0.4rem 0.35rem;*/
  padding: 0.3rem 0.3rem 0.25rem;
  min-width: 1rem;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 3px;
  vertical-align: middle;
  color: var(--fg);
}
.button-link {
  border: 1px solid transparent;
  text-decoration: none;
}
.button-link:hover {
  text-decoration: underline;
}

input[type="submit"],
.button,
button,
.button-link {
  background-color: var(--bg-button);
  border: 1px solid var(--border);
  color: var(--fg);
}

.button:hover,
button:hover,
.button-link:hover {
  background-color: var(--bg);
  text-decoration: none;
}

button[disabled], button[disabled]:hover {
  color: var(--fg-muted);
  background-color: var(--bg-button);
  border-color: var(--border-light);
  cursor: default;
}

/* Overflow menus keep secondary actions behind a ⋮, in the same
   dropdown shape as the account menu. */
details.overflow {
  position: relative;
  display: inline-block;
}

.actions-wrap details.overflow {
  margin-inline-start: 0.3rem;
}

details.overflow > summary {
  list-style: none;
  user-select: none;
}

details.overflow > summary::-webkit-details-marker {
  display: none;
}

.actions-end {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-inline-start: auto;
}

.actions-end .actions-search {
  margin-inline-start: 0;
}

.overflow-menu {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 2px);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  min-width: max-content;
  padding: 0.5rem;
  background-color: var(--bg);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Unicode has no shrinking-bars sort glyph, so it is drawn inline,
   masked so it takes the same text color as its sibling buttons. */
summary.sort-button {
  display: inline-block;
  padding-inline: 0.15rem;
}

summary.sort-button::before {
  content: "";
  display: block;
  width: 0.85rem;
  height: 1.15rem;
  background-color: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5'%3E%3Cpath d='M4 6h16'/%3E%3Cpath d='M4 12h10'/%3E%3Cpath d='M4 18h5'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5'%3E%3Cpath d='M4 6h16'/%3E%3Cpath d='M4 12h10'/%3E%3Cpath d='M4 18h5'/%3E%3C/svg%3E") center / contain no-repeat;
}

.overflow-menu > strong {
  padding: 0.3rem;
}

.overflow-menu form {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.overflow-menu button,
.overflow-menu .button-link {
  width: 100%;
  text-align: start;
}

.button:active,
button:active,
.button-link:active {
  color: var(--border-strong);
  background-color: var(--bg-active);
}

.alert {
  padding: 0.5rem;
  border: 1px solid transparent;
  margin: 1rem 0;
  background: var(--alert-bg);
  color: var(--alert-fg);
  border-color: var(--alert-border);
  max-width: 600px;
}

/* Tasks */
.task-list {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.task-list .tasks {
  padding: 0.5rem;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border-light);
}

.task-item.completed .task-summary {
  text-decoration: line-through;
  color: var(--fg-faint);
}

.task-checkbox {
  margin-inline-end: 0.5rem;
}

.checkbox-button {
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--fg-muted);
  border-radius: 3px;
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  padding: 0;
}

.checkbox-button.checked {
  background: var(--green);
  border-color: var(--green);
  color: var(--bg);
}

.task-content {
  flex-grow: 1;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0;
}

.task-content .task-summary {
  flex-grow: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-summary {
  display: block;
  color: inherit;
  text-decoration: none;
}

.task-summary:hover {
  text-decoration: underline;
}

.task-due {
  font-size: 0.85rem;
  color: var(--fg-muted);
}

main.task .details h1.completed {
  text-decoration: line-through;
  color: var(--fg-faint);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-label input {
  width: auto;
}

.task-group {
  margin-bottom: 1rem;
}

.task-group-header {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fg-dim);
  margin: 0.5rem 0;
}

.show-completed-toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--fg-muted);
  margin-top: 1rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-light);
}

.show-completed-toggle input {
  width: auto;
}

/* Small screens: the desktop minimum width no longer applies and the
   sidebar becomes an off-canvas drawer, driven by the checkbox in the
   header so no script is involved. */
.sidebar-toggle,
.sidebar-button,
.sidebar-backdrop {
  display: none;
}

@media (max-width: 768px) {
  body { min-width: 0; }

  .sidebar-button {
    display: inline-block;
    cursor: pointer;
    padding: 0 0.3rem;
    margin-inline-end: 0.5rem;
    font-size: 1.2rem;
  }

  /* Error pages have no sidebar, so no button to open one. */
  body:not(:has(aside)) .sidebar-button { display: none; }

  /* The header is a single swipeable row; the account block leaves it
     and docks at the bottom of the open drawer instead. */
  header nav {
    display: flex;
    align-items: center;
    overflow-x: auto;
    white-space: nowrap;
  }

  header nav > a { margin-inline-end: 0.75rem; }

  header nav > div { float: none; display: none; }

  .sidebar-toggle:checked ~ header nav > div {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    position: fixed;
    bottom: 0;
    inset-inline-start: 0;
    width: 14rem;
    z-index: 21;
    padding: 0.75rem;
    background-color: var(--bg);
    border-top: 1px solid var(--border);
    border-inline-end: 1px solid var(--border);
  }

  .sidebar-toggle:checked ~ header nav > div > a { margin-inline-start: 0; }

  .sidebar-toggle:checked ~ header .accounts-menu {
    position: static;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  /* The summary already names the active account; the menu only needs
     the others. */
  .sidebar-toggle:checked ~ header .accounts-menu > .active { display: none; }

  aside {
    position: fixed;
    inset-block: 0;
    inset-inline-start: -14rem;
    width: 14rem;
    z-index: 20;
    overflow-y: auto;
    padding-bottom: 10rem; /* room for the docked account block */
    background-color: var(--bg);
    border-inline-end: 1px solid var(--border);
    transition: inset-inline-start 0.15s ease-out;
  }

  .sidebar-toggle:checked ~ .page-wrap aside { inset-inline-start: 0; }

  body:has(.sidebar-toggle:checked) { overflow: hidden; }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 15;
    background-color: rgba(0, 0, 0, 0.4);
  }

  .sidebar-toggle:checked ~ .sidebar-backdrop { display: block; }

  /* Lists and toolbars run edge to edge; standalone forms keep an inset. */
  main { padding: 0; }
  main.create-update,
  main.settings { padding: 0.75rem; }

  main.login > section { width: 100%; }

  /* The mailbox becomes two-line rows: sender and date on top, subject
     and flags below. */
  .message-grid { display: block; }

  .message-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "check sender date"
      "check subject flags";
    column-gap: 0.5rem;
    padding-inline: 0.5rem;
    border-bottom: 1px solid var(--border-light);
  }

  .message-row:has(.message-list-unread) { background-color: var(--bg); }

  /* The two-line row draws one separator on its wrapper. */
  .message-list .messages .message-list-item {
    padding: 0.15rem 0;
    border-inline: 0;
    border-bottom: 0;
  }

  .message-list-checkbox { grid-area: check; }
  .message-list-checkbox .color-dot { height: 100%; }
  /* The sender is a from-search link, but the subject is the row's real
     action; only it keeps the link color. */
  .message-list-sender { grid-area: sender; }
  .message-list-sender a { color: inherit; }
  .message-list-date {
    grid-area: date;
    justify-content: flex-end;
    font-size: 0.8rem;
  }
  .message-list-subject { grid-area: subject; }
  .message-list-flags { grid-area: flags; }

  /* Toolbars compact to two rows: the buttons and the count share the
     first, the search gets the second. */
  .actions {
    flex-wrap: wrap;
    row-gap: 0.3rem;
    column-gap: 0.3rem;
    padding: 0.3rem 0.5rem;
  }

  /* The select-all checkbox shares the first toolbar row, in the same
     column as the row checkboxes below it. */
  .message-list .actions,
  .contact-list .actions {
    flex-wrap: nowrap;
    align-items: flex-start;
    padding-inline: 0;
  }

  /* The drawer toggle stays focusable for the keyboard, just unseen. */
  .sidebar-toggle {
    display: block;
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    opacity: 0;
  }

  .sidebar-toggle:focus-visible ~ header .sidebar-button {
    outline: 2px solid var(--link);
  }

  .actions { position: relative; }

  .message-list .actions > .message-list-checkbox,
  .contact-list .actions > .message-list-checkbox {
    padding-block: 0.4rem;
    padding-inline: 0.5rem;
  }

  .contact-list .actions > .message-list-checkbox {
    padding-inline: 0.3rem;
  }

  .actions button,
  .actions .button-link {
    white-space: nowrap;
  }

  .actions-wrap { flex-wrap: wrap; row-gap: 0.3rem; min-width: 0; }
  .actions-message { flex-wrap: wrap; row-gap: 0.3rem; column-gap: 0.3rem; }

  /* The search collapses to a bare magnifier icon; focusing it overlays
     the whole toolbar row with the input. */
  .actions-search {
    margin-inline-start: auto;
    flex-grow: 0;
  }

  .actions-search input {
    width: 2rem;
    border: none;
    box-shadow: none;
    color: transparent;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M21 21l-5.2-5.2'/%3E%3C/svg%3E") center / 1.2rem no-repeat;
  }

  .actions-search input::placeholder { color: transparent; }
  .actions-search button { display: none; }

  .actions-search:focus-within {
    position: absolute;
    inset: 0;
    z-index: 5;
    margin: 0;
    padding: 0.3rem 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background-color: var(--bg);
  }

  .actions-search:focus-within input {
    flex: 1;
    width: 100%;
    color: inherit;
    border: 1px solid var(--border);
    background: var(--bg);
  }

  .actions-search:focus-within input::placeholder {
    color: var(--fg-faint);
  }

  .actions-search:focus-within button { display: inline-block; }

  /* Alone in its toolbar, the search already has the row and stays a
     full input. */
  .task-list .actions-search { flex-grow: 1; margin-inline-start: 0; }
  .task-list .actions-search input {
    width: 100%;
    flex: 1;
    color: inherit;
    border: 1px solid var(--border);
    background: var(--bg);
  }
  .task-list .actions-search input::placeholder { color: var(--fg-faint); }
  .task-list .actions-search button { display: inline-block; }

  .pagination-range { display: none; }
  .actions-wrap .action-group { margin-inline-start: 0; }
  .actions-pagination { margin-inline-start: auto; }
  .actions-pagination h3 { font-size: 0.8rem; }

  /* Message view: header fields wrap and the parts pane stacks below. */
  main.message .message-header { flex-direction: column; }
  main.message .message-header .parts {
    width: auto;
    margin-inline-start: 0;
    margin-top: 0.3rem;
  }
  main.message th, main.event th { width: auto; }
  main.message td {
    white-space: normal;
    max-width: none;
    overflow-wrap: anywhere;
  }

  /* Compose: single header column, attachments below the fields. */
  main.create-update .headers { grid-template-columns: auto minmax(0, 1fr); }
  main.create-update #attachment-list {
    grid-column: 1 / -1;
    grid-row: auto;
    width: auto;
    height: 8rem;
  }

  /* Contacts: name and phone only; the e-mail column waits for the
     detail page. */
  .contact-grid { grid-template-columns: auto 2rem minmax(0, 1fr) auto; }
  .contact-list .contacts .contact-grid > .contact-list-email,
  .contact-list .contacts .contact-grid > .contact-list-header:nth-child(4) {
    display: none;
  }
  .contact-list-phone { font-size: 0.8rem; }

  /* Calendar: a compact month with single-letter weekdays and events
     reduced to their color dots; the day link opens the full list. */
  main.calendar .dates { grid-gap: 2px; padding: 0; }
  main.calendar .dates .weekday { font-size: 0; }
  main.calendar .dates .weekday::first-letter { font-size: 0.8rem; }
  main.calendar .date { padding: 2px; min-height: 3rem; }
  main.calendar .date h4 { font-size: 0.7rem; }
  main.calendar .date h4 .da { font-size: 0.9rem; }
  main.calendar .date ul { padding-inline-start: 0; }
  main.calendar .events li { display: inline; font-size: 0; }
  main.calendar .events li .color-dot {
    width: 6px;
    height: 6px;
    margin-inline-end: 2px;
  }
  main.calendar .events .overflow { font-size: 0.7rem; }
}
