/* ============================================
   Mailbox — App-specific styles
   Extends pibico.css
   ============================================ */

/* --- App Layout --- */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--pibico-light-grey);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* --- Header (card style) --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    margin: 8px 16px 0;
    background: var(--pibico-grad-primary);
    color: var(--pibico-white);
    font-family: var(--pibico-font-heading);
    font-weight: 600;
    font-size: 1.1rem;
    position: sticky;
    top: 8px;
    z-index: 100;
    border-radius: var(--pibico-radius);
    box-shadow: var(--pibico-card-shadow);
}
.app-header-title { display: flex; align-items: center; gap: 8px; }
.app-header-title svg {
    width: 22px; height: 22px; stroke: currentColor; fill: none;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.app-header-actions { display: flex; gap: 6px; }
.app-header-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: var(--pibico-white);
    border-radius: var(--pibico-radius-xs);
    padding: 6px 8px;
    cursor: pointer;
    display: flex; align-items: center;
    transition: background 0.2s ease;
}
.app-header-btn:hover { background: rgba(255,255,255,0.25); }
.app-header-btn.active { background: rgba(255,255,255,0.35); }
.app-header-btn svg {
    width: 18px; height: 18px; stroke: currentColor; fill: none;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.app-header-link {
    background: rgba(255,255,255,0.15);
    border: none;
    color: var(--pibico-white);
    border-radius: var(--pibico-radius-xs);
    padding: 4px 10px;
    cursor: pointer;
    display: flex; align-items: center; gap: 4px;
    font-size: 0.75rem; font-weight: 500;
    text-decoration: none;
    transition: background 0.2s ease;
}
.app-header-link:hover { background: rgba(255,255,255,0.25); }
.app-header-link svg {
    width: 16px; height: 16px; stroke: currentColor; fill: none;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* --- Main --- */
.app-main {
    flex: 1;
    padding: 16px;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    overflow-y: auto;
}

/* --- Footer (card style) --- */
.app-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 16px;
    margin: 0 16px 8px;
    background: var(--pibico-white);
    font-size: 0.75rem;
    color: var(--pibico-grey-dark);
    border-radius: var(--pibico-radius);
    box-shadow: var(--pibico-card-shadow);
}
.app-footer a {
    color: var(--pibico-steel-blue);
    text-decoration: none;
    font-weight: 500;
}
.app-footer a:hover { text-decoration: underline; }
.app-footer .footer-sep { color: var(--pibico-grey-mid); }

/* --- Upload Zone --- */
.upload-zone {
    padding: 24px !important;
    text-align: center;
    cursor: pointer;
    border: 2px dashed var(--pibico-grey-mid);
    border-radius: var(--pibico-radius);
    transition: all 0.2s ease;
    margin-bottom: 16px;
}
.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--pibico-steel-blue);
    background: var(--pibico-steel-pale);
}
.upload-zone-content p { margin: 4px 0; }
.upload-icon {
    width: 40px; height: 40px; stroke: var(--pibico-steel-blue); fill: none;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
    margin-bottom: 8px;
}
.upload-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 10px;
}
.upload-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border: 1.5px solid var(--pibico-steel-blue);
    border-radius: var(--pibico-radius-sm);
    background: var(--pibico-white);
    color: var(--pibico-steel-blue);
    font-family: var(--pibico-font-btn);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.upload-btn:hover {
    background: var(--pibico-steel-blue);
    color: var(--pibico-white);
}
.upload-btn svg {
    width: 16px; height: 16px; stroke: currentColor; fill: none;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* --- Upload Checkbox --- */
.upload-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--pibico-grey-dark);
    cursor: pointer;
    justify-content: center;
}
.upload-checkbox input[type="checkbox"] {
    accent-color: var(--pibico-steel-blue);
    width: 15px;
    height: 15px;
    cursor: pointer;
}

/* --- Upload Progress --- */
.upload-progress { margin-top: 12px; }
.progress-bar {
    height: 6px;
    background: var(--pibico-light-grey);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--pibico-steel-blue);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease;
}
.progress-text {
    font-size: 0.8rem;
    color: var(--pibico-grey-dark);
    margin-top: 4px;
    display: block;
}

/* --- List Toolbar --- */
.list-toolbar {
    margin-bottom: 8px;
    padding: 0 4px;
}
.list-count {
    font-family: var(--pibico-font-heading);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--pibico-grey-dark);
}
.pibico-btn-sm {
    font-size: 0.75rem;
    padding: 4px 10px;
}

/* --- Email List --- */
.email-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 3px 4px;
    background: var(--pibico-white);
    border-radius: var(--pibico-radius-sm);
    margin-bottom: 6px;
    cursor: pointer;
    transition: box-shadow 0.2s ease;
    box-shadow: var(--pibico-card-shadow);
}
.email-row:hover {
    box-shadow: var(--pibico-card-shadow-hover);
}
.email-row .email-from {
    font-weight: 600;
    font-family: var(--pibico-font-heading);
    font-size: 0.85rem;
    min-width: 180px;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.email-row .email-subject {
    flex: 1;
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.email-row .email-date {
    font-size: 0.7rem;
    color: var(--pibico-grey-dark);
    min-width: 130px;
    text-align: right;
    white-space: nowrap;
}
.email-row .email-badges {
    display: flex;
    gap: 4px;
    min-width: 60px;
    justify-content: flex-end;
}
/* Extracted (thread-split) emails — indented, subtle bg */
.email-row-extract {
    margin-left: 20px;
    background: var(--pibico-steel-pale, #eaf2f8);
}
.pibico-badge-extract {
    background: var(--pibico-steel-blue);
    color: var(--pibico-white);
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 999px;
    font-weight: 500;
}

.email-split-btn,
.email-delete-btn {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    color: var(--pibico-grey-mid);
    flex-shrink: 0;
}
.email-row:hover .email-split-btn,
.email-row:hover .email-delete-btn {
    opacity: 1;
}
.email-split-btn:hover {
    color: var(--pibico-steel-blue);
}
.email-delete-btn:hover {
    color: var(--pibico-red-brick);
}
.email-split-btn svg,
.email-delete-btn svg {
    width: 16px; height: 16px; stroke: currentColor; fill: none;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* --- Thread View --- */
.thread-group {
    margin-bottom: 16px;
}
.thread-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--pibico-steel-pale);
    border-radius: var(--pibico-radius-sm) var(--pibico-radius-sm) 0 0;
    font-family: var(--pibico-font-heading);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
}
.thread-header:hover { background: var(--pibico-grey-mid); }
.thread-count {
    font-size: 0.75rem;
    background: var(--pibico-steel-blue);
    color: var(--pibico-white);
    border-radius: 999px;
    padding: 1px 7px;
    font-weight: 500;
}
.thread-emails {
    margin-left: 8px;
}
.thread-emails .email-row {
    border-radius: 0;
    margin-bottom: 0;
    border-bottom: 1px solid var(--pibico-light-grey);
}
.thread-emails .email-row:last-child {
    border-bottom: none;
    border-radius: 0 0 var(--pibico-radius-sm) 0;
}

/* --- Preview Panel header nav --- */
#preview-panel .pibico-panel-header {
    gap: 8px;
}
.preview-nav {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}
.preview-subject-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.preview-header-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    align-items: center;
}
.panel-nav-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: var(--pibico-white);
    border-radius: var(--pibico-radius-xs);
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background 0.15s;
}
.panel-nav-btn:hover { background: rgba(255,255,255,0.3); }
.panel-nav-btn:disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}
.panel-nav-btn svg {
    width: 16px; height: 16px; stroke: currentColor; fill: none;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* Expanded panel */
#preview-panel.panel-expanded {
    width: 75%;
}

/* --- Preview Panel — compact Arial --- */
.pibico-panel-body {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.8rem;
    line-height: 1;
    padding: 8px 12px;
}
.pibico-panel-body * {
    line-height: 1;
}
.pibico-panel-body h4 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    margin: 6px 0 3px;
    line-height: 1;
}
.preview-meta {
    margin-bottom: 6px;
    font-size: 0.8rem;
}
.preview-meta-row {
    display: flex;
    gap: 6px;
    padding: 3px 0;
}
.preview-meta-label {
    font-weight: 700;
    min-width: 32px;
    color: var(--pibico-grey-dark);
    font-size: 0.75rem;
    text-transform: uppercase;
}
.preview-frame-wrap {
    margin-bottom: 6px;
}
.preview-frame {
    width: 100%;
    min-height: 50vh;
    border: 1px solid var(--pibico-light-grey);
    border-radius: var(--pibico-radius-xs);
    background: var(--pibico-white);
}
.preview-attachments {
    margin-bottom: 6px;
}
.att-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 6px;
    background: var(--pibico-light-grey);
    border-radius: var(--pibico-radius-xs);
    margin-bottom: 2px;
    font-size: 0.75rem;
    cursor: pointer;
}
.att-item:hover { background: var(--pibico-steel-pale); }
.att-item svg {
    width: 12px; height: 12px; stroke: var(--pibico-steel-blue); fill: none;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* --- Toast notifications --- */
.toast-container {
    position: fixed;
    top: 60px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    background: var(--pibico-white);
    color: #1a1a2e;
    padding: 10px 16px;
    border-radius: var(--pibico-radius-sm);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.85rem;
    max-width: 360px;
    pointer-events: auto;
    animation: toastIn 0.3s ease;
    border-left: 4px solid var(--pibico-steel-blue);
}
.toast.toast-error {
    border-left-color: var(--pibico-red-brick);
}
.toast.toast-out {
    animation: toastOut 0.3s ease forwards;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* --- Confirm dialog --- */
.confirm-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.confirm-dialog {
    background: var(--pibico-white);
    border-radius: var(--pibico-radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    padding: 20px 24px;
    max-width: 380px;
    width: 90%;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.9rem;
    animation: toastIn 0.2s ease;
}
.confirm-dialog p {
    margin: 0 0 16px;
    line-height: 1.4;
}
.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* --- Empty state --- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--pibico-grey-dark);
}
.empty-state svg {
    width: 48px; height: 48px;
    stroke: var(--pibico-grey-mid); fill: none;
    stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
    margin-bottom: 12px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .email-row .email-from { min-width: 100px; max-width: 120px; }
    .email-row .email-date { display: none; }
    .app-main { padding: 10px; }
}

@media (max-width: 400px) {
    .email-row .email-badges { display: none; }
}

@media (display-mode: standalone) {
    .app-layout { padding-top: 20px; }
}
