/* Base: reset, layout, sidebar, main content, overview grid, responsive */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

body.app-loading .container {
    display: none;
}

.container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: #2c3e50;
    color: white;
    padding: 20px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: sticky;
    top: 0;
}

.auth-gate {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    z-index: 1100;
}

.auth-card {
    background: white;
    border-radius: 8px;
    padding: 30px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    text-align: center;
}

.auth-card h2 {
    margin-bottom: 10px;
}

.auth-card p {
    color: #666;
    margin-bottom: 20px;
}

.auth-info {
    margin-bottom: 20px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}

.auth-user {
    font-size: 12px;
    opacity: 0.9;
    margin-bottom: 8px;
    word-break: break-all;
}

.sidebar h1 {
    font-size: 18px;
    margin-bottom: 5px;
}

.sidebar .subtitle {
    font-size: 12px;
    opacity: 0.7;
    margin-bottom: 25px;
}

.sidebar h2 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.7;
    margin-bottom: 10px;
}

.mailbox-list {
    list-style: none;
}

.mailbox-list li {
    padding: 10px 12px;
    margin-bottom: 5px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.mailbox-list li:hover {
    background: rgba(255, 255, 255, 0.1);
}

.mailbox-list li.active {
    background: #1d4ed8;
}

.mailbox-list .email {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mailbox-list .meta {
    font-size: 11px;
    margin-top: 3px;
}

.mailbox-list .status {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 5px;
}

.status.authenticated {
    background: #2ecc71;
}

.status.unauthenticated {
    background: #e74c3c;
}

.btn-new-mailbox {
    width: 100%;
    padding: 12px;
    background: #2563eb;
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    margin-top: 20px;
    transition: background 0.2s;
}

.btn-new-mailbox:hover {
    background: #1d4ed8;
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sidebar-footer {
    margin-top: 20px;
    position: sticky;
    bottom: 20px;
}

/* Main Content */
.main {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    min-width: 0;
}
.content-inner {
    max-width: 1080px;
    margin: 0 auto;
}

/* Overview 4-column stat card grid */
.overview-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}
.stat-card {
    background: white;
    border: 1px solid #e8ecf0;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition:
        box-shadow 0.15s,
        border-color 0.15s;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
}
.stat-card:hover {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    border-color: #3498db;
}
.stat-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.stat-card-icon {
    color: #3498db;
}
.stat-card-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    letter-spacing: 0.3px;
}
.badge-ok {
    background: #dcfce7;
    color: #166534;
}
.badge-warn {
    background: #fee2e2;
    color: #991b1b;
}
.badge-miss {
    background: #fef9c3;
    color: #854d0e;
}
.badge-none {
    background: #f1f5f9;
    color: #475569;
}
.profile-hidden-source {
    display: none;
}
.profile-editor {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.profile-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 12px;
    border: 1px solid #e6edf5;
    border-radius: 10px;
    background: linear-gradient(180deg, #fbfdff 0%, #f6f9fc 100%);
}
.profile-editor-title {
    font-size: 12px;
    font-weight: 700;
    color: #243b53;
    letter-spacing: 0.2px;
}
.profile-editor-note {
    font-size: 11px;
    color: #64748b;
}
.profile-sections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px;
}
.profile-section-card {
    border: 1px solid #e6edf5;
    border-radius: 8px;
    background: #fcfdff;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}
.profile-section-card.persona-card {
    background: #fcfdff;
    border-color: #e6edf5;
}
.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.section-heading-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.section-heading-icon {
    color: #3498db;
    flex-shrink: 0;
}
.section-description {
    color: #666;
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 20px;
}
.section-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.profile-section-heading {
    font-size: 11px;
    font-weight: 800;
    color: #334155;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.profile-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.profile-field-label {
    font-size: 11px;
    font-weight: 600;
    color: #475569;
}
.profile-field textarea {
    width: 100%;
    min-height: 66px;
    padding: 10px;
    border: 1px solid #d8e1ea;
    border-radius: 8px;
    font-size: 12px;
    resize: vertical;
    line-height: 1.45;
    background: white;
    color: #243b53;
}
.profile-field textarea:focus {
    outline: none;
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.14);
}
.personalization-toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.personalization-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    color: #475569;
    font-weight: 600;
}
/* A switch inside a .form-group is also matched by the generic
   `.form-group label` rule (display:block, 14px, margin-bottom). Restore
   the switch layout explicitly so the track keeps its width and the thumb
   cannot overlap the label text. */
.form-group label.personalization-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    color: #475569;
    font-weight: 600;
    margin-bottom: 0;
}
/* The attribute selector keeps this above `.form-group input` in components.css,
   which sets width:100% for every input in a form group. */
.personalization-switch input[type="checkbox"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}
.personalization-switch-track {
    width: 38px;
    height: 22px;
    border-radius: 999px;
    background: #cbd5e1;
    position: relative;
    transition: background 0.18s ease;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.06);
    flex-shrink: 0;
}
.personalization-switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.18);
    transition: transform 0.18s ease;
}
.personalization-switch input:checked + .personalization-switch-track {
    background: #2563eb;
}
.personalization-switch
    input:checked
    + .personalization-switch-track
    .personalization-switch-thumb {
    transform: translateX(16px);
}
.personalization-switch-text {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.personalization-beta-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 999px;
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fdba74;
}
.personalization-card-body-disabled {
    opacity: 0.52;
    filter: saturate(0.75);
}
.personalization-card-body-disabled textarea,
.personalization-card-body-disabled button {
    pointer-events: none;
}
.personalization-warning-list {
    margin: 0 0 18px 20px;
    color: #57534e;
    line-height: 1.6;
}
.personalization-warning-list li + li {
    margin-top: 6px;
}
.auth-success-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid #cce9d7;
    background: linear-gradient(180deg, #f5fcf7 0%, #eefaf2 100%);
    margin-bottom: 12px;
}
.auth-success-main {
    display: flex;
    align-items: center;
    gap: 12px;
}
.auth-success-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #dff5e7;
    color: #15803d;
    flex-shrink: 0;
}
.auth-success-title {
    font-size: 14px;
    font-weight: 700;
    color: #166534;
    margin: 0;
}
.auth-success-note {
    font-size: 12px;
    color: #4b5563;
    margin-top: 2px;
}
.auth-expiry-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    background: white;
    border: 1px solid #d6efe0;
    font-size: 11px;
    color: #166534;
    white-space: nowrap;
}
.stat-card-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6b7280;
    margin: 0;
}
.stat-card-value {
    font-size: 15px;
    font-weight: 600;
    color: #222;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stat-card-desc {
    font-size: 11px;
    color: #6b7280;
    line-height: 1.4;
}

/* Responsive layout */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 300;
    background: #2c3e50;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 10px;
    cursor: pointer;
    line-height: 1;
}
@media (max-width: 1100px) {
    .overview-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (max-width: 860px) {
    .sidebar-toggle {
        display: block;
    }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        overflow-y: auto;
        width: 260px !important;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 199;
    }
    .sidebar-backdrop.open {
        display: block;
    }
    .main {
        padding: 16px;
        padding-top: 52px;
    }
    #mailboxMessage {
        left: 0 !important;
    }
}
@media (max-width: 660px) {
    .overview-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (max-width: 420px) {
    .overview-grid {
        grid-template-columns: 1fr;
    }
}

.panel {
    background: white;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Mailbox defaults (About This Mailbox / Signature) used to be rendered as
   nested cards inside Shared Mailbox Settings. They are now standalone
   panels after that section, so no special nested-panel styling is needed. */

.panel h2 {
    font-size: 18px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

/* Mailbox title row: title plus the classic/shared mode badge. */
.mailbox-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}
.mailbox-header h2 {
    margin: 0;
    padding: 0;
    border: 0;
}

.panel h3 {
    font-size: 14px;
    color: #666;
    margin-bottom: 10px;
}
