/* ============================================================
   Kapsule Mail — Main Stylesheet
   Roundcube 1.6.x / extends: elastic
   Light mode only
   ============================================================ */

/* ── 1. Font face ─────────────────────────────────────────── */
@font-face {
  font-family: 'Urbanist Variable';
  src: url('../fonts/urbanist-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ── 2. CSS custom properties ─────────────────────────────── */
:root,
html.kapsule {
  --bg:            #FAFAFA;
  --surface:       #FFFFFF;
  --surface-elev:  #F4F4F5;
  --border:        #E4E4E7;
  --border-strong: #D4D4D8;
  --text-primary:  #18181B;
  --text-secondary:#52525B;
  --text-muted:    #A1A1AA;
  --accent:        #14bccf;
  --accent-fg:     #FFFFFF;
  --accent-hover:  #11a8ba;
  --accent-subtle: rgba(20,188,207,0.08);
  --success:       #10B981;
  --warning:       #F59E0B;
  --danger:        #EF4444;

  --font-ui: 'Urbanist Variable', system-ui, sans-serif;

  --radius-sm:  4px;
  --radius-md:  6px;
  --radius-lg:  8px;
  --radius-xl:  12px;
  --radius-2xl: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.06), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);

  --topbar-h: 56px;
  --sidebar-w: 220px;
  --list-w: 380px;
}

/* ── 3. Reset / neutralise elastic defaults ───────────────── */
html.kapsule,
html.kapsule body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100%;
  overflow: hidden;
}

html.kapsule *,
html.kapsule *::before,
html.kapsule *::after {
  box-sizing: border-box;
}

html.kapsule h1,
html.kapsule h2,
html.kapsule h3,
html.kapsule h4,
html.kapsule h5,
html.kapsule h6 {
  font-family: var(--font-ui);
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin: 0 0 0.5em;
}

html.kapsule h1 { font-size: 1.5rem; font-weight: 700; }
html.kapsule h2 { font-size: 1.25rem; font-weight: 700; }
html.kapsule h3 { font-size: 1.1rem; font-weight: 600; }

html.kapsule a {
  color: var(--accent);
  text-decoration: none;
}
html.kapsule a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

html.kapsule ul,
html.kapsule ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

html.kapsule button,
html.kapsule input,
html.kapsule select,
html.kapsule textarea {
  font-family: var(--font-ui);
  font-size: 14px;
}

/* ── 4. Base typography ───────────────────────────────────── */
html.kapsule p {
  margin: 0 0 1em;
  color: var(--text-secondary);
}

html.kapsule small {
  font-size: 0.75rem;
  color: var(--text-muted);
}

html.kapsule strong {
  font-weight: 600;
}

/* ── 5. Topbar ────────────────────────────────────────────── */
html.kapsule #topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 200;
  box-shadow: var(--shadow-sm);
}

html.kapsule #topbar .logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  text-decoration: none;
}

html.kapsule #topbar .logo-area img,
html.kapsule #topbar .logo-area svg {
  width: 32px;
  height: 32px;
  display: block;
}

html.kapsule #topbar .logo-wordmark {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

html.kapsule #topbar .logo-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

html.kapsule #topbar .logo-product {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

html.kapsule #topbar .search-wrapper {
  flex: 1;
  max-width: 480px;
  margin: 0 auto;
}

html.kapsule #topbar #mailsearchform,
html.kapsule #topbar .searchform {
  display: flex;
  align-items: center;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0 14px;
  height: 36px;
  gap: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

html.kapsule #topbar #mailsearchform:focus-within,
html.kapsule #topbar .searchform:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
  background: var(--surface);
}

html.kapsule #topbar #mailsearchform input[type="text"],
html.kapsule #topbar .searchform input[type="text"] {
  border: none;
  background: transparent;
  outline: none;
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
}

html.kapsule #topbar #mailsearchform input[type="text"]::placeholder,
html.kapsule #topbar .searchform input[type="text"]::placeholder {
  color: var(--text-muted);
}

html.kapsule #topbar #mailsearchform .search-icon,
html.kapsule #topbar .searchform .search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

html.kapsule #topbar .topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

html.kapsule #topbar .task-menu {
  display: flex;
  align-items: center;
  gap: 4px;
}

html.kapsule #topbar .task-menu a,
html.kapsule #topbar .task-menu button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
}

html.kapsule #topbar .task-menu a:hover,
html.kapsule #topbar .task-menu button:hover {
  background: var(--surface-elev);
  color: var(--text-primary);
  text-decoration: none;
}

html.kapsule #topbar .task-menu a.selected,
html.kapsule #topbar .task-menu a.active,
html.kapsule #topbar .task-menu button.selected {
  background: var(--accent-subtle);
  color: var(--accent);
}

/* Compose button */
html.kapsule #topbar .btn-compose,
html.kapsule a.btn-compose,
html.kapsule button.btn-compose {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  height: 36px;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

html.kapsule #topbar .btn-compose:hover,
html.kapsule a.btn-compose:hover,
html.kapsule button.btn-compose:hover {
  background: var(--accent-hover);
  text-decoration: none;
  color: var(--accent-fg);
  box-shadow: var(--shadow-sm);
}

/* Topbar icon buttons */
html.kapsule #topbar .icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
}

html.kapsule #topbar .icon-btn:hover {
  background: var(--surface-elev);
  color: var(--text-primary);
}

/* User menu trigger */
html.kapsule #topbar .user-menu-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background 0.12s, border-color 0.12s;
  max-width: 180px;
}

html.kapsule #topbar .user-menu-btn:hover {
  background: var(--surface-elev);
  border-color: var(--border-strong);
}

html.kapsule #topbar .user-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

html.kapsule #topbar .user-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── 6. Layout three-pane grid ────────────────────────────── */
html.kapsule #layout {
  display: flex;
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
}

html.kapsule #layout-sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  max-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

html.kapsule #layout-list {
  width: var(--list-w);
  min-width: var(--list-w);
  max-width: var(--list-w);
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

html.kapsule #layout-content {
  flex: 1;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── 7. Sidebar / folder list ─────────────────────────────── */
html.kapsule #layout-sidebar .sidebar-header {
  padding: 16px 16px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

html.kapsule #layout-sidebar .sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 16px;
}

html.kapsule #layout-sidebar .sidebar-scroll::-webkit-scrollbar {
  width: 4px;
}
html.kapsule #layout-sidebar .sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}

/* Folder list items */
html.kapsule ul.folderlist,
html.kapsule ul.treelist {
  list-style: none;
  margin: 0;
  padding: 0;
}

html.kapsule ul.folderlist li,
html.kapsule ul.treelist li {
  position: relative;
}

html.kapsule ul.folderlist li a,
html.kapsule ul.treelist li a,
html.kapsule ul.folderlist li span.foldername {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  border-left: 3px solid transparent;
  line-height: 1.4;
}

html.kapsule ul.folderlist li a:hover,
html.kapsule ul.treelist li a:hover {
  background: var(--surface-elev);
  color: var(--text-primary);
  text-decoration: none;
}

html.kapsule ul.folderlist li.selected > a,
html.kapsule ul.treelist li.selected > a,
html.kapsule ul.folderlist li.active > a,
html.kapsule ul.treelist li.active > a {
  background: var(--accent-subtle);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* Unread count badge */
html.kapsule ul.folderlist li .unreadcount,
html.kapsule ul.treelist li .unreadcount,
html.kapsule ul.folderlist li .badge {
  margin-left: auto;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  line-height: 16px;
}

html.kapsule ul.folderlist li.selected .unreadcount,
html.kapsule ul.folderlist li.active .unreadcount {
  background: var(--accent);
}

/* Folder icons */
html.kapsule ul.folderlist li a .folder-icon,
html.kapsule ul.treelist li a .folder-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  opacity: 0.6;
}

html.kapsule ul.folderlist li.selected > a .folder-icon,
html.kapsule ul.folderlist li.active > a .folder-icon {
  opacity: 1;
}

/* Nested folders */
html.kapsule ul.folderlist ul,
html.kapsule ul.treelist ul {
  margin-left: 20px;
}

/* Folder section divider */
html.kapsule .folderlist-section-header {
  padding: 12px 16px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Quota widget in sidebar */
html.kapsule #quotadisplay,
html.kapsule .quotadisplay {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

html.kapsule #quotadisplay .quota-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}

html.kapsule #quotadisplay .quota-bar {
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

html.kapsule #quotadisplay .quota-bar .quota-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width 0.3s;
}

html.kapsule #quotadisplay .quota-bar .quota-fill.warning {
  background: var(--warning);
}

html.kapsule #quotadisplay .quota-bar .quota-fill.danger {
  background: var(--danger);
}

/* ── 8. Message list pane ─────────────────────────────────── */
html.kapsule #layout-list .list-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

html.kapsule #layout-list .list-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

html.kapsule #layout-list .messages-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

html.kapsule #layout-list .messages-scroll::-webkit-scrollbar {
  width: 4px;
}
html.kapsule #layout-list .messages-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}

/* ── 10. Message list table ───────────────────────────────── */
html.kapsule table.messagelist {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

html.kapsule table.messagelist thead {
  display: none;
}

html.kapsule table.messagelist tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}

html.kapsule table.messagelist tr:hover {
  background: var(--surface-elev);
}

html.kapsule table.messagelist tr.selected {
  background: var(--accent-subtle);
}

html.kapsule table.messagelist tr.unread {
  background: var(--surface);
}

html.kapsule table.messagelist tr.unread::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

html.kapsule table.messagelist td {
  padding: 10px 12px;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
  color: var(--text-secondary);
}

html.kapsule table.messagelist td.fromto {
  width: 38%;
  font-weight: 500;
  color: var(--text-primary);
}

html.kapsule table.messagelist tr.unread td.fromto {
  font-weight: 600;
  color: var(--text-primary);
}

html.kapsule table.messagelist td.subject {
  width: 100%;
  color: var(--text-secondary);
}

html.kapsule table.messagelist tr.unread td.subject {
  color: var(--text-primary);
  font-weight: 500;
}

html.kapsule table.messagelist td.date {
  width: 80px;
  text-align: right;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

html.kapsule table.messagelist td.flags {
  width: 28px;
  text-align: center;
  padding: 10px 4px;
}

html.kapsule table.messagelist td.checkbox-cell {
  width: 32px;
  padding: 10px 8px;
}

html.kapsule table.messagelist td.attachment {
  width: 24px;
  text-align: center;
  padding: 10px 4px;
}

/* Flag/star icons in message list */
html.kapsule table.messagelist .flag-icon {
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.1s;
}

html.kapsule table.messagelist tr.flagged .flag-icon {
  color: var(--warning);
}

/* Message list row layout on small widths */
html.kapsule .message-row-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

html.kapsule .message-preview {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

/* Pagenav */
html.kapsule #layout-list .pagenav,
html.kapsule #pagenav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-muted);
}

html.kapsule #pagenav a,
html.kapsule #pagenav button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.12s;
}

html.kapsule #pagenav a:hover,
html.kapsule #pagenav button:hover {
  background: var(--surface-elev);
}

html.kapsule #pagenav a.disabled,
html.kapsule #pagenav button:disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

/* Search bar in list header */
html.kapsule #mailsearchform {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0 12px;
  height: 32px;
  flex: 1;
  transition: border-color 0.15s, box-shadow 0.15s;
}

html.kapsule #mailsearchform:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
  background: var(--surface);
}

html.kapsule #mailsearchform input {
  border: none;
  background: transparent;
  outline: none;
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
  font-family: var(--font-ui);
}

html.kapsule #mailsearchform input::placeholder {
  color: var(--text-muted);
}

/* ── 9. Message viewer / content pane ────────────────────── */
html.kapsule #layout-content .content-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

html.kapsule #layout-content .content-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

html.kapsule #messagecontframe {
  flex: 1;
  border: none;
  width: 100%;
  background: var(--surface);
}

/* Message header (full message view) */
html.kapsule .message-header-block {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

html.kapsule .message-header-block .subject-line {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 12px;
  line-height: 1.3;
}

html.kapsule .message-header-block .header-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

html.kapsule .message-header-block .header-label {
  font-weight: 500;
  color: var(--text-muted);
  min-width: 48px;
  flex-shrink: 0;
}

html.kapsule .message-header-block .header-value {
  color: var(--text-primary);
  word-break: break-word;
}

html.kapsule .message-body-wrap {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
  background: var(--surface);
}

html.kapsule .message-body-wrap::-webkit-scrollbar {
  width: 6px;
}
html.kapsule .message-body-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}

html.kapsule #messageheader {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

html.kapsule #messageheader table {
  border-collapse: collapse;
  width: 100%;
}

html.kapsule #messageheader table td {
  padding: 3px 0;
  font-size: 13px;
  vertical-align: top;
}

html.kapsule #messageheader table td:first-child {
  font-weight: 500;
  color: var(--text-muted);
  width: 80px;
  padding-right: 12px;
}

html.kapsule #messageheader table td:last-child {
  color: var(--text-primary);
}

/* Attachment list */
html.kapsule #messageattachments {
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--surface-elev);
}

html.kapsule #messageattachments .attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}

html.kapsule #messageattachments .attachment:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

html.kapsule #messageattachments .attachment-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

html.kapsule #messageattachments .attachment-name {
  font-weight: 500;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html.kapsule #messageattachments .attachment-size {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── 11. Forms ────────────────────────────────────────────── */
html.kapsule .form-group {
  margin-bottom: 16px;
}

html.kapsule label,
html.kapsule .form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

html.kapsule input[type="text"],
html.kapsule input[type="email"],
html.kapsule input[type="password"],
html.kapsule input[type="search"],
html.kapsule input[type="url"],
html.kapsule input[type="number"],
html.kapsule select,
html.kapsule textarea {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: var(--font-ui);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}

html.kapsule input[type="text"]:focus,
html.kapsule input[type="email"]:focus,
html.kapsule input[type="password"]:focus,
html.kapsule input[type="search"]:focus,
html.kapsule input[type="url"]:focus,
html.kapsule input[type="number"]:focus,
html.kapsule select:focus,
html.kapsule textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

html.kapsule input[type="text"]::placeholder,
html.kapsule input[type="email"]::placeholder,
html.kapsule input[type="password"]::placeholder,
html.kapsule textarea::placeholder {
  color: var(--text-muted);
}

html.kapsule select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23A1A1AA' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

html.kapsule textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.6;
}

html.kapsule input[type="checkbox"],
html.kapsule input[type="radio"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* Buttons */
html.kapsule .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 14px;
  font-family: var(--font-ui);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}

html.kapsule .btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

html.kapsule .btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: var(--shadow-sm);
  color: var(--accent-fg);
  text-decoration: none;
}

html.kapsule .btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border);
}

html.kapsule .btn-secondary:hover {
  background: var(--surface-elev);
  border-color: var(--border-strong);
  color: var(--text-primary);
  text-decoration: none;
}

html.kapsule .btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

html.kapsule .btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
  text-decoration: none;
}

html.kapsule .btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

html.kapsule .btn-ghost:hover {
  background: var(--surface-elev);
  color: var(--text-primary);
  text-decoration: none;
}

html.kapsule .btn-sm {
  padding: 5px 12px;
  font-size: 13px;
}

html.kapsule .btn-lg {
  padding: 11px 24px;
  font-size: 15px;
}

html.kapsule .btn:disabled,
html.kapsule .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Toolbar buttons */
html.kapsule .toolbar-btn,
html.kapsule .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: var(--font-ui);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
  white-space: nowrap;
}

html.kapsule .toolbar-btn:hover,
html.kapsule .button:hover {
  background: var(--surface-elev);
  color: var(--text-primary);
  text-decoration: none;
}

html.kapsule .toolbar-btn.active,
html.kapsule .button.active {
  background: var(--accent-subtle);
  color: var(--accent);
}

html.kapsule .toolbar-btn:disabled,
html.kapsule .button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

html.kapsule .toolbar-btn .inner,
html.kapsule .button .inner {
  display: flex;
  align-items: center;
  gap: 6px;
}

html.kapsule .toolbar-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

/* ── 12. Compose ──────────────────────────────────────────── */
html.kapsule #compose-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

html.kapsule #compose-content .compose-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

html.kapsule #compose-content .compose-header h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

html.kapsule #compose-content .compose-fields {
  padding: 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

html.kapsule #compose-content .compose-field-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}

html.kapsule #compose-content .compose-field-row:last-child {
  border-bottom: none;
}

html.kapsule #compose-content .compose-field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  width: 64px;
  flex-shrink: 0;
}

html.kapsule #compose-content .compose-field-row input[type="text"],
html.kapsule #compose-content .compose-field-row input[type="email"] {
  border: none;
  box-shadow: none;
  border-radius: 0;
  padding: 10px 0;
  background: transparent;
  width: 100%;
}

html.kapsule #compose-content .compose-field-row input:focus {
  box-shadow: none;
}

html.kapsule #compose-content .compose-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
}

html.kapsule #compose-content .compose-body textarea,
html.kapsule #compose-content .compose-body .mce-container {
  border: none;
  box-shadow: none;
  width: 100%;
  resize: none;
  font-size: 14px;
  line-height: 1.7;
}

html.kapsule #compose-content .compose-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

html.kapsule #compose-content .compose-footer .btn-send {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  padding: 10px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

html.kapsule #compose-content .compose-footer .btn-send:hover {
  background: var(--accent-hover);
}

/* Attachment drop zone */
html.kapsule .compose-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  transition: border-color 0.15s, background 0.15s;
  margin: 8px 24px;
}

html.kapsule .compose-drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

html.kapsule .compose-attachments {
  padding: 8px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

html.kapsule .compose-attachment-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 12px;
  color: var(--text-secondary);
}

html.kapsule .compose-attachment-item .remove-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 10px;
  transition: background 0.1s;
}

html.kapsule .compose-attachment-item .remove-btn:hover {
  background: var(--danger);
  color: #fff;
}

/* ── 13. Login page ───────────────────────────────────────── */
html.kapsule body.task-login {
  background: linear-gradient(135deg, var(--bg) 0%, var(--surface-elev) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: auto;
}

html.kapsule body.task-login #login-page {
  width: 100%;
  max-width: 420px;
  padding: 16px;
}

html.kapsule #login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  padding: 40px;
}

html.kapsule #login-card .login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

html.kapsule #login-card .login-logo img,
html.kapsule #login-card .login-logo svg {
  width: 40px;
  height: 40px;
}

html.kapsule #login-card .login-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

html.kapsule #login-card .login-logo-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

html.kapsule #login-card .login-logo-tagline {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

html.kapsule #login-card h1,
html.kapsule #login-card .login-heading {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

html.kapsule #login-card .login-subheading {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

html.kapsule #login-card table {
  width: 100%;
  border-collapse: collapse;
}

html.kapsule #login-card table tr td {
  padding: 0;
  vertical-align: top;
}

html.kapsule #login-card .form-row {
  margin-bottom: 14px;
}

html.kapsule #login-card .form-row label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

html.kapsule #login-card .form-row input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: var(--font-ui);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

html.kapsule #login-card .form-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

html.kapsule #login-card .login-submit,
html.kapsule #login-card input[type="submit"],
html.kapsule #login-card button[type="submit"] {
  width: 100%;
  padding: 11px 24px;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-family: var(--font-ui);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  margin-top: 8px;
}

html.kapsule #login-card .login-submit:hover,
html.kapsule #login-card input[type="submit"]:hover,
html.kapsule #login-card button[type="submit"]:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-sm);
}

html.kapsule #login-card .login-footer-links {
  margin-top: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

html.kapsule #login-card .login-footer-links a {
  color: var(--accent);
  font-weight: 500;
}

html.kapsule #login-card .login-footer-links a:hover {
  color: var(--accent-hover);
}

html.kapsule #login-card .login-error {
  background: rgba(239,68,68,0.07);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--danger);
  margin-bottom: 16px;
}

/* Login task — hide the topbar */
html.kapsule body.task-login #topbar {
  display: none;
}

html.kapsule body.task-login #layout {
  display: none;
}

/* ── 14. Settings page ────────────────────────────────────── */
html.kapsule body.task-settings #layout-content {
  overflow-y: auto;
}

html.kapsule .settings-content {
  padding: 24px;
  max-width: 680px;
}

html.kapsule .settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  margin-bottom: 20px;
  overflow: hidden;
}

html.kapsule .settings-section-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

html.kapsule .settings-section-body {
  padding: 16px 20px;
}

html.kapsule .settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

html.kapsule .settings-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

html.kapsule .settings-row:first-child {
  padding-top: 0;
}

html.kapsule .settings-row-label {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-primary);
}

html.kapsule .settings-row-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

html.kapsule .settings-row-control {
  flex-shrink: 0;
}

/* Settings sidebar nav */
html.kapsule #layout-sidebar .settings-nav {
  padding: 8px 0;
}

html.kapsule #layout-sidebar .settings-nav a,
html.kapsule #layout-sidebar .settings-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 3px solid transparent;
  border: none;
  background: transparent;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.1s, color 0.1s;
}

html.kapsule #layout-sidebar .settings-nav a:hover,
html.kapsule #layout-sidebar .settings-nav button:hover {
  background: var(--surface-elev);
  color: var(--text-primary);
}

html.kapsule #layout-sidebar .settings-nav a.active,
html.kapsule #layout-sidebar .settings-nav button.selected {
  background: var(--accent-subtle);
  color: var(--accent);
  border-left-color: var(--accent);
}

/* ── 15. Address book ─────────────────────────────────────── */
html.kapsule #contacts-list {
  flex: 1;
  overflow-y: auto;
}

html.kapsule .contact-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

html.kapsule .contact-row:hover {
  background: var(--surface-elev);
}

html.kapsule .contact-row.selected {
  background: var(--accent-subtle);
}

html.kapsule .contact-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

html.kapsule .contact-info .contact-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

html.kapsule .contact-info .contact-email {
  font-size: 12px;
  color: var(--text-muted);
}

html.kapsule .contact-detail {
  padding: 24px;
  overflow-y: auto;
}

html.kapsule .contact-detail .contact-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

html.kapsule .contact-detail .contact-avatar-lg {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  flex-shrink: 0;
  border: 2px solid var(--border);
}

html.kapsule .contact-detail .contact-name-large {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

html.kapsule .contact-field {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

html.kapsule .contact-field:last-child {
  border-bottom: none;
}

html.kapsule .contact-field-label {
  font-weight: 500;
  color: var(--text-muted);
  width: 100px;
  flex-shrink: 0;
}

html.kapsule .contact-field-value {
  color: var(--text-primary);
}

/* ── 16. Error page ───────────────────────────────────────── */
html.kapsule body.task-error {
  background: linear-gradient(135deg, var(--bg) 0%, var(--surface-elev) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

html.kapsule #error-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  padding: 48px 40px;
  max-width: 480px;
  width: 100%;
  margin: 16px;
  text-align: center;
}

html.kapsule #error-card .error-icon {
  width: 56px;
  height: 56px;
  background: rgba(239,68,68,0.08);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  color: var(--danger);
}

html.kapsule #error-card .error-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

html.kapsule #error-card .error-message {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 28px;
  line-height: 1.6;
}

html.kapsule #error-card .error-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── 17. Popup menus ──────────────────────────────────────── */
html.kapsule .popupmenu,
html.kapsule ul.popupmenu {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 180px;
  z-index: 500;
  list-style: none;
  margin: 0;
}

html.kapsule .popupmenu li,
html.kapsule ul.popupmenu li {
  margin: 0;
}

html.kapsule .popupmenu li a,
html.kapsule .popupmenu li button,
html.kapsule ul.popupmenu li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 400;
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background 0.1s;
}

html.kapsule .popupmenu li a:hover,
html.kapsule .popupmenu li button:hover,
html.kapsule ul.popupmenu li a:hover {
  background: var(--surface-elev);
  text-decoration: none;
}

html.kapsule .popupmenu li.separator,
html.kapsule ul.popupmenu li.separator {
  height: 1px;
  background: var(--border);
  margin: 4px 8px;
  padding: 0;
}

html.kapsule .popupmenu li.danger a,
html.kapsule .popupmenu li.danger button {
  color: var(--danger);
}

html.kapsule .popupmenu li.danger a:hover,
html.kapsule .popupmenu li.danger button:hover {
  background: rgba(239,68,68,0.07);
}

/* ── 18. Quota widget (sidebar) ───────────────────────────── */
html.kapsule #quotadisplay .quota-text {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  justify-content: space-between;
}

html.kapsule #quotadisplay .quota-used {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ── 19. Empty states ─────────────────────────────────────── */
html.kapsule .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  flex: 1;
  min-height: 240px;
}

html.kapsule .empty-state-icon {
  width: 56px;
  height: 56px;
  background: var(--surface-elev);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  margin-bottom: 16px;
}

html.kapsule .empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

html.kapsule .empty-state-desc {
  font-size: 13.5px;
  color: var(--text-muted);
  max-width: 280px;
  line-height: 1.6;
  margin-bottom: 20px;
}

/* ── 20. Status badges ────────────────────────────────────── */
html.kapsule .badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 16px;
}

html.kapsule .badge-success {
  background: rgba(16,185,129,0.1);
  color: #059669;
}

html.kapsule .badge-warning {
  background: rgba(245,158,11,0.1);
  color: #d97706;
}

html.kapsule .badge-danger {
  background: rgba(239,68,68,0.1);
  color: var(--danger);
}

html.kapsule .badge-info {
  background: var(--accent-subtle);
  color: var(--accent);
}

html.kapsule .badge-neutral {
  background: var(--surface-elev);
  color: var(--text-secondary);
}

/* ── 21. Alerts / notifications ───────────────────────────── */
html.kapsule .alert {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  margin-bottom: 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

html.kapsule .alert-success {
  background: rgba(16,185,129,0.08);
  border: 1px solid rgba(16,185,129,0.2);
  color: #065f46;
}

html.kapsule .alert-warning {
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.2);
  color: #92400e;
}

html.kapsule .alert-danger {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  color: #991b1b;
}

html.kapsule .alert-info {
  background: var(--accent-subtle);
  border: 1px solid rgba(20,188,207,0.2);
  color: #0e7490;
}

/* Message status bar (Roundcube uses div#messagebox) */
html.kapsule #messagebox,
html.kapsule .statusbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 20px;
  font-size: 13px;
  color: var(--text-secondary);
  display: none;
}

html.kapsule #messagebox.show,
html.kapsule .statusbar.show {
  display: block;
}

/* ── 22. Responsive ───────────────────────────────────────── */
@media (max-width: 1024px) {
  html.kapsule {
    --list-w: 320px;
    --sidebar-w: 200px;
  }
}

@media (max-width: 768px) {
  html.kapsule #layout {
    flex-direction: column;
  }

  html.kapsule #layout-sidebar {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    overflow-x: auto;
    flex-shrink: 0;
  }

  html.kapsule #layout-list {
    width: 100%;
    max-width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    height: 40vh;
  }

  html.kapsule #layout-content {
    flex: 1;
    height: auto;
  }

  html.kapsule #topbar .logo-wordmark,
  html.kapsule #topbar .user-email {
    display: none;
  }

  html.kapsule #topbar .search-wrapper {
    max-width: none;
  }

  html.kapsule #login-card {
    padding: 28px 20px;
  }

  html.kapsule .settings-content {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  html.kapsule #topbar {
    padding: 0 10px;
    gap: 8px;
  }

  html.kapsule #topbar .btn-compose span {
    display: none;
  }

  html.kapsule #login-card {
    padding: 24px 16px;
    border-radius: var(--radius-xl);
  }
}

/* ── 23. Print ────────────────────────────────────────────── */
@media print {
  html.kapsule #topbar,
  html.kapsule #layout-sidebar,
  html.kapsule #layout-list,
  html.kapsule .compose-footer,
  html.kapsule .toolbar-btn,
  html.kapsule #messagebox {
    display: none !important;
  }

  html.kapsule #layout {
    display: block;
    position: static;
    top: 0;
  }

  html.kapsule #layout-content {
    width: 100%;
  }

  html.kapsule #messagecontframe {
    display: none;
  }

  html.kapsule .message-body-wrap {
    padding: 0;
    overflow: visible;
  }

  html.kapsule body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  html.kapsule a[href]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #666;
  }
}

/* ── 24. Accessibility ────────────────────────────────────── */
html.kapsule :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

html.kapsule .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html.kapsule .skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 8px 16px;
  border-radius: 0 0 var(--radius-md) 0;
  font-weight: 500;
  z-index: 9999;
  text-decoration: none;
  transition: top 0.15s;
}

html.kapsule .skip-link:focus {
  top: 0;
}

/* Spinner / loading state */
html.kapsule .loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: kap-spin 0.7s linear infinite;
}

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

/* ── Miscellaneous overrides ──────────────────────────────── */
html.kapsule .ui-widget {
  font-family: var(--font-ui);
}

/* Elastic overrides — hide elastic header/footer */
html.kapsule #header,
html.kapsule #footer {
  display: none !important;
}

/* Override elastic's app_name class */
html.kapsule .app-name {
  display: none;
}

/* Folder expand/collapse toggle */
html.kapsule ul.treelist li .expando {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.15s;
}

html.kapsule ul.treelist li.expanded > a .expando {
  transform: rotate(90deg);
}

html.kapsule ul.treelist ul {
  display: none;
}

html.kapsule ul.treelist li.expanded > ul {
  display: block;
}

/* Drag indicator */
html.kapsule .drag-active {
  opacity: 0.5;
}

html.kapsule .drop-target {
  background: var(--accent-subtle) !important;
  border-color: var(--accent) !important;
}

/* Tooltip */
html.kapsule [title]:not([title=""]) {
  cursor: help;
}

/* Divider */
html.kapsule .divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

/* Table in settings (key-value) */
html.kapsule table.propform {
  width: 100%;
  border-collapse: collapse;
}

html.kapsule table.propform td {
  padding: 8px 0;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

html.kapsule table.propform td:first-child {
  width: 180px;
  font-weight: 500;
  color: var(--text-secondary);
  padding-right: 20px;
}

html.kapsule table.propform tr:last-child td {
  border-bottom: none;
}

/* Input row with label inline */
html.kapsule .input-group {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

html.kapsule .input-group-addon {
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--surface-elev);
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
}

html.kapsule .input-group input {
  border: none;
  border-radius: 0;
  flex: 1;
}

html.kapsule .input-group input:focus {
  box-shadow: none;
}

/* Folders table */
html.kapsule table.records-table {
  width: 100%;
  border-collapse: collapse;
}

html.kapsule table.records-table thead th {
  padding: 8px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-elev);
}

html.kapsule table.records-table tbody td {
  padding: 10px 12px;
  font-size: 13.5px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

html.kapsule table.records-table tbody tr:hover {
  background: var(--surface-elev);
}

html.kapsule table.records-table tbody tr.selected {
  background: var(--accent-subtle);
}

html.kapsule table.records-table tbody tr:last-child td {
  border-bottom: none;
}

/* Pagination counter text */
html.kapsule .pagenav .pagenav-text {
  color: var(--text-muted);
  font-size: 12px;
  padding: 0 8px;
}

/* Iframe for composed message preview - none by default */
html.kapsule .task-compose #layout-list {
  display: none;
}

/* Compose task layout */
html.kapsule body.task-compose #layout-sidebar {
  display: none;
}
