:root {
    --p3x-onenote-purple: #7719AA;
    --p3x-onenote-purple-light: #9B51C6;
    --p3x-onenote-purple-dark: #5B0E85;
    --p3x-onenote-accent: #D83B01;
    --p3x-onenote-bottom-bar-height: 26px;
    --p3x-onenote-tab-bar-height: 32px;
    --p3x-onenote-font: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
}

/* ── Dark mode invert ──────────────────────────────────────────── */

body.p3x-dark-mode-invert-quirks .p3x-onenote-webview {
    filter: invert(1) hue-rotate(180deg);
}

/* ── Base ──────────────────────────────────────────────────────── */

body {
    background-color: #f3f2f1;
    padding: 0;
    margin: 0;
    overflow: hidden;
    font-family: var(--p3x-onenote-font);
    -webkit-font-smoothing: antialiased;
}

/* ── Bottom bar ────────────────────────────────────────────────── */

#p3x-onenote-bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--p3x-onenote-bottom-bar-height);
    background: var(--p3x-onenote-purple);
    color: rgba(255, 255, 255, 0.95);
    font-family: var(--p3x-onenote-font);
    font-size: 12px;
    line-height: var(--p3x-onenote-bottom-bar-height);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    user-select: none;
    z-index: 100;
}

.p3x-bar-group {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.p3x-bar-group.p3x-bar-right {
    margin-left: auto;
}

.p3x-bar-separator {
    width: 1px;
    height: 14px;
    background: rgba(255, 255, 255, 0.25);
    margin: 0 2px;
}

.p3x-bar-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 8px;
    margin: 0;
    height: var(--p3x-onenote-bottom-bar-height);
    line-height: var(--p3x-onenote-bottom-bar-height);
    min-width: 26px;
    font-size: 12px;
    font-family: var(--p3x-onenote-font);
    color: rgba(255, 255, 255, 0.95);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.1s;
}

.p3x-bar-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.p3x-bar-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.p3x-bar-btn:disabled {
    opacity: 0.35;
    cursor: default;
    background: none !important;
}

#p3x-zoom-factor {
    font-size: 11px;
    min-width: 32px;
    text-align: center;
    opacity: 0.85;
}

#p3x-location-bar {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    padding: 0 8px;
    opacity: 0.85;
    font-size: 11px;
}

#p3x-location-bar:hover {
    opacity: 1;
}

/* ── Tab bar ──────────────────────────────────────────────────── */

#p3x-onenote-tab-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--p3x-onenote-tab-bar-height);
    background: var(--p3x-onenote-purple-dark);
    display: flex;
    align-items: center;
    padding: 0 4px;
    gap: 2px;
    z-index: 100;
    user-select: none;
    overflow-x: auto;
    overflow-y: hidden;
}

.p3x-tab {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 24px;
    padding: 0 8px;
    border-radius: 4px 4px 0 0;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    font-family: var(--p3x-onenote-font);
    cursor: pointer;
    white-space: nowrap;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    border: none;
    flex-shrink: 0;
}

.p3x-tab:hover {
    background: rgba(255, 255, 255, 0.15);
}

.p3x-tab.p3x-tab-active {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.p3x-tab-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    font-size: 10px;
    padding: 0 2px;
    line-height: 1;
    border-radius: 2px;
}

.p3x-tab-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.p3x-tab.p3x-tab-dragging {
    opacity: 0.4;
}

.p3x-tab.p3x-tab-drag-over {
    border-left: 2px solid rgba(255, 255, 255, 0.8);
}

#p3x-tab-add {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 14px;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#p3x-tab-add:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* ── Webview container ────────────────────────────────────────── */

#p3x-onenote-webview-container {
    position: fixed;
    top: var(--p3x-onenote-tab-bar-height);
    left: 0;
    width: 100%;
    height: calc(100% - var(--p3x-onenote-tab-bar-height) - var(--p3x-onenote-bottom-bar-height));
}

.p3x-onenote-webview {
    width: 100%;
    height: 100%;
    border: none;
}

.p3x-onenote-webview.p3x-hidden {
    display: none;
}

/* ── Toast ──────────────────────────────────────────────────────── */

#p3x-toast-container {
    position: fixed;
    bottom: 36px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
}

.p3x-toast {
    background: var(--p3x-onenote-purple-dark);
    color: #fff;
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 13px;
    font-family: var(--p3x-onenote-font);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(16px);
    animation: p3x-toast-in 0.25s forwards;
    max-width: 400px;
    word-break: break-word;
}

.p3x-toast.p3x-toast-out {
    animation: p3x-toast-out 0.2s forwards;
}

@keyframes p3x-toast-in {
    to { opacity: 1; transform: translateY(0); }
}

@keyframes p3x-toast-out {
    to { opacity: 0; transform: translateY(16px); }
}

/* ── Dialog ─────────────────────────────────────────────────────── */

#p3x-dialog {
    border: none;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.24);
    padding: 0;
    min-width: 340px;
    max-width: 520px;
    font-family: var(--p3x-onenote-font);
    color: #323130;
}

#p3x-dialog::backdrop {
    background: rgba(0, 0, 0, 0.4);
}

.p3x-dialog-title {
    font-size: 20px;
    font-weight: 600;
    padding: 24px 24px 4px;
    margin: 0;
    color: var(--p3x-onenote-purple);
}

.p3x-dialog-body {
    padding: 12px 24px 16px;
    font-size: 14px;
    line-height: 1.5;
}

.p3x-dialog-body p {
    margin: 0 0 12px;
    color: #605e5c;
}

.p3x-dialog-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #8a8886;
    border-radius: 4px;
    outline: none;
    padding: 8px 10px;
    font-size: 14px;
    font-family: var(--p3x-onenote-font);
    background: #fff;
    color: #323130;
    transition: border-color 0.15s;
}

.p3x-dialog-input:focus {
    border-color: var(--p3x-onenote-purple);
    box-shadow: 0 0 0 1px var(--p3x-onenote-purple);
}

.p3x-dialog-field {
    margin-bottom: 16px;
}

.p3x-dialog-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #323130;
    margin-bottom: 6px;
}

.p3x-dialog-field .p3x-field-error {
    font-size: 12px;
    color: #a4262c;
    margin-top: 4px;
    display: none;
}

.p3x-dialog-field.p3x-invalid .p3x-field-error {
    display: block;
}

.p3x-dialog-field.p3x-invalid .p3x-dialog-input {
    border-color: #a4262c;
}

.p3x-dialog-actions {
    display: flex;
    justify-content: flex-end;
    padding: 12px 24px 16px;
    gap: 8px;
}

.p3x-btn {
    background: #fff;
    border: 1px solid #8a8886;
    cursor: pointer;
    padding: 6px 20px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--p3x-onenote-font);
    color: #323130;
    transition: background 0.1s, border-color 0.1s;
}

.p3x-btn:hover {
    background: #f3f2f1;
}

.p3x-btn.p3x-btn-primary {
    background: var(--p3x-onenote-purple);
    border-color: var(--p3x-onenote-purple);
    color: #fff;
}

.p3x-btn.p3x-btn-primary:hover {
    background: var(--p3x-onenote-purple-light);
    border-color: var(--p3x-onenote-purple-light);
}

.p3x-btn.p3x-btn-warn {
    color: #a4262c;
    border-color: #a4262c;
}

.p3x-btn.p3x-btn-warn:hover {
    background: #fde7e9;
}

/* ── Bookmark Manager ──────────────────────────────────────────────── */

#p3x-dialog.p3x-bookmark-manager {
    min-width: 700px;
    max-width: 900px;
    max-height: 80vh;
}

.p3x-bm-toolbar {
    display: flex;
    gap: 8px;
    padding: 0 24px 12px;
    align-items: center;
}

.p3x-bm-search {
    flex: 1;
}

.p3x-bm-list {
    max-height: 50vh;
    overflow-y: auto;
    padding: 0 24px 16px;
}

.p3x-bm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.p3x-bm-table th {
    text-align: left;
    padding: 6px 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: #605e5c;
    border-bottom: 2px solid #e1dfdd;
    user-select: none;
    white-space: nowrap;
}

.p3x-bm-table td {
    padding: 5px 8px;
    border-bottom: 1px solid #e1dfdd;
    vertical-align: middle;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.p3x-bm-table tr:hover {
    background: rgba(0, 0, 0, 0.04);
}

.p3x-bm-table .p3x-bm-cell-edit {
    cursor: pointer;
}

.p3x-bm-table .p3x-bm-cell-edit:hover {
    color: var(--p3x-onenote-purple);
    text-decoration: underline;
}

.p3x-bm-table .p3x-bm-actions {
    white-space: nowrap;
    width: 1%;
}

.p3x-bm-table .p3x-bm-actions button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 12px;
    color: #605e5c;
}

.p3x-bm-table .p3x-bm-actions button:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #323130;
}

.p3x-bm-table .p3x-bm-actions button.p3x-bm-delete:hover {
    color: #a4262c;
    background: #fde7e9;
}

.p3x-bm-inline-input {
    border: 1px solid var(--p3x-onenote-purple);
    border-radius: 3px;
    padding: 2px 4px;
    font-size: 13px;
    font-family: var(--p3x-onenote-font);
    width: 100%;
    box-sizing: border-box;
}

.p3x-bm-empty {
    text-align: center;
    padding: 24px;
    color: #605e5c;
    font-style: italic;
}

.p3x-bm-folder-tag {
    display: inline-block;
    background: rgba(119, 25, 170, 0.1);
    color: var(--p3x-onenote-purple);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 11px;
}

/* ── Dark mode bookmark manager ─────────────────────────────────── */

body.p3x-dark-mode-invert-quirks .p3x-bm-table {
    color: #e0e0e0;
}

body.p3x-dark-mode-invert-quirks .p3x-bm-table th {
    color: #b0b0b0;
    border-bottom-color: #555;
}

body.p3x-dark-mode-invert-quirks .p3x-bm-table td {
    color: #e0e0e0;
    border-bottom-color: #4a4a4a;
}

body.p3x-dark-mode-invert-quirks .p3x-bm-table .p3x-bm-cell-edit:hover {
    color: var(--p3x-onenote-purple-light);
}

body.p3x-dark-mode-invert-quirks .p3x-bm-table tr:hover {
    background: rgba(255, 255, 255, 0.08);
}

body.p3x-dark-mode-invert-quirks .p3x-bm-table .p3x-bm-actions button {
    color: #b0b0b0;
}

body.p3x-dark-mode-invert-quirks .p3x-bm-table .p3x-bm-actions button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
}

body.p3x-dark-mode-invert-quirks .p3x-bm-table .p3x-bm-actions button.p3x-bm-delete:hover {
    color: #f48fb1;
    background: #3d2020;
}

body.p3x-dark-mode-invert-quirks .p3x-bm-inline-input {
    background: #3c3c3c;
    color: #e0e0e0;
    border-color: var(--p3x-onenote-purple-light);
}

body.p3x-dark-mode-invert-quirks .p3x-bm-folder-tag {
    background: rgba(155, 81, 198, 0.3);
    color: var(--p3x-onenote-purple-light);
}

body.p3x-dark-mode-invert-quirks .p3x-bm-empty {
    color: #b0b0b0;
}

body.p3x-dark-mode-invert-quirks .p3x-bm-search {
    background: #3c3c3c;
    color: #e0e0e0;
    border-color: #6b6b6b;
}

/* ── Dark mode dialog & toast (Fluent Design dark palette) ──────── */

body.p3x-dark-mode-invert-quirks #p3x-dialog {
    background: #2d2d2d;
    color: #e0e0e0;
}

body.p3x-dark-mode-invert-quirks #p3x-dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

body.p3x-dark-mode-invert-quirks .p3x-dialog-title {
    color: var(--p3x-onenote-purple-light);
}

body.p3x-dark-mode-invert-quirks .p3x-dialog-body p {
    color: #c8c8c8;
}

body.p3x-dark-mode-invert-quirks .p3x-dialog-input {
    background: #3c3c3c;
    color: #e0e0e0;
    border-color: #6b6b6b;
}

body.p3x-dark-mode-invert-quirks .p3x-dialog-input:focus {
    border-color: var(--p3x-onenote-purple-light);
    box-shadow: 0 0 0 1px var(--p3x-onenote-purple-light);
}

body.p3x-dark-mode-invert-quirks .p3x-dialog-field label {
    color: #e0e0e0;
}

body.p3x-dark-mode-invert-quirks .p3x-btn {
    background: #3c3c3c;
    border-color: #6b6b6b;
    color: #e0e0e0;
}

body.p3x-dark-mode-invert-quirks .p3x-btn:hover {
    background: #4a4a4a;
}

body.p3x-dark-mode-invert-quirks .p3x-btn.p3x-btn-warn {
    color: #f48fb1;
    border-color: #f48fb1;
}

body.p3x-dark-mode-invert-quirks .p3x-btn.p3x-btn-warn:hover {
    background: #4a2020;
}
