/* --- Material 3 Inspired Design System --- */
:root {
    /* Referencia: https://m3.material.io/styles/color/the-color-system/tokens */
    /* Usaremos un tema claro para el dialog y oscuro para el fondo del body */

    /* Primary (ej. Morado M3) */
    --md-sys-color-primary: #6750A4;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-primary-container: #EADDFF;
    --md-sys-color-on-primary-container: #21005D;

    /* Secondary (ej. Gris Azulado M3) */
    --md-sys-color-secondary: #625B71;
    --md-sys-color-on-secondary: #FFFFFF;
    --md-sys-color-secondary-container: #E8DEF8;
    --md-sys-color-on-secondary-container: #1D192B;
    
    /* Tertiary (ej. Rosa Oscuro M3) */
    --md-sys-color-tertiary: #7D5260;
    --md-sys-color-on-tertiary: #FFFFFF;
    --md-sys-color-tertiary-container: #FFD8E4;
    --md-sys-color-on-tertiary-container: #31111D;

    /* Error */
    --md-sys-color-error: #B3261E;
    --md-sys-color-on-error: #FFFFFF;
    --md-sys-color-error-container: #F9DEDC;
    --md-sys-color-on-error-container: #410E0B;

    /* Surface & Background (Para el Dialog/Card) */
    --md-sys-color-surface: #FFFBFE; /* Casi blanco, para el card */
    --md-sys-color-on-surface: #1C1B1F; /* Texto principal en el card */
    --md-sys-color-surface-variant: #E7E0EC; /* Fondos sutiles, bordes */
    --md-sys-color-on-surface-variant: #49454F; /* Texto secundario */
    --md-sys-color-outline: #79747E; /* Bordes de inputs, etc. */
    --md-sys-color-shadow: #000000;

    /* Background (Para el body) */
    --app-bg-color: #141218; /* Un fondo oscuro para que el dialog resalte */

    /* Typography */
    --md-sys-typescale-headline-small-font-family: 'Roboto', sans-serif;
    --md-sys-typescale-headline-small-font-weight: 400;
    --md-sys-typescale-headline-small-font-size: 1.5rem; /* 24px */
    --md-sys-typescale-headline-small-line-height: 2rem; /* 32px */

    --md-sys-typescale-title-large-font-family: 'Roboto', sans-serif;
    --md-sys-typescale-title-large-font-weight: 500;
    --md-sys-typescale-title-large-font-size: 1.375rem; /* 22px */
    --md-sys-typescale-title-large-line-height: 1.75rem; /* 28px */
    
    --md-sys-typescale-title-medium-font-family: 'Roboto', sans-serif;
    --md-sys-typescale-title-medium-font-weight: 500;
    --md-sys-typescale-title-medium-font-size: 1rem; /* 16px */
    --md-sys-typescale-title-medium-line-height: 1.5rem; /* 24px */

    --md-sys-typescale-body-large-font-family: 'Roboto', sans-serif;
    --md-sys-typescale-body-large-font-weight: 400;
    --md-sys-typescale-body-large-font-size: 1rem; /* 16px */
    --md-sys-typescale-body-large-line-height: 1.5rem; /* 24px */

    --md-sys-typescale-body-medium-font-family: 'Roboto', sans-serif;
    --md-sys-typescale-body-medium-font-weight: 400;
    --md-sys-typescale-body-medium-font-size: 0.875rem; /* 14px */
    --md-sys-typescale-body-medium-line-height: 1.25rem; /* 20px */

    --md-sys-typescale-body-small-font-family: 'Roboto', sans-serif;
    --md-sys-typescale-body-small-font-weight: 400;
    --md-sys-typescale-body-small-font-size: 0.75rem; /* 12px */
    --md-sys-typescale-body-small-line-height: 1rem; /* 16px */

    --md-sys-typescale-label-large-font-family: 'Roboto', sans-serif;
    --md-sys-typescale-label-large-font-weight: 500;
    --md-sys-typescale-label-large-font-size: 0.875rem; /* 14px */
    --md-sys-typescale-label-large-line-height: 1.25rem; /* 20px */
}

/* --- Global Styles & Resets --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--md-sys-typescale-body-large-font-family);
    background-color: var(--app-bg-color);
    color: var(--md-sys-color-on-surface); 
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 16px;
    overflow-x: hidden;
}

/* --- Material Symbols Base Style --- */
.material-symbols-outlined {
  font-variation-settings:
  'FILL' 0,
  'wght' 400,
  'GRAD' 0,
  'opsz' 24;
  vertical-align: middle;
}

/* --- Typography Classes --- */
.m3-typography--headline-small {
    font-family: var(--md-sys-typescale-headline-small-font-family);
    font-weight: var(--md-sys-typescale-headline-small-font-weight);
    font-size: var(--md-sys-typescale-headline-small-font-size);
    line-height: var(--md-sys-typescale-headline-small-line-height);
    color: var(--md-sys-color-on-surface);
}
.m3-typography--title-large {
    font-family: var(--md-sys-typescale-title-large-font-family);
    font-weight: var(--md-sys-typescale-title-large-font-weight);
    font-size: var(--md-sys-typescale-title-large-font-size);
    line-height: var(--md-sys-typescale-title-large-line-height);
    color: var(--md-sys-color-on-surface);
}
.m3-typography--title-medium {
    font-family: var(--md-sys-typescale-title-medium-font-family);
    font-weight: var(--md-sys-typescale-title-medium-font-weight);
    font-size: var(--md-sys-typescale-title-medium-font-size);
    line-height: var(--md-sys-typescale-title-medium-line-height);
    color: var(--md-sys-color-on-surface-variant); 
}
.m3-typography--body-large {
    font-family: var(--md-sys-typescale-body-large-font-family);
    font-weight: var(--md-sys-typescale-body-large-font-weight);
    font-size: var(--md-sys-typescale-body-large-font-size);
    line-height: var(--md-sys-typescale-body-large-line-height);
}
.m3-typography--body-medium {
    font-family: var(--md-sys-typescale-body-medium-font-family);
    font-weight: var(--md-sys-typescale-body-medium-font-weight);
    font-size: var(--md-sys-typescale-body-medium-font-size);
    line-height: var(--md-sys-typescale-body-medium-line-height);
}
.m3-typography--body-small {
    font-family: var(--md-sys-typescale-body-small-font-family);
    font-weight: var(--md-sys-typescale-body-small-font-weight);
    font-size: var(--md-sys-typescale-body-small-font-size);
    line-height: var(--md-sys-typescale-body-small-line-height);
    color: var(--md-sys-color-on-surface-variant);
}
.m3-typography--label-large {
    font-family: var(--md-sys-typescale-label-large-font-family);
    font-weight: var(--md-sys-typescale-label-large-font-weight);
    font-size: var(--md-sys-typescale-label-large-font-size);
    line-height: var(--md-sys-typescale-label-large-line-height);
}

/* --- Button Styles --- */
.m3-button {
    font-family: var(--md-sys-typescale-label-large-font-family);
    font-weight: var(--md-sys-typescale-label-large-font-weight);
    font-size: var(--md-sys-typescale-label-large-font-size);
    line-height: var(--md-sys-typescale-label-large-line-height);
    border-radius: 20px; 
    padding: 10px 24px;
    border: none;
    cursor: pointer;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px; 
    transition: background-color 0.2s, box-shadow 0.2s;
    position: relative; 
    overflow: hidden; 
}

.m3-button--filled {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}
.m3-button--filled:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-primary) 92%, black 8%);
    box-shadow: 0 1px 3px 1px rgba(0,0,0,0.15), 0 1px 2px 0 rgba(0,0,0,0.3);
}
.m3-button:disabled {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 88%, transparent 12%);
    color: color-mix(in srgb, var(--md-sys-color-on-surface) 62%, transparent 38%);
    cursor: not-allowed;
    box-shadow: none;
}
.m3-button:disabled .m3-button__loader {
    display: inline-block;
}

.m3-icon-button {
    background-color: transparent;
    color: var(--md-sys-color-on-surface-variant);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    padding: 8px; 
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s; /* Added color transition */
}
.m3-icon-button .material-symbols-outlined {
    font-size: 24px;
}
.m3-icon-button:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
    color: var(--md-sys-color-primary);
}


/* Button Loader */
.m3-button__loader {
    width: 18px;
    height: 18px;
    border: 2px solid var(--md-sys-color-on-primary);
    border-bottom-color: transparent;
    border-radius: 50%;
    display: none; /* Hidden by default */
    box-sizing: border-box;
    animation: m3-button-rotation 1s linear infinite;
    margin-left: 8px;
}
.m3-button:disabled .m3-button__loader {
    border-color: color-mix(in srgb, var(--md-sys-color-on-surface) 62%, transparent 38%);
    border-bottom-color: transparent;
}

@keyframes m3-button-rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


/* --- Dialog / Card --- */
#show-access-dialog-btn {
    position: fixed;
}

.m3-dialog {
    background-color: var(--md-sys-color-surface);
    border-radius: 28px; 
    padding: 24px;
    width: 90%;
    max-width: 560px; 
    box-shadow: 0px 8px 12px 6px rgba(0,0,0,0.15), 0px 4px 4px 0px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    gap: 20px; 
    max-height: 90vh; 
}
.m3-dialog.hidden { display: none; } 

/* --- Text Field (Filled M3 Style) --- */
.m3-text-field {
    position: relative;
    background-color: color-mix(in srgb, var(--md-sys-color-primary) 4%, var(--md-sys-color-surface)); 
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    padding-top: 8px; 
    border-bottom: 1px solid var(--md-sys-color-on-surface-variant);
    transition: border-bottom-color 0.2s;
    margin-bottom: 16px; 
}
.m3-text-field:focus-within {
    border-bottom: 2px solid var(--md-sys-color-primary);
}
.m3-text-field__input {
    display: block;
    width: 100%;
    padding: 16px 16px 8px 16px; 
    font-family: var(--md-sys-typescale-body-large-font-family);
    font-size: var(--md-sys-typescale-body-large-font-size);
    color: var(--md-sys-color-on-surface);
    background-color: transparent;
    border: none;
    outline: none;
}
.m3-text-field__label {
    position: absolute;
    left: 16px;
    top: 16px; 
    font-family: var(--md-sys-typescale-body-large-font-family);
    font-size: var(--md-sys-typescale-body-large-font-size);
    color: var(--md-sys-color-on-surface-variant);
    pointer-events: none;
    transition: top 0.2s, font-size 0.2s, color 0.2s;
}
.m3-text-field__input:focus + .m3-text-field__label,
.m3-text-field__input:not(:placeholder-shown) + .m3-text-field__label {
    top: 4px;
    font-size: var(--md-sys-typescale-body-small-font-size);
    color: var(--md-sys-color-primary);
}
.m3-text-field:focus-within .m3-text-field__label {
     color: var(--md-sys-color-primary);
}

/* --- Status Messages --- */
.status-message {
    text-align: center;
    min-height: var(--md-sys-typescale-body-small-line-height);
    margin-top: 8px;
    margin-bottom: 8px;
}
.status-message.error {
    color: var(--md-sys-color-error);
    font-weight: 500;
}
.status-message.success {
    color: var(--md-sys-color-tertiary); 
    font-weight: 500;
}

/* --- Auth Flow Specifics --- */
#auth-flow-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
#auth-flow-content #dialog-title {
    text-align: center;
    margin-bottom: 8px;
}
#auth-flow-content #next-btn {
    width: 100%;
}

/* --- Secrets View Specifics --- */
#secrets-view-content .dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
#secrets-actions {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--md-sys-color-surface-variant);
}
#secrets-actions h3 {
    margin-bottom: -8px; 
}
#secrets-actions #add-secret-btn {
    width: 100%;
}

#secrets-list-container {
    max-height: 30vh; 
    overflow-y: auto;
    padding-right: 8px; 
    margin-right: -8px; 
}
#secrets-list-container::-webkit-scrollbar {
    width: 8px;
}
#secrets-list-container::-webkit-scrollbar-track {
    background: var(--md-sys-color-surface-variant);
    border-radius: 4px;
}
#secrets-list-container::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-outline);
    border-radius: 4px;
}
#secrets-list-container::-webkit-scrollbar-thumb:hover {
    background: var(--md-sys-color-secondary);
}

.secret-item {
    background-color: var(--md-sys-color-surface-variant);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column; 
    gap: 8px; 
}

.secret-item-content {
    flex-grow: 1;
    overflow: hidden;
    width: 100%;
}

.secret-item-content h3 { 
    font-family: var(--md-sys-typescale-title-medium-font-family);
    font-weight: var(--md-sys-typescale-title-medium-font-weight);
    font-size: var(--md-sys-typescale-title-medium-font-size);
    line-height: var(--md-sys-typescale-title-medium-line-height);
    color: var(--md-sys-color-on-secondary-container); 
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.secret-item-content p { 
    font-family: var(--md-sys-typescale-body-medium-font-family);
    font-weight: var(--md-sys-typescale-body-medium-font-weight);
    font-size: var(--md-sys-typescale-body-medium-font-size);
    line-height: var(--md-sys-typescale-body-medium-line-height);
    color: var(--md-sys-color-on-surface-variant);
    max-height: 60px; /* Approx 3 lines */
    overflow-y: auto; 
    white-space: pre-wrap; 
    word-break: break-word; 
    scrollbar-width: thin;
    scrollbar-color: var(--md-sys-color-outline) var(--md-sys-color-surface-variant);
}
.secret-item-content p::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.secret-item-content p::-webkit-scrollbar-track {
    background: color-mix(in srgb, var(--md-sys-color-surface-variant) 50%, transparent);
    border-radius: 3px;
}
.secret-item-content p::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-outline);
    border-radius: 3px;
}


.secret-item-actions {
    display: flex;
    align-items: center;
    gap: 4px; 
    padding-top: 8px;
    margin-top: 4px; 
    border-top: 1px solid color-mix(in srgb, var(--md-sys-color-outline) 20%, transparent); 
}

.m3-icon-button.action-copy-name,
.m3-icon-button.action-copy-content {
    color: var(--md-sys-color-secondary); 
}
.m3-icon-button.action-copy-name:hover,
.m3-icon-button.action-copy-content:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-secondary) 12%, transparent);
    color: var(--md-sys-color-secondary);
}

.secret-item-actions .delete-btn {
    margin-left: auto; 
    color: var(--md-sys-color-error); 
}
.secret-item-actions .delete-btn:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-error) 12%, transparent);
    color: var(--md-sys-color-error); /* Ensure color remains on hover */
}

/* Feedback visual de copia */
.m3-icon-button .icon-copied { 
    font-variation-settings: 'FILL' 1 !important; 
    color: var(--md-sys-color-tertiary) !important; 
}


.empty-message {
    text-align: center;
    padding: 20px;
    color: var(--md-sys-color-on-surface-variant);
    font-style: italic;
}

/* Visibility Utility */
.hidden {
    display: none !important; 
}

/* --- Responsive Adjustments --- */
@media (max-width: 600px) {
    .m3-dialog {
        width: 100%;
        margin: 0;
        border-radius: 5; 
        min-height: 100vh; 
        max-height: 100vh;
        justify-content: flex-start; 
        padding: 16px; 
    }
    #show-access-dialog-btn { 
        z-index: 100; 
    }
    #secrets-list-container {
        max-height: 40vh; 
    }
    .secret-item-content p {
        max-height: 80px; /* Allow a bit more height on mobile for content */
    }
}