 /* UNIVERSAL MODAL WRAPPER */
.modal-wrap {
     position: fixed;
     top: 0;
     left: 0;
     width: 100%;
     height: 100%;
     background: color-mix(in srgb, var(--surface-base), transparent 35%);
     display: none;
     justify-content: center;
     align-items: center;
     z-index: 1000000 !important;
}

 /* UNIVERSAL MODAL BOX STYLING */
.modal-box {
     scrollbar-width: none;
     background: var(--surface-elevated);
     padding: 25px;
     border-radius: 12px;
     border: 2px solid var(--surface-border);
     box-shadow: var(--shadow-elevated);
     color: var(--text-primary);
}

.new-flashcard-modal-box {
     position: relative;
     overflow-x: hidden;
     overflow-y: auto;
     max-height: min(80vh, 520px);
     width: min(420px, 92vw) !important;
     display: flex;
     flex-direction: column;
     align-items: center;
     gap: 12px;
     padding: 24px;
     text-align: center;
}

.new-flashcard-title {
     margin: 0;
}

.new-flashcard-modal-box .modal-input {
     width: 100%;
}

.new-flashcard-actions {
     display: flex;
     gap: 10px;
     justify-content: center;
     width: 100%;
}

.modal-close-x {
     position: absolute;
     top: 14px;
     right: 14px;
     width: 34px;
     height: 34px;
     border: none;
     background: transparent;
     color: var(--text-secondary);
     font-size: 24px;
     line-height: 1;
     cursor: pointer;
     display: inline-flex;
     align-items: center;
     justify-content: center;
     border-radius: 8px;
     transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.modal-close-x:hover {
     background: var(--surface-hover);
     color: var(--text-primary);
     transform: translateY(-1px);
}

.modal-close-x:focus-visible {
     outline: 2px solid color-mix(in srgb, var(--accent-primary), transparent 40%);
     outline-offset: 2px;
}

.profile-modal-box {
     width: min(96vw, 1180px);
     height: min(86vh, 820px);
     max-height: 86vh;
     overflow: hidden;
     padding: 0;
     min-height: 560px;
}

.profile-modal-layout {
     display: grid;
     grid-template-columns: 240px 1fr;
     min-height: 420px;
     height: 100%;
     position: relative;
}

.profile-nav-backdrop {
     display: none;
}

.profile-modal-nav {
     background: var(--surface-base);
     border-right: 1px solid var(--surface-border);
     padding: 20px 16px;
     display: flex;
     flex-direction: column;
     gap: 10px;
     height: 100%;
     min-width: 0;
     transition: transform 0.25s ease, width 0.25s ease, padding 0.25s ease;
}

.profile-modal-nav-header {
     display: flex;
     align-items: center;
     justify-content: space-between;
     gap: 8px;
}

.profile-nav-collapse-btn {
     width: 30px;
     height: 30px;
     border: 1px solid var(--surface-border);
     border-radius: 8px;
     background: var(--surface-hover);
     color: var(--text-primary);
     cursor: pointer;
     display: inline-flex;
     align-items: center;
     justify-content: center;
     padding: 0;
}

.profile-nav-collapse-btn:hover {
     background: var(--surface-elevated);
}

.profile-modal-layout.nav-collapsed {
     grid-template-columns: 0 1fr;
}

.profile-modal-layout.nav-collapsed .profile-modal-nav {
     width: 0;
     min-width: 0;
     padding-left: 0;
     padding-right: 0;
     border-right-color: transparent;
     transform: translateX(-100%);
     overflow: hidden;
}

.profile-modal-layout.nav-collapsed .profile-nav-collapse-btn span {
     transform: rotate(180deg);
}

.profile-nav-spacer {
     flex: 1;
}

.profile-modal-title {
     font-size: 0.8rem;
     text-transform: uppercase;
     letter-spacing: 0.2em;
     color: var(--text-secondary);
     margin-bottom: 8px;
}

.profile-nav-item {
     text-align: left;
     padding: 10px 12px;
     border-radius: 10px;
     border: 1px solid transparent;
     background: transparent;
     color: var(--text-primary);
     cursor: pointer;
     font-size: 0.95rem;
     transition: background 0.2s ease, border-color 0.2s ease;
}

.profile-nav-item:hover {
     background: var(--surface-hover);
     border-color: var(--surface-border);
}

.profile-nav-item.active {
     background: color-mix(in srgb, var(--accent-primary), transparent 85%);
     border-color: color-mix(in srgb, var(--accent-primary), transparent 60%);
}

.profile-nav-logout {
     margin-top: auto;
     text-align: left;
     padding: 10px 12px;
     border-radius: 10px;
     border: 1px solid color-mix(in srgb, var(--accent-danger), transparent 60%);
     background: color-mix(in srgb, var(--accent-danger), transparent 85%);
     color: var(--text-on-danger);
     cursor: pointer;
     font-size: 0.95rem;
}

.profile-nav-logout:hover {
     background: color-mix(in srgb, var(--accent-danger), transparent 70%);
}

.profile-modal-main {
     position: relative;
     padding: 24px;
     overflow-y: scroll;
     height: 100%;
     min-height: 0;
     -webkit-overflow-scrolling: touch;
     overscroll-behavior: contain;
     scrollbar-gutter: stable both-edges;
}

.profile-nav-toggle-btn {
     display: none;
     margin: 0 0 14px;
     height: 34px;
     padding: 0 12px;
     border-radius: 9px;
     border: 1px solid var(--surface-border);
     background: var(--surface-hover);
     color: var(--text-primary);
     font-size: 0.92rem;
     font-weight: 600;
     cursor: pointer;
}

.profile-nav-toggle-btn:hover {
     background: var(--surface-elevated);
}

.profile-modal-layout.nav-collapsed .profile-nav-toggle-btn {
     display: inline-flex;
     align-items: center;
     justify-content: center;
}

@media (min-width: 721px) {
     .profile-modal-layout.nav-collapsed {
          grid-template-columns: 240px 1fr;
     }

     .profile-modal-layout.nav-collapsed .profile-modal-nav {
          width: auto;
          padding: 20px 16px;
          border-right-color: var(--surface-border);
          transform: none;
          overflow: visible;
     }

     .profile-nav-collapse-btn {
          display: none;
     }

     .profile-nav-toggle-btn {
          display: none !important;
     }
}

.profile-modal-close-btn {
     position: absolute;
     top: 14px;
     right: 14px;
     width: 34px;
     height: 34px;
     border-radius: 0;
     border: none;
     background: transparent;
     color: var(--text-primary);
     font-size: 24px;
     line-height: 1;
     cursor: pointer;
     display: inline-flex;
     align-items: center;
     justify-content: center;
     transition: color 0.2s ease, transform 0.2s ease;
}

.profile-modal-close-btn:hover {
     background: transparent;
     border-color: transparent;
     color: color-mix(in srgb, var(--text-primary), var(--accent-primary) 22%);
     transform: translateY(-1px);
}

.profile-modal-footer {
     text-align: right;
     margin-top: 20px;
}

@media (max-width: 900px) {
     .modal-wrap {
          align-items: flex-start;
          overflow-y: auto;
          padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
          padding-right: 12px;
          padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
          padding-left: 12px;
     }

     .profile-modal-box {
          width: min(100%, 1180px);
          min-height: 0;
          height: min(86dvh, 820px);
          max-height: min(86dvh, 820px);
     }
}

@media (max-width: 720px) {
     .profile-modal-box {
          max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px);
          overflow: hidden;
     }

     .profile-modal-layout {
          grid-template-columns: 1fr;
     }

     .profile-nav-backdrop {
          position: absolute;
          inset: 0;
          background: rgba(0, 0, 0, 0.42);
          z-index: 4;
     }

     .profile-modal-layout.nav-open .profile-nav-backdrop {
          display: block;
     }

     .profile-modal-nav {
          position: absolute;
          top: 0;
          left: 0;
          z-index: 5;
          width: min(78vw, 300px);
          max-width: 300px;
          border-right: 1px solid var(--surface-border);
          border-bottom: none;
          transform: translateX(-105%);
          box-shadow: var(--shadow-elevated);
     }

     .profile-modal-layout.nav-open .profile-modal-nav {
          transform: translateX(0);
     }

     .profile-nav-spacer {
          display: none;
     }

     .profile-nav-logout {
          margin-top: 0;
     }

     .profile-modal-main {
          padding: 18px 14px calc(env(safe-area-inset-bottom, 0px) + 18px);
          overflow-y: scroll;
     }

     .profile-nav-toggle-btn {
          display: inline-flex;
          align-items: center;
          justify-content: center;
     }

     .profile-nav-collapse-btn {
          display: none;
     }
}

.modal-input {
     width: 100%;
     padding: 12px 14px;
     margin: 16px 0;
     border-radius: 12px;
     border: 1px solid var(--surface-border);
     background: var(--surface-base);
     color: var(--text-primary);
     font-size: 15px;
     transition:
         border-color 0.2s ease,
         box-shadow 0.2s ease,
         background 0.2s ease;
}

.modal-input::placeholder {
     color: var(--text-secondary);
}

.modal-input:focus {
     outline: none;
     border-color: color-mix(in srgb, var(--accent-primary), var(--surface-border) 45%);
     background: var(--surface-elevated);
     box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-primary), transparent 78%);
}

 .modal-box::-webkit-scrollbar {
     width: 0;
     /* Chrome/Safari */
     height: 0;
 }

.modal-overview-btn {
     padding: 14px 26px;
     border-radius: 12px;

     background: var(--surface-base);
     border: 1px solid var(--surface-border);

     color: var(--text-secondary);
     font-size: 17px;
     font-weight: 500;

     cursor: pointer;
     white-space: nowrap;

     transition:
         background 0.2s ease,
         border-color 0.2s ease;
}

.modal-overview-btn:hover {
     background: var(--surface-hover);
     border-color: color-mix(in srgb, var(--surface-border), var(--text-primary) 20%);
}

.modal-overview-btn:hover {
     background: var(--surface-hover);
}

/* AI confirm modal */
.ai-confirm-box {
    width: min(92vw, 420px);
    padding: 24px;
    border-radius: 16px;
}

.ai-confirm-title {
    margin: 0 0 8px;
    font-size: 1.25rem;
}

.ai-confirm-message {
    margin: 0 0 10px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.4;
}

.ai-confirm-remaining {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 18px;
}

.ai-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Base modal button */
.modal-btn {
     padding: 12px 20px;
     border: none;
     border-radius: 10px;
     color: var(--text-primary);
     cursor: pointer;
     white-space: nowrap;
    transition:
        background 0.25s ease,
        transform 0.2s ease,
        backdrop-filter 0.25s ease,
        box-shadow 0.25s ease;
}

/* Save (primary action) */
.save-btn {
    background: var(--accent-primary);
    color: var(--text-on-accent);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-primary), transparent 55%),
        0 10px 24px color-mix(in srgb, var(--accent-primary), transparent 70%);
}

/* Cancel (neutral) */
.cancel-btn {
    background: var(--surface-base);
}

/* Delete (danger) */
.danger-btn {
    background: color-mix(in srgb, var(--accent-primary), transparent 35%);
    color: var(--text-on-accent);
}

.save-btn:hover {
    filter: brightness(1.05);
}

.danger-btn:hover {
    filter: brightness(1.05);
}

 /* Active state */
 .modal-btn:active {
     transform: translateY(0px);
     box-shadow: none;
 }

 @keyframes modalPop {
     from {
         transform: scale(0.95);
         opacity: 0;
     }

     to {
         transform: scale(1);
         opacity: 1;
     }
 }

.instance-modal {
     position: absolute;
     inset: 0;
     background: color-mix(in srgb, var(--surface-base), transparent 45%);
     display: flex;
     align-items: center;
     justify-content: center;
}

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

.instance-modal-inner {
    background: var(--surface-elevated);
    padding: 26px;
    border-radius: 16px;
    width: min(420px, 90%);
    border: 2px solid var(--surface-border);
    box-shadow: var(--shadow-elevated);
    animation: modalPop 0.2s ease;
}
 .instance-modal.instant .instance-modal-inner {
     animation: none;
 }

 .instance-modal-inner h3 {
     margin-bottom: 14px;
 }

.instance-modal-inner input {
     width: 100%;
     padding: 12px;
     font-size: 16px;
     border-radius: 10px;
     border: 1px solid var(--surface-border);
     background: var(--surface-base);
     color: var(--text-primary);
     outline: none;
}

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

 .instance-modal-actions button {
     padding: 10px 16px;
     border-radius: 10px;
     border: none;
     cursor: pointer;
     font-size: 14px;
 }
