/* ============================================================
   MISAC Storage Manager — Sidebar, Popover, Banner, Badge
   ============================================================ */

/* ── Backdrop ─────────────────────────────────────────────── */
.mst-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1049;
    opacity: 0;
    transition: opacity 0.22s ease;
    pointer-events: none;
}
.mst-backdrop--open {
    opacity: 1;
    pointer-events: auto;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.mst-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 380px;
    max-width: 100vw;
    background: var(--m-surface, #fff);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.mst-sidebar--open {
    transform: translateX(0);
}

/* ── Header ───────────────────────────────────────────────── */
.mst-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 12px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.mst-header__title {
    font-weight: 600;
    font-size: 15px;
    color: #111827;
    margin: 0;
}
.mst-header__close {
    background: none;
    border: none;
    padding: 4px 8px;
    cursor: pointer;
    color: #6b7280;
    font-size: 18px;
    line-height: 1;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
}
.mst-header__close:hover {
    background: #f3f4f6;
    color: #111827;
}

/* ── Tabs ─────────────────────────────────────────────────── */
.mst-tabs {
    display: flex;
    border-bottom: 2px solid #e5e7eb;
    flex-shrink: 0;
    padding: 0 12px;
    gap: 4px;
}
.mst-tab {
    padding: 10px 14px 8px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}
.mst-tab:hover {
    color: #374151;
}
.mst-tab--active {
    color: var(--m-accent, #2563eb);
    border-bottom-color: var(--m-accent, #2563eb);
}

/* ── Content (scrollable body) ────────────────────────────── */
.mst-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* ── Footer ───────────────────────────────────────────────── */
.mst-footer {
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

/* ── Empty state ──────────────────────────────────────────── */
.mst-empty {
    text-align: center;
    padding: 36px 16px;
    color: #9ca3af;
    font-size: 13px;
}
.mst-empty__icon {
    font-size: 32px;
    display: block;
    margin-bottom: 8px;
}

/* ── Draft groups & items ─────────────────────────────────── */
.mst-draft-group {
    margin-bottom: 16px;
}
.mst-draft-group__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.mst-draft-group__title {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.mst-draft-group__clear {
    font-size: 11px;
    color: #ef4444;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-decoration: underline;
}
.mst-draft-group__clear:hover {
    color: #b91c1c;
}

.mst-draft-item {
    display: flex;
    align-items: flex-start;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    margin-bottom: 6px;
    background: #fafafa;
    gap: 8px;
    transition: border-color 0.15s;
}
.mst-draft-item:hover {
    border-color: #d1d5db;
}
.mst-draft-item__body {
    flex: 1;
    min-width: 0;
}
.mst-draft-item__title {
    font-size: 13px;
    font-weight: 500;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mst-draft-item__meta {
    font-size: 11px;
    color: #6b7280;
    margin-top: 2px;
}
.mst-draft-item__auto {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: #e0e7ff;
    color: #4338ca;
    border-radius: 3px;
    padding: 1px 4px;
    margin-left: 5px;
    vertical-align: middle;
}
.mst-draft-item__warn {
    color: #d97706;
    margin-left: 4px;
}
.mst-draft-item__actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    align-items: center;
}
.mst-draft-item__btn {
    padding: 3px 8px;
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid;
    line-height: 1.4;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.mst-draft-item__btn--restore {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1d4ed8;
}
.mst-draft-item__btn--restore:hover {
    background: #dbeafe;
}
.mst-draft-item__btn--delete {
    background: #fff;
    border-color: #e5e7eb;
    color: #6b7280;
}
.mst-draft-item__btn--delete:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #dc2626;
}

/* ── Cache rows ───────────────────────────────────────────── */
.mst-cache-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 0;
    border-bottom: 1px solid #f3f4f6;
    gap: 8px;
}
.mst-cache-row:last-child {
    border-bottom: none;
}
.mst-cache-row__label {
    font-size: 13px;
    color: #374151;
    flex: 1;
}
.mst-cache-row__meta {
    font-size: 11px;
    color: #9ca3af;
    text-align: right;
}
.mst-cache-row__clear {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    background: #fff;
    border: 1px solid #e5e7eb;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.15s;
}
.mst-cache-row__clear:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #dc2626;
}

/* ── Usage bar ────────────────────────────────────────────── */
.mst-usage {
    margin-bottom: 16px;
    padding: 10px 12px;
    background: #f9fafb;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}
.mst-usage__label {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #6b7280;
    margin-bottom: 6px;
}
.mst-usage__bar {
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    overflow: hidden;
}
.mst-usage__fill {
    height: 100%;
    border-radius: 3px;
    background: var(--m-accent, #3b82f6);
    transition: width 0.3s ease;
}
.mst-usage__fill--warn {
    background: #f59e0b;
}
.mst-usage__fill--danger {
    background: #ef4444;
}

/* ── Danger button ────────────────────────────────────────── */
.mst-btn-danger {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    background: #fff;
    color: #dc2626;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.mst-btn-danger:hover {
    background: #fee2e2;
    border-color: #f87171;
}

/* ── Draft Popover ────────────────────────────────────────── */
.misac-draft-popover {
    position: fixed;
    width: 320px;
    max-width: calc(100vw - 24px);
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14);
    z-index: 1060;
    padding: 14px;
    font-size: 13px;
}
.misac-draft-popover__label {
    font-size: 11px;
    font-weight: 600;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 5px;
}
.misac-draft-popover__input {
    width: 100%;
    padding: 6px 9px;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    font-size: 13px;
    color: #111827;
    outline: none;
    box-sizing: border-box;
}
.misac-draft-popover__input:focus {
    border-color: var(--m-accent, #3b82f6);
    box-shadow: 0 0 0 2px var(--m-accent-ring, rgba(59, 130, 246, 0.2));
}
.misac-draft-popover__warn {
    font-size: 11px;
    color: #92400e;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 4px;
    padding: 5px 8px;
    margin-top: 8px;
}
.misac-draft-popover__save-btn {
    width: 100%;
    margin-top: 10px;
    padding: 7px 12px;
    background: var(--m-accent, #2563eb);
    color: var(--m-text-on-accent, #fff);
    border: none;
    border-radius: 5px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}
.misac-draft-popover__save-btn:hover {
    background: var(--m-accent-hover, #1d4ed8);
}
.misac-draft-popover__divider {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 10px 0 8px;
}
.misac-draft-popover__recent-title {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}
.misac-draft-popover__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid #f3f4f6;
    gap: 6px;
}
.misac-draft-popover__item:last-of-type {
    border-bottom: none;
}
.misac-draft-popover__item-info {
    flex: 1;
    min-width: 0;
}
.misac-draft-popover__item-title {
    font-size: 12px;
    font-weight: 500;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.misac-draft-popover__item-meta {
    font-size: 10px;
    color: #9ca3af;
}
.misac-draft-popover__item-actions {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
}
.misac-draft-popover__item-btn {
    padding: 2px 6px;
    font-size: 11px;
    border: 1px solid #e5e7eb;
    border-radius: 3px;
    background: #f9fafb;
    cursor: pointer;
    color: #374151;
    transition: all 0.12s;
}
.misac-draft-popover__item-btn:hover {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #1d4ed8;
}
.misac-draft-popover__item-btn--del:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #dc2626;
}
.misac-draft-popover__manage {
    display: block;
    margin-top: 10px;
    font-size: 12px;
    color: var(--m-accent, #2563eb);
    text-align: center;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-decoration: underline;
    padding: 4px 0;
}
.misac-draft-popover__manage:hover {
    color: var(--m-accent-hover, #1d4ed8);
}

/* ── Draft Banner ─────────────────────────────────────────── */
.misac-draft-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    background: var(--m-info-light, #eff6ff);
    border: 1px solid var(--m-accent-ring, #bfdbfe);
    border-radius: var(--m-radius, 6px);
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--m-accent-text, #1e40af);
}
.misac-draft-banner__text {
    flex: 1;
}
.misac-draft-banner__link {
    color: var(--m-accent, #2563eb);
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    font-size: 13px;
    text-decoration: underline;
    font-weight: 500;
}
.misac-draft-banner__link:hover {
    color: var(--m-accent-hover, #1d4ed8);
}
.misac-draft-banner__dismiss {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0 2px;
    font-size: 15px;
    line-height: 1;
    flex-shrink: 0;
}
.misac-draft-banner__dismiss:hover {
    color: #111827;
}

/* ── Draft split-button group ─────────────────────────────── */
.misac-draft-group {
    /* btn-group handles border-radius joining automatically */
}
.misac-btn--autosave {
    font-size: 12px;
    padding: 4px 9px;
    border-right-width: 0; /* share border with draft btn */
    white-space: nowrap;
}
.misac-btn--autosave.btn-outline-success {
    /* On state: green tint so it reads as active */
    background: #f0fdf4;
}
.misac-draft-group .misac-btn--draft {
    font-size: 13px;
    padding: 4px 11px;
    border-left: 1px solid currentColor; /* visible divider between the two halves */
}

/* ── Draft badge on button ────────────────────────────────── */
.misac-draft-badge {
    display: inline-block;
    background: #ef4444;
    color: #fff;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    padding: 2px 5px;
    margin-left: 4px;
    vertical-align: middle;
}

/* ── Device bar (below header, above tabs) ────────────────── */
.mst-device-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    gap: 8px;
    flex-shrink: 0;
}
.mst-device-bar__left {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    flex: 1;
}
.mst-device-bar__icon {
    font-size: 13px;
    flex-shrink: 0;
}
.mst-device-bar__name-text {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}
.mst-device-bar__edit {
    background: none;
    border: none;
    padding: 1px 4px;
    color: #9ca3af;
    font-size: 13px;
    cursor: pointer;
    border-radius: 3px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}
.mst-device-bar__edit:hover {
    color: #374151;
    background: #e5e7eb;
}
.mst-device-bar__name-input {
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 12px;
    color: #111827;
    outline: none;
    width: 120px;
}
.mst-device-bar__name-input:focus {
    border-color: var(--m-accent, #3b82f6);
    box-shadow: 0 0 0 2px var(--m-accent-ring, rgba(59, 130, 246, 0.2));
}
.mst-device-bar__right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* ── Sync status text ─────────────────────────────────────── */
.mst-sync-status {
    font-size: 10px;
    color: #9ca3af;
    white-space: nowrap;
}

/* ── Sync button ──────────────────────────────────────────── */
.mst-sync-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 12px;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    background: #fff;
    color: #374151;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}
.mst-sync-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}
.mst-sync-btn--loading {
    opacity: 0.7;
    cursor: not-allowed;
}
.mst-sync-btn__icon {
    font-size: 13px;
    line-height: 1;
}

/* ── Spinner ──────────────────────────────────────────────── */
.mst-spinner {
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 2px solid #d1d5db;
    border-top-color: #6b7280;
    border-radius: 50%;
    animation: mst-spin 0.7s linear infinite;
    vertical-align: middle;
}
@keyframes mst-spin {
    to { transform: rotate(360deg); }
}

/* ── Loading placeholder ──────────────────────────────────── */
.mst-loading {
    padding: 36px 16px;
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
}

/* ── Device rows (Devices tab) ────────────────────────────── */
.mst-device-row {
    padding: 12px 0;
    border-bottom: 1px solid #f3f4f6;
}
.mst-device-row:last-child {
    border-bottom: none;
}
.mst-device-row--current {
    background: #f0fdf4;
    margin: 0 -16px;
    padding: 12px 16px;
    border-bottom-color: #d1fae5;
}
.mst-device-row__name {
    font-size: 13px;
    color: #111827;
    margin-bottom: 2px;
}
.mst-device-row__you {
    font-size: 11px;
    font-weight: 400;
    color: #059669;
}
.mst-device-row__meta {
    font-size: 11px;
    color: #9ca3af;
    margin-bottom: 6px;
}
.mst-device-row__actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.mst-device-row__btn {
    padding: 3px 10px;
    font-size: 11px;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.mst-device-row__btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}
.mst-device-row__btn--danger {
    border-color: #fca5a5;
    color: #dc2626;
}
.mst-device-row__btn--danger:hover {
    background: #fee2e2;
    border-color: #f87171;
}

/* ── Settings tab ────────────────────────────────────────── */
.mst-settings-section {
    margin-bottom: 20px;
}
.mst-settings-section__title {
    font-size: 11px;
    font-weight: 700;
    color: var(--m-text-secondary, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--m-border-light, #e5e7eb);
}

.mst-settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--m-border-light, #f3f4f6);
}
.mst-settings-row:last-child {
    border-bottom: none;
}
.mst-settings-row__left {
    flex: 1;
    min-width: 0;
}
.mst-settings-row__label {
    font-size: 13px;
    font-weight: 500;
    color: var(--m-text, #111827);
}
.mst-settings-row__desc {
    font-size: 11px;
    color: var(--m-text-muted, #9ca3af);
    margin-top: 2px;
}

.mst-settings-input {
    width: 140px;
    padding: 5px 8px;
    border: 1px solid var(--m-border, #d1d5db);
    border-radius: 5px;
    font-size: 12px;
    color: var(--m-text, #111827);
    background: var(--m-input-bg, #fff);
    outline: none;
    flex-shrink: 0;
}
.mst-settings-input:focus {
    border-color: var(--m-accent, #3b82f6);
    box-shadow: 0 0 0 2px var(--m-accent-ring, rgba(59, 130, 246, 0.2));
}

/* ── Toggle switch ───────────────────────────────────────── */
.mst-toggle {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
    cursor: pointer;
}
.mst-toggle__input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.mst-toggle__track {
    position: absolute;
    inset: 0;
    background: #d1d5db;
    border-radius: 12px;
    transition: background 0.2s ease;
}
.mst-toggle__track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
    transition: transform 0.2s ease;
}
.mst-toggle__input:checked + .mst-toggle__track {
    background: var(--m-brand, #2272b5);
}
.mst-toggle__input:checked + .mst-toggle__track::after {
    transform: translateX(18px);
}
.mst-toggle__input:focus-visible + .mst-toggle__track {
    box-shadow: 0 0 0 2px var(--m-accent-ring, rgba(34, 114, 181, 0.25));
}
