* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

/* Dark Theme Backgrounds & Text */
body,
html {
    height: 100%;
    background-color: #121212;
    color: #e0e0e0;
}

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar List */
.email-list-container {
    width: 350px;
    background: #1e1e1e;
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.email-item {
    padding: 15px;
    border-bottom: 1px solid #2c2c2c;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

@media (hover: hover) {
  .email-item:hover {
    background: #2a2a2a;
  }
}
.email-item.active {
    background: #2e1a10;
    border-left: 4px solid #f5934e;
    padding-left: 11px;
}

.email-sender {
    flex: 1;
    min-width: 0;
    font-weight: 400;
    font-size: 12px;
    color: #ffffff;
    word-break: break-word;
}
.email-date {
    flex-shrink: 0;
    font-size: 12px;
    color: #aaaaaa;
    white-space: nowrap;
    margin-left: 8px;
}
.email-title {
    font-size: 14px;
    font-weight: 500;
    color: #dddddd;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.email-preview {
    font-size: 13px;
    color: #888888;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

#load-more-btn {
    margin: 15px;
    padding: 10px;
    cursor: pointer;
    background: #f5934e;
    color: white;
    border: none;
    border-radius: 4px;
    font-weight: 500;
}
@media (hover: hover) {
  #load-more-btn:hover {
    background: #2980b9;
  }
}
#loading-indicator {
    padding: 20px;
    text-align: center;
    color: #888;
    font-size: 14px;
}

/* Main Viewer Canvas */
.email-viewer-container {
    flex: 1;
    background: #121212;
    display: flex;
    flex-direction: column;
    padding: 1vw;
}

#viewer-placeholder {
    margin: auto;
    color: #666;
    font-size: 18px;
}
#viewer-content {
    padding: 30px;
    overflow-y: auto;
    height: 100%;
}

#view-subject {
    font-size: 24px;
    color: #ffffff;
    margin-bottom: 15px;
}
.meta-info {
    font-size: 14px;
    color: #bbbbbb;
    margin-bottom: 20px;
    line-height: 1.5;
}
hr {
    border: 0;
    border-top: 1px solid #333;
    margin-bottom: 20px;
}

/* Das Canvas für E-Mails */
.mail-canvas {
    font-size: 15px;
    color: #e0e0e0;
    line-height: 1.6;
}

/* Da echte HTML E-Mails oft schwarze Schrift haben, überschreiben wir das für den Darkmode */
.mail-canvas * {
    color: inherit !important;
    background-color: transparent !important;
}
.mail-canvas a {
    color: #f5934e !important;
}

/* Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    background: #1e1e1e;
    border-bottom: 1px solid #333;
}
.tab-btn {
    flex: 1;
    padding: 12px;
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: 0.2s;
}
@media (hover: hover) {
  .tab-btn:hover {
    color: #ddd;
  }
}
.tab-btn.active {
    color: #f5934e;
    border-bottom: 2px solid #f5934e;
    background: #252525;
}

/* Contacts UI */
.sort-controls {
    display: flex;
    padding: 10px 15px;
    gap: 10px;
    border-bottom: 1px solid #333;
    background: #252525;
}
.sort-controls select {
    flex: 1;
    padding: 5px;
    background: #121212;
    color: #ddd;
    border: 1px solid #444;
    border-radius: 4px;
}
.sort-controls button {
    background: transparent;
    border: 1px solid #444;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
}
@media (hover: hover) {
  .sort-controls button:hover {
    background: #333;
  }
}

.contact-item {
    padding: 15px;
    border-bottom: 1px solid #2c2c2c;
}
.contact-name {
    font-weight: 600;
    font-size: 15px;
    color: #ffffff;
    margin-bottom: 4px;
}
.contact-meta {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: #aaaaaa;
    gap: 2px;
}
.contact-meta strong {
    color: #f5934e;
    font-weight: 500;
}

/* Contact Canvas */
.action-btn {
    height: 32px;
    padding: 0 12px;
    background: #f5934e;
    color: #1a1a1a;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    vertical-align: middle;
}
@media (hover: hover) {
  .action-btn:hover {
    background: #d4703a;
  }
}
.contact-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}
.contact-input-lg {
    flex: 1;
    background: transparent;
    border: 1px solid transparent;
    color: #fff;
    font-size: 16px;
    font-weight: normal;
    padding: 15px;
    outline: none;
    transition: border 0.2s;
}
.contact-input-lg:focus {
    border-bottom: 1px solid #f5934e;
}
@media (hover: hover) {
  .contact-input-lg:hover {
    border-bottom: 1px solid #f5934e;
  }
}
.save-status {
    font-size: 12px;
    color: #888;
    margin-left: 15px;
    transition: color 0.3s;
}
.save-status.saving {
    color: #f39c12;
}

.contact-split-view {
    display: flex;
    gap: 30px;
    height: calc(100% - 150px);
}
.contact-notes-area {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.contact-notes-area h3,
.contact-history-area h3 {
    color: #ddd;
    margin-bottom: 10px;
    font-size: 16px;
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
}
#contact-edit-notes {
    flex: 1;
    background: #1a1a1a;
    border: 1px solid #333;
    color: #e0e0e0;
    padding: 15px;
    border-radius: 4px;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.5;
}
#contact-edit-notes:focus {
    border-color: #f5934e;
}

.contact-history-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.thread-item {
    padding: 10px;
    background: #1e1e1e;
    border: 1px solid #333;
    margin-bottom: 10px;
    border-radius: 4px;
    cursor: pointer;
}
@media (hover: hover) {
  .thread-item:hover {
    border-color: #f5934e;
  }
}
.thread-date {
    font-size: 11px;
    color: #888;
    margin-bottom: 3px;
}
.thread-subject {
    font-size: 13px;
    color: #ddd;
    font-weight: 500;
}

.thread-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
    margin-bottom: 15px;
}
.thread-actions h3 {
    border: none;
    padding: 0;
    margin: 0;
}
.thread-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}
.control-btn {
    background: #252525;
    border: 1px solid #444;
    color: #ddd;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}
@media (hover: hover) {
  .control-btn:hover {
    background: #333;
  }
}
.action-btn.small {
    height: 26px;
    padding: 0 8px;
    font-size: 0.8em;
}
.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}
.select-all-label {
    font-size: 12px;
    color: #ddd;
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

/* Thread Item Styling für Split-View */
.thread-item {
    padding: 10px;
    background: #1e1e1e;
    border: 1px solid #333;
    margin-bottom: 10px;
    border-radius: 4px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
@media (hover: hover) {
  .thread-item:hover {
    border-color: #555;
  }
}
.thread-checkbox {
    margin-top: 4px;
    cursor: pointer;
}
.thread-content {
    flex: 1;
    cursor: pointer;
    overflow: hidden;
}
.thread-body-preview {
    display: none;
    padding-top: 8px;
    margin-top: 8px;
    border-top: 1px dashed #333;
    font-size: 13px;
    color: #999;
    line-height: 1.5;
    white-space: pre-wrap;
}
.thread-body-preview.expanded {
    display: block;
}

/* Contact Split View Fix */
#contact-viewer-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.contact-split-view {
    display: flex;
    gap: 30px;
    flex: 1;
    min-height: 0;
    margin-top: 15px;
}

.contact-notes-area {
    flex: 1;
    display: flex;
    flex-direction: column;
}
#contact-edit-notes {
    flex: 1;
    background: #1a1a1a;
    border: 1px solid #333;
    color: #e0e0e0;
    padding: 15px;
    border-radius: 4px;
    resize: none;
    outline: none;
    line-height: 1.5;
}

.contact-history-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
#contact-email-thread {
    flex: 1;
    overflow-y: auto;
    padding-right: 10px;
} /* Hier passiert die Magie */

/* Rule Manager UI */
.rule-item {
    background: #252525;
    border: 1px solid #333;
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.rule-item-title {
    font-weight: 600;
    color: #ddd;
    font-size: 14px;
    margin-bottom: 4px;
}
.rule-item-meta {
    font-size: 11px;
    color: #888;
}
.rule-btn-group {
    display: flex;
    gap: 5px;
}

.rule-label {
    display: block;
    font-size: 12px;
    color: #aaa;
    margin-bottom: 5px;
    margin-top: 10px;
    font-weight: 500;
}
.rule-input,
.rule-select {
    width: 100%;
    background: #121212;
    border: 1px solid #444;
    color: #eee;
    padding: 8px;
    border-radius: 4px;
    outline: none;
    font-size: 13px;
}
.rule-input:focus,
.rule-select:focus {
    border-color: #f5934e;
}

.rule-row {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
    background: #222;
    padding: 8px;
    border-radius: 4px;
    border: 1px dashed #444;
    align-items: center;
}
.rule-row select,
.rule-row input {
    flex: 1;
    padding: 5px;
    font-size: 12px;
}
.rule-row .delete-row-btn {
    background: #c0392b;
    border: none;
    color: white;
    padding: 5px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}
@media (hover: hover) {
  .rule-row .delete-row-btn:hover {
    background: #e74c3c;
  }
}

/* Rule Canvas Layout */
.rule-split-layout {
    display: flex;
    gap: 30px;
}
.rule-column {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.rule-column h3 {
    color: #ddd;
    margin-bottom: 15px;
    font-size: 16px;
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
}

/* Vorhandene Rule-Klassen (falls noch nicht drin) */
.rule-item {
    background: #1e1e1e;
    border: 1px solid #333;
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: 0.2s;
}
@media (hover: hover) {
  .rule-item:hover {
    border-color: #f5934e;
  }
}
.rule-item.active {
    background: #2e1a10;
    border-left: 4px solid #f5934e;
}
.rule-item-title {
    font-weight: 600;
    color: #ddd;
    font-size: 14px;
    margin-bottom: 4px;
}
.rule-item-meta {
    font-size: 11px;
    color: #888;
}

.rule-label {
    display: block;
    font-size: 12px;
    color: #aaa;
    margin-bottom: 5px;
    font-weight: 500;
}
.rule-input,
.rule-select {
    width: 100%;
    background: #121212;
    border: 1px solid #444;
    color: #eee;
    padding: 8px;
    border-radius: 4px;
    outline: none;
    font-size: 13px;
}
.rule-input:focus,
.rule-select:focus {
    border-color: #f5934e;
}

.rule-row {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
    background: #252525;
    padding: 8px;
    border-radius: 4px;
    align-items: center;
}
.rule-row select,
.rule-row input {
    flex: 1;
    padding: 6px;
    font-size: 12px;
}
.rule-row .delete-row-btn {
    background: #c0392b;
    border: none;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}
@media (hover: hover) {
  .rule-row .delete-row-btn:hover {
    background: #e74c3c;
  }
}

/* --- Layout & Utilities --- */
.hidden {
    display: none !important;
}
.flex-col {
    display: flex;
    flex-direction: column;
}
.w-100 {
    width: 100%;
}
.h-100 {
    height: 100%;
}
.overflow-y-auto {
    overflow-y: auto;
}

/* Spacing */
.p-15 {
    padding: 15px;
}
.p-30 {
    padding: 30px;
}
.mb-15 {
    margin-bottom: 15px;
}
.mb-20 {
    margin-bottom: 20px;
}
.mb-30 {
    margin-bottom: 30px;
}
.mt-0 {
    margin-top: 0;
}
.gap-12 {
    gap: 12px;
}

/* Flexbox Alignments */
.flex-right {
    display: flex;
    justify-content: flex-end;
}
.flex-center-y {
    display: flex;
    align-items: center;
}

/* --- Komponenten --- */
.panel-card {
    background: #1e1e1e;
    padding: 25px;
    border-radius: 4px;
    border: 1px solid #333;
}
.list-container-dark {
    background: #121212;
    padding: 15px;
    border-radius: 4px;
    border: 1px inset #222;
    min-height: 100px;
}
.divider {
    border-color: #333;
}

/* Typografie */
.header-h2 {
    margin: 0;
    color: #fff;
    font-size: 24px;
}
.header-h3 {
    color: #ddd;
    margin-top: 0;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
    font-size: 16px;
}
.text-description {
    color: #aaa;
    font-size: 13px;
    line-height: 1.6;
}
.text-empty {
    color: #666;
    font-size: 13px;
    text-align: center;
    padding: 20px;
    font-style: italic;
}
.text-error {
    color: #e74c3c;
}
.text-success {
    color: #f5934e;
}
.badge-success {
    font-size: 10px;
    color: #f5934e;
    margin-left: 10px;
}

/* Spezifische UI Elemente */
.thread-content.is-exported {
    border-color: #1a5629;
}
.folder-item {
    cursor: pointer;
    color: #ddd;
}

/* --- Regel-Editor Split-Layout --- */
.rule-split-layout {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}
.rule-column-left {
    flex: 1;
    min-width: 250px;
}
.rule-column-right {
    flex: 2;
    display: flex;
    flex-direction: column;
    gap: 30px;
}
.folder-list-scrollable {
    max-height: 450px;
    overflow-y: auto;
    flex-grow: 1;
}
.border-bottom-dark {
    border-bottom: 1px solid #333;
    padding-bottom: 15px;
    margin-bottom: 15px;
}

.sender-name {
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sender-email {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-item .email-title {
    font-size: 12px;
    color: #ccc;
    display: -webkit-box;
    -webkit-line-clamp: 1; /* Begrenzt auf eine Zeile */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.attachment-link {
    display: inline-block;
    background: #222;
    color: #55afff;
    padding: 5px 10px;
    border-radius: 4px;
    text-decoration: none;
    margin: 5px 0;
    border: 1px solid #333;
}

@media (hover: hover) {
  .attachment-link:hover {
    background: #333;
    border-color: #55afff;
  }
}

.badge-archive {
    margin-right: 5px;
    cursor: help;
}
.badge-server {
    margin-right: 5px;
    opacity: 0.5;
    cursor: help;
}

/* Container für den Dialog */
#contact-email-thread {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 10px;
}

.thread-item {
    display: flex;
    margin-bottom: 10px;
    width: 100%;
}
.thread-bubble {
    max-width: 80%;
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
}

/* Empfangen (von Johanna) -> Links, Grau */
.thread-received {
    justify-content: flex-start;
}
.thread-received .thread-bubble {
    background: #333;
    color: white;
    border-bottom-left-radius: 2px;
}

/* Gesendet (von mir an Johanna) -> Rechts, Blau */
.thread-sent {
    justify-content: flex-end;
}
.thread-sent .thread-bubble {
    background: #d4703a;
    color: white;
    border-bottom-right-radius: 2px;
    text-align: right;
}

.thread-meta {
    font-size: 0.7em;
    opacity: 0.7;
    margin-bottom: 5px;
}

.thread-body-preview {
    display: none; /* Standardmäßig zu */
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
    line-height: 1.4;
    overflow-wrap: break-word;
    text-align: left;
}

.thread-body-preview.expanded {
    display: block; /* Zeigen wenn ausgeklappt */
}

.thread-bubble {
    transition: all 0.2s ease;
}

.thread-item {
    display: flex;
    margin-bottom: 15px;
    width: 100%;
}
.thread-bubble {
    max-width: 85%;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    position: relative;
}

/* Empfangen (Grau, links) */
.thread-received {
    justify-content: flex-start;
}
.thread-received .thread-bubble {
    background: #333;
    color: #fff;
    border-bottom-left-radius: 2px;
}

/* Gesendet (Blau, rechts) */
.thread-sent {
    justify-content: flex-end;
}
.thread-sent .thread-bubble {
    background: #d4703a;
    color: #fff;
    border-bottom-right-radius: 2px;
    text-align: right;
}

.thread-meta {
    font-size: 0.75rem;
    opacity: 0.6;
    margin-bottom: 5px;
}
.thread-body-preview {
    display: none;
    margin-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 10px;
    text-align: left;
}
.thread-body-preview.expanded {
    display: block;
}

#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.login-box {
    background: #222;
    padding: 30px;
    border-radius: 8px;
    border: 1px solid #444;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 300px;
}

.login-box h2 {
    margin: 0 0 10px 0;
    font-size: 1.2rem;
}
.login-box input {
    padding: 10px;
    background: #111;
    border: 1px solid #444;
    color: white;
    border-radius: 4px;
}
.login-box button {
    padding: 10px;
    background: #d4703a;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
.error-text {
    color: #ff4444;
    font-size: 0.85rem;
}

#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    display: none; /* Wird per JS auf 'flex' gesetzt */
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

#login-overlay.active {
    display: flex !important;
}

/* Contact Create Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
}

.modal-overlay.hidden {
    display: none;
}

.modal-box {
    background: #222;
    padding: 28px;
    border-radius: 8px;
    border: 1px solid #444;
    min-width: 340px;
    max-width: 440px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-box h3 {
    margin: 0 0 6px;
    font-size: 1.1rem;
}

.modal-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.modal-field label {
    font-size: 0.8rem;
    color: #aaa;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 8px;
}

/* Utility classes */
.mt-10 { margin-top: 10px; }
.flex-row { display: flex; flex-direction: row; }

/* Compose Panel */
.tab-btn-compose {
    background: #d4703a;
    color: white;
    font-size: 1rem;
    flex: 0 0 auto;
    padding: 8px 12px;
}

@media (hover: hover) {
  .tab-btn-compose:hover {
    background: #b35c28;
  }
}

.compose-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}

.compose-field label {
    font-size: 0.8rem;
    color: #aaa;
}

.compose-field-grow {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 180px;
}

.compose-field-grow .compose-textarea {
    flex: 1;
}

.compose-textarea {
    width: 100%;
    min-height: 180px;
    background: #111;
    border: 1px solid #444;
    color: #e0e0e0;
    padding: 10px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
    resize: vertical;
}

.compose-textarea:focus {
    outline: none;
    border-color: #d4703a;
}

.compose-field-links {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

.compose-toggle-link {
    font-size: 0.8rem;
    color: #aaa;
    text-decoration: none;
}

@media (hover: hover) {
  .compose-toggle-link:hover {
    color: #e0e0e0;
  }
}

.compose-attachments {
    margin-top: 8px;
}

.compose-attachment-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.compose-attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.82rem;
}

.compose-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #333;
}

.archive-file-item {
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.88rem;
}

@media (hover: hover) {
  .archive-file-item:hover {
    background: #2a2a2a;
  }
}

@media (hover: hover) {
  .sender-link:hover { opacity: 0.8; }
}

/* Thread action buttons (Kommunikation tab) */
.thread-actions-bar {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #333;
    text-align: left;
}

.thread-action-btn {
    background: #2a2a2a;
    color: #ccc;
    border: 1px solid #444;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
}

@media (hover: hover) {
  .thread-action-btn:hover {
    background: #3a3a3a;
    color: #fff;
  }
}

/* ── Contact Search ─────────────────────────────────── */
#contact-search {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 10px;
    background: #1e1e1e;
    color: #ddd;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 0.9em;
    margin-bottom: 8px;
    outline: none;
}

#contact-search::placeholder {
    color: #666;
}

/* ── Mail Attachment Bar ────────────────────────────── */
.mail-attachments-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 0;
    border-top: 1px solid #333;
    margin-top: 10px;
}

.mail-attachment-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #1e1e1e;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.85em;
}

.mail-attachment-name {
    color: #ccc;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-attachment-btn {
    background: #2a2a2a;
    color: #aaa;
    border: 1px solid #444;
    border-radius: 3px;
    padding: 2px 7px;
    cursor: pointer;
    font-size: 0.85em;
    text-decoration: none;
    display: inline-block;
}

@media (hover: hover) {
  .mail-attachment-btn:hover {
    background: #3a3a3a;
    color: #fff;
  }
}

#contact-search:focus {
    border-color: #666;
}

/* ── Unread indicator ───────────────────────────────── */
.email-item.is-unread .email-title {
    font-weight: 600;
    color: #ffffff;
}


/* ── Email list delete button ───────────────────────── */
.email-delete-btn {
    display: none;
    position: absolute;
    right: 4px;
    top: 8px;
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 1em;
    padding: 2px 5px;
    border-radius: 3px;
    line-height: 1;
}

@media (hover: hover) {
  .email-item:hover .email-delete-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

@media (hover: hover) {
  .email-delete-btn:hover {
    color: #e05c5c;
    background: #2a2a2a;
  }
}

/* ── Toast notifications ────────────────────────────── */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 10px 16px;
    border-radius: 4px;
    font-size: 0.9em;
    z-index: 1000;
    animation: toast-fadeout 3s forwards;
}
.toast:not(.toast-undo) {
    pointer-events: none;
}
.toast-undo {
    animation: toast-fadeout 5s forwards;
}
.toast-error {
    background: #5c2020;
    color: #ffd4d4;
    border: 1px solid #8c3030;
}
.toast-info {
    background: #1e2e1e;
    color: #8f8;
    border: 1px solid #3a5a3a;
}
.toast-undo {
    background: #2a2a2a;
    color: #fff;
    border: 1px solid #444;
    display: flex;
    align-items: center;
    gap: 12px;
}
.toast-undo-btn {
    background: transparent;
    color: #f5934e;
    border: 1px solid #f5934e;
    padding: 4px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
}
@media (hover: hover) {
  .toast-undo-btn:hover {
    background: #f5934e;
    color: #1a1a1a;
  }
}
@keyframes toast-fadeout {
    0%   { opacity: 1; }
    70%  { opacity: 1; }
    100% { opacity: 0; }
}

/* ── Email list layout ──────────────────────────────── */
.email-row {
    display: flex;
    align-items: flex-start;
    padding-right: 28px;
}

.email-dot-col {
    width: 12px;
    flex-shrink: 0;
    padding-top: 3px;
    display: flex;
    justify-content: center;
}

.unread-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #f5934e;
    flex-shrink: 0;
}

.email-main {
    flex: 1;
    min-width: 0;
}

.email-header {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 4px;
}

/* ── Bulk selection ─────────────────────────────────── */
.email-checkbox {
    margin-right: 6px;
    margin-top: 4px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 120ms ease;
    accent-color: #f5934e;
    cursor: pointer;
}
.email-checkbox:checked {
    opacity: 1;
}
@media (hover: hover) {
  .email-item:hover .email-checkbox {
    opacity: 1;
  }
}
.bulk-bar {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #1a1a1a;
    border-top: 1px solid #333;
    z-index: 10;
}
.bulk-count {
    flex: 1;
    font-size: 12px;
    color: #ccc;
}
.bulk-cancel {
    background: transparent;
    color: #ccc;
    border: 1px solid #444;
}
@media (hover: hover) {
  .bulk-cancel:hover {
    background: #333;
    color: #fff;
  }
}

/* ── Keyboard focus + shortcut help ─────────────────── */
.email-item.is-kbd-focus {
    outline: 2px solid #f5934e;
    outline-offset: -2px;
}
.shortcut-help {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.shortcut-help.hidden {
    display: none;
}
.shortcut-help-inner {
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 20px 24px;
    min-width: 340px;
    color: #eee;
}
.shortcut-help-inner h3 {
    margin: 0 0 12px;
    color: #f5934e;
}
.shortcut-help-inner table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 14px;
}
.shortcut-help-inner td {
    padding: 4px 8px;
    font-size: 0.9em;
}
.shortcut-help-inner kbd {
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 3px;
    padding: 1px 6px;
    font-family: monospace;
    font-size: 0.85em;
}

/* =========================================================
   Mobile layout (≤900px): single-pane list/detail
   ========================================================= */
@media (max-width: 900px) {
  .app-container {
    display: block;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .email-list-container,
  .email-viewer-container {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border-right: none;
    transition: transform 0.25s ease;
    will-change: transform;
  }

  /* Default: list visible, viewer off-screen to the right */
  .email-list-container {
    transform: translateX(0);
    z-index: 2;
  }
  .email-viewer-container {
    transform: translateX(100%);
    z-index: 3;
    padding: 0;
  }

  /* When a viewer is open: slide list out, slide viewer in */
  body.viewer-open .email-list-container {
    transform: translateX(-100%);
  }
  body.viewer-open .email-viewer-container {
    transform: translateX(0);
  }

  /* Sticky sidebar header: tabs + search stick at top of list */
  .email-list-container > div:first-child > .sidebar-tabs,
  .email-list-container > div:first-child > .p-15.border-bottom-dark {
    position: sticky;
    top: 0;
    z-index: 4;
    background: #1e1e1e;
  }
  .email-list-container > div:first-child > .sidebar-tabs {
    top: 0;
  }
  .email-list-container > div:first-child > .p-15.border-bottom-dark {
    top: 44px;
  }

  /* Hide the old sidebar footer (Cache leeren); moves into overflow menu (Task 4) */
  .email-list-container > div:last-child {
    display: none;
  }

  /* Viewer internals: use full viewport width, reduce padding */
  #viewer-content,
  #contact-viewer-content,
  #rule-viewer-content,
  #compose-viewer-content {
    padding: 15px !important;
  }

  /* Modals go full-screen */
  .modal-overlay .modal-box {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    border-radius: 0;
    margin: 0;
    overflow-y: auto;
  }

  /* Respect reduced motion */
  @media (prefers-reduced-motion: reduce) {
    .email-list-container,
    .email-viewer-container {
      transition: none;
    }
  }
}

.back-btn {
  display: none;
  background: transparent;
  border: none;
  color: #f5934e;
  font-size: 22px;
  line-height: 1;
  padding: 8px 12px;
  margin-right: 8px;
  cursor: pointer;
  border-radius: 4px;
}
@media (hover: hover) {
  .back-btn:hover {
    background: #2a2a2a;
  }
}
@media (max-width: 900px) {
  .back-btn {
    display: inline-flex;
    align-items: center;
  }
}

.tab-btn-overflow {
  flex: 0 0 auto;
  padding: 12px 14px;
  font-size: 20px;
  line-height: 1;
}

/* Hide overflow button on desktop (footer still visible there) */
@media (min-width: 901px) {
  .tab-btn-overflow,
  #overflow-menu {
    display: none !important;
  }
}

.overflow-menu {
  position: absolute;
  right: 8px;
  top: 44px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  padding: 6px;
  z-index: 10;
  min-width: 220px;
}
.overflow-menu.hidden {
  display: none;
}
.overflow-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: #e0e0e0;
  padding: 10px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}
@media (hover: hover) {
  .overflow-menu-item:hover {
    background: #2a2a2a;
  }
}

/* =========================================================
   Touch-target sizing (any coarse-pointer device)
   ========================================================= */
@media (pointer: coarse) {
  .action-btn,
  .control-btn {
    min-height: 44px;
    padding: 0 14px;
    font-size: 14px;
  }
  .action-btn.small {
    min-height: 36px;
  }

  .tab-btn {
    min-height: 48px;
    font-size: 15px;
  }

  .email-item {
    padding: 18px 16px;
  }

  .back-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 24px;
  }

  /* Prevent iOS auto-zoom on input focus */
  html { font-size: 16px; }
  input, textarea, select {
    font-size: 16px !important;
  }

  /* Enlarge checkbox tap target via wrapping label */
  label.folder-item,
  .select-all-label {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* Keyboard-shortcut help button is pointless on touch */
  #shortcut-help-trigger {
    display: none !important;
  }
}

@media (pointer: coarse) {
  .email-item:active { background: #2a2a2a; }
  .action-btn:active { background: #d4703a; }
  .control-btn:active { background: #333; }
  .tab-btn:active { color: #ddd; }
}

/* Safe-area insets for fixed bars and viewer headers on mobile */
@media (max-width: 900px) {
  .email-list-container,
  .email-viewer-container {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  #bulk-bar {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  /* Undo toast is created in JS with inline styles; see Task 11 if it
     needs safe-area. For now the spec accepts bottom:16px which is
     usually above the home indicator. */
}

/* Wide HTML emails must not break the layout */
.mail-canvas {
  max-width: 100%;
  overflow-x: auto;
}
.mail-canvas img,
.mail-canvas table {
  max-width: 100%;
  height: auto;
}

@media (max-width: 900px) {
  /* Contact split view: notes above, communication thread below */
  .contact-split-view {
    flex-direction: column;
    gap: 16px;
    height: auto;
  }
  .contact-notes-area,
  .contact-history-area {
    flex: none;
    width: 100%;
  }
  #contact-edit-notes {
    min-height: 140px;
  }

  /* Rule editor: folders above, conditions+actions below */
  .rule-split-layout {
    flex-direction: column;
    gap: 16px;
  }
  .rule-column-left,
  .rule-column-right {
    width: 100%;
  }
  .folder-list-scrollable {
    max-height: 200px;
  }

  /* Rule row (condition / action) wraps on narrow screens */
  .rule-row {
    flex-wrap: wrap;
  }
  .rule-row select,
  .rule-row input {
    flex: 1 1 140px;
  }
}

/* Swipe-to-delete reveal layer (shown behind .email-item as it slides) */
.email-item {
  position: relative;
}
.email-item::before {
  content: "🗑";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 24px;
  background: #c0392b;
  color: white;
  font-size: 20px;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}
.email-item.swiping::before {
  opacity: 1;
}
